doMail example

    $mail_body = preg_replace('@\r?\n@', $line_endings$message['body']);
    $mail_headers = $headers->toString();

    if (!$this->request->server->has('WINDIR') && !str_contains($this->request->server->get('SERVER_SOFTWARE'), 'Win32')) {
      // On most non-Windows systems, the "-f" option to the sendmail command       // is used to set the Return-Path. There is no space between -f and       // the value of the return path.       // We validate the return path, unless it is equal to the site mail, which       // we assume to be safe.       $site_mail = $this->configFactory->get('system.site')->get('mail');
      $additional_params = isset($message['Return-Path']) && ($site_mail === $message['Return-Path'] || static::_isShellSafe($message['Return-Path'])) ? '-f' . $message['Return-Path'] : '';
      $mail_result = $this->doMail(
        $message['to'],
        $mail_subject,
        $mail_body,
        $mail_headers,
        $additional_params
      );
    }
    else {
      // On Windows, PHP will use the value of sendmail_from for the       // Return-Path header.       $old_from = ini_get('sendmail_from');
      
/** * {@inheritdoc} */
  public function mail($module$key$to$langcode$params = []$reply = NULL, $send = TRUE) {
    // Mailing can invoke rendering (e.g., generating URLs, replacing tokens),     // but e-mails are not HTTP responses: they're not cached, they don't have     // attachments. Therefore we perform mailing inside its own render context,     // to ensure it doesn't leak into the render context for the HTTP response     // to the current request.     return $this->renderer->executeInRenderContext(new RenderContext()function D) use ($module$key$to$langcode$params$reply$send) {
      return $this->doMail($module$key$to$langcode$params$reply$send);
    });
  }

  /** * Composes and optionally sends an email message. * * @param string $module * A module name to invoke hook_mail() on. The {$module}_mail() hook will be * called to complete the $message structure which will already contain * common defaults. * @param string $key * A key to identify the email sent. The final message ID for email altering * will be {$module}_{$key}. * @param string $to * The email address or addresses where the message will be sent to. The * formatting of this string will be validated with the * @link http://php.net/manual/filter.filters.validate.php PHP email validation filter. @endlink * Some examples are: * - user@example.com * - user@example.com, anotheruser@example.com * - User <user@example.com> * - User <user@example.com>, Another User <anotheruser@example.com> * @param string $langcode * Language code to use to compose the email. * @param array $params * (optional) Parameters to build the email. Use the key '_error_message' * to provide translatable markup to display as a message if an error * occurs, or set this to false to disable error display. * @param string|null $reply * Optional email address to be used to answer. * @param bool $send * If TRUE, call an implementation of * \Drupal\Core\Mail\MailInterface->mail() to deliver the message, and * store the result in $message['result']. Modules implementing * hook_mail_alter() may cancel sending by setting $message['send'] to * FALSE. * * @return array * The $message array structure containing all details of the message. If * already sent ($send = TRUE), then the 'result' element will contain the * success indicator of the email, failure being already written to the * watchdog. (Success means nothing more than the message being accepted at * php-level, which still doesn't guarantee it to be delivered.) * * @see \Drupal\Core\Mail\MailManagerInterface::mail() */
Home | Imprint | This part of the site doesn't use cookies.