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

Breadcrumb

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

function SendmailTransport::doSend

Overrides AbstractTransport::doSend

File

vendor/symfony/mailer/Transport/SendmailTransport.php, line 90

Class

SendmailTransport
SendmailTransport for sending mail through a Sendmail/Postfix (etc..) binary.

Namespace

Symfony\Component\Mailer\Transport

Code

protected function doSend(SentMessage $message) : void {
    $this->getLogger()
        ->debug(\sprintf('Email transport "%s" starting', __CLASS__));
    $command = $this->command;
    if ($recipients = $message->getEnvelope()
        ->getRecipients()) {
        $command = str_replace(' -t', '', $command);
    }
    if (!str_contains($command, ' -f')) {
        $command .= ' -f' . escapeshellarg($message->getEnvelope()
            ->getSender()
            ->getEncodedAddress());
    }
    $chunks = AbstractStream::replace("\r\n", "\n", $message->toIterable());
    if (!str_contains($command, ' -i') && !str_contains($command, ' -oi')) {
        $chunks = AbstractStream::replace("\n.", "\n..", $chunks);
    }
    foreach ($recipients as $recipient) {
        $command .= ' ' . escapeshellarg($recipient->getEncodedAddress());
    }
    $this->stream
        ->setCommand($command);
    $this->stream
        ->initialize();
    foreach ($chunks as $chunk) {
        $this->stream
            ->write($chunk);
    }
    $this->stream
        ->flush();
    $this->stream
        ->terminate();
    $this->getLogger()
        ->debug(\sprintf('Email transport "%s" stopped', __CLASS__));
}
RSS feed
Powered by Drupal