Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SymfonyMailer.php

function SymfonyMailer::mail

Overrides MailInterface::mail

File

core/lib/Drupal/Core/Mail/Plugin/Mail/SymfonyMailer.php, line 120

Class

SymfonyMailer
Defines an experimental mail backend, based on the Symfony mailer component.

Namespace

Drupal\Core\Mail\Plugin\Mail

Code

public function mail(array $message) {
    try {
        $email = new Email();
        $headers = $email->getHeaders();
        foreach ($message['headers'] as $name => $value) {
            if (!in_array(strtolower($name), self::SKIP_HEADERS, TRUE)) {
                if (in_array(strtolower($name), self::MAILBOX_LIST_HEADERS, TRUE)) {
                    // Split values by comma, but ignore commas encapsulated in double
                    // quotes.
                    $value = str_getcsv($value, escape: '\\');
                }
                $headers->addHeader($name, $value);
            }
        }
        $email->to($message['to'])
            ->subject($message['subject'])
            ->text($message['body']);
        $mailer = $this->getMailer();
        $mailer->send($email);
        return TRUE;
    } catch (\Exception $e) {
        Error::logException($this->logger, $e);
        return FALSE;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal