wppaste
WordPress

PHPMailer::sendmailSend( string $header, string $body ): bool

Source
wp-includes/PHPMailer/PHPMailer.php:1726
Send mail using the $Sendmail program.

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$headerstring
The message headers
$bodystring
The message body

Return value

bool

Performance profile

How much work a call to PHPMailer::sendmailSend() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via fwrite().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
60–165

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 259.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • filesystemfilesystem accessfwrite()called directly

What one call costs · 36 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost PHPMailer::sendmailSend() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($value)60–64->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug()
!empty($value) && !::validateAddress()66–70->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug()
empty($value) && !empty($sendmail_from_value)67–69->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug()
!empty($value) && ::validateAddress()72–80->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug()
!empty($sendmail_from_value) && !::validateAddress()73–75->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug()
empty($value)75–78->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang(), ->doCallback()
empty($value)78–81->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang()
!empty($sendmail_from_value) && ::validateAddress()79–85->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug()
!empty($value) && !::validateAddress()81–84->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang(), ->doCallback()
empty($value) && !empty($sendmail_from_value)82–83->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang(), ->doCallback()
!empty($value) && !::validateAddress()84–87->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang()
empty($value) && !empty($sendmail_from_value)85–86->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang()
24 further outcomes, up to 165 instructions
!empty($value) && ::validateAddress()87–94->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang(), ->doCallback()
!empty($sendmail_from_value) && !::validateAddress()88–89->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang(), ->doCallback()
!empty($value) && ::validateAddress()90–97->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang()
!empty($sendmail_from_value) && !::validateAddress()91–92->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang()
!empty($sendmail_from_value) && ::validateAddress()94–99->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang(), ->doCallback()
!empty($sendmail_from_value) && ::validateAddress()97–102->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->lang()
empty($value) && $result === 0106–110->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug()
!empty($value) && !::validateAddress() && $result === 0112–116->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug()
empty($value) && !empty($sendmail_from_value) && $result === 0113–115->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug()
empty($value) && $result !== 0116–120->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ->lang()
!empty($value) && ::validateAddress() && $result === 0118–126->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug()
!empty($sendmail_from_value) && !::validateAddress() && $result === 0119–121->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug()
!empty($value) && !::validateAddress() && $result !== 0122–126->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ->lang()
empty($value) && !empty($sendmail_from_value) && $result !== 0123–125->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ->lang()
!empty($sendmail_from_value) && ::validateAddress() && $result === 0125–131->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug()
!empty($value) && ::validateAddress() && $result !== 0128–136->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ->lang()
!empty($sendmail_from_value) && !::validateAddress() && $result !== 0129–131->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ->lang()
!empty($sendmail_from_value) && ::validateAddress() && $result !== 0135–141->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ->lang()
empty($value) && $result !== 0140–144->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ->lang()
!empty($value) && !::validateAddress() && $result !== 0146–150->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ->lang()
empty($value) && !empty($sendmail_from_value) && $result !== 0147–149->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ->lang()
!empty($value) && ::validateAddress() && $result !== 0152–160->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ->lang()
!empty($sendmail_from_value) && !::validateAddress() && $result !== 0153–155->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ->lang()
!empty($sendmail_from_value) && ::validateAddress() && $result !== 0159–165->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), sprintf(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ->lang()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 259 instructions, 60–165 executed per call, 16 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 8

  • \PHPMailer\PHPMailer\PHPMailer::edebug()
  • static::stripTrailingWSP()
  • static::validateAddress()
  • \PHPMailer\PHPMailer\PHPMailer::isShellSafe()
  • \PHPMailer\PHPMailer\Exception::__construct()
  • \PHPMailer\PHPMailer\PHPMailer::lang()
  • static::parseAddresses()
  • \PHPMailer\PHPMailer\PHPMailer::doCallback()

Source code

    protected function sendmailSend($header, $body)    {        if ($this->Mailer === 'qmail') {            $this->edebug('Sending with qmail');        } else {            $this->edebug('Sending with sendmail');        }        $header = static::stripTrailingWSP($header) . static::$LE . static::$LE;        //This sets the SMTP envelope sender which gets turned into a return-path header by the receiver        //A space after `-f` is optional, but there is a long history of its presence        //causing problems, so we don't use one        //Exim docs: https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html        //Sendmail docs: https://www.sendmail.org/~ca/email/man/sendmail.html        //Example problem: https://www.drupal.org/node/1057954         //PHP 5.6 workaround        $sendmail_from_value = ini_get('sendmail_from');        if (empty($this->Sender) && !empty($sendmail_from_value)) {            //PHP config has a sender address we can use            $this->Sender = ini_get('sendmail_from');        }        //CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.        if (!empty($this->Sender) && static::validateAddress($this->Sender) && self::isShellSafe($this->Sender)) {            if ($this->Mailer === 'qmail') {                $sendmailFmt = '%s -f%s';            } else {                $sendmailFmt = '%s -oi -f%s -t';            }        } else {            //allow sendmail to choose a default envelope sender. It may            //seem preferable to force it to use the From header as with            //SMTP, but that introduces new problems (see            //<https://github.com/PHPMailer/PHPMailer/issues/2298>), and            //it has historically worked this way.            $sendmailFmt = '%s -oi -t';        }         $sendmail = sprintf($sendmailFmt, escapeshellcmd($this->Sendmail), $this->Sender);        $this->edebug('Sendmail path: ' . $this->Sendmail);        $this->edebug('Sendmail command: ' . $sendmail);        $this->edebug('Envelope sender: ' . $this->Sender);        $this->edebug("Headers: {$header}");         if ($this->SingleTo) {            foreach ($this->SingleToArray as $toAddr) {                $mail = @popen($sendmail, 'w');                if (!$mail) {                    throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);                }                $this->edebug("To: {$toAddr}");                fwrite($mail, 'To: ' . $toAddr . "\n");                fwrite($mail, $header);                fwrite($mail, $body);                $result = pclose($mail);                $addrinfo = static::parseAddresses($toAddr, true, $this->CharSet);                $this->doCallback(                    ($result === 0),                    [[$addrinfo['address'], $addrinfo['name']]],                    $this->cc,                    $this->bcc,                    $this->Subject,                    $body,                    $this->From,                    []                );                $this->edebug("Result: " . ($result === 0 ? 'true' : 'false'));                if (0 !== $result) {                    throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);                }            }        } else {            $mail = @popen($sendmail, 'w');            if (!$mail) {                throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);            }            fwrite($mail, $header);            fwrite($mail, $body);            $result = pclose($mail);            $this->doCallback(                ($result === 0),

Changelog

Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.10 tag, from src/wp-includes/PHPMailer/PHPMailer.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.