PHPMailer::sendmailSend( string $header, string $body ): bool
- Source
wp-includes/PHPMailer/PHPMailer.php:1892
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), 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
- Scaling
- Scales with input
- Instructions
- 63–151
- Plugin surface
- None
- Called by
- 0
Reads or writes the filesystem via fwrite().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 269.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- filesystemfilesystem access
fwrite()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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) | 63–71 | ->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug() |
!empty($value) && !::validateAddress() | 69–77 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug() |
empty($value) && !empty($sendmail_from_value) | 70–76 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug() |
!empty($value) && ::validateAddress() | 75–87 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug() |
!empty($sendmail_from_value) && !::validateAddress() | 76–82 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug() |
empty($value) | 78–85 | ->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang(), ->doCallback() |
empty($value) | 81–88 | ->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() | 82–92 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug() |
!empty($value) && !::validateAddress() | 84–91 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang(), ->doCallback() |
empty($value) && !empty($sendmail_from_value) | 85–90 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang(), ->doCallback() |
!empty($value) && !::validateAddress() | 87–94 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang() |
empty($value) && !empty($sendmail_from_value) | 88–93 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang() |
24 further outcomes, up to 151 instructions
!empty($value) && ::validateAddress() | 90–101 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang(), ->doCallback() |
!empty($sendmail_from_value) && !::validateAddress() | 91–96 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang(), ->doCallback() |
!empty($value) && ::validateAddress() | 93–104 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() | 94–99 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() | 97–106 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang(), ->doCallback() |
!empty($sendmail_from_value) && ::validateAddress() | 100–109 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ::lang() |
empty($value) && $result === 0 | 109–117 | ->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug() |
!empty($value) && !::validateAddress() && $result === 0 | 115–123 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug() |
empty($value) && !empty($sendmail_from_value) && $result === 0 | 116–122 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug() |
empty($value) && $result !== 0 | 119–127 | ->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ::lang() |
!empty($value) && ::validateAddress() && $result === 0 | 121–133 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug() |
empty($value) && $result !== 0 | 121–130 | ->edebug(), ::stripTrailingWSP(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && $result === 0 | 122–128 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug() |
!empty($value) && !::validateAddress() && $result !== 0 | 125–133 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ::lang() |
empty($value) && !empty($sendmail_from_value) && $result !== 0 | 126–132 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ::lang() |
!empty($value) && !::validateAddress() && $result !== 0 | 127–136 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && $result === 0 | 128–138 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug() |
empty($value) && !empty($sendmail_from_value) && $result !== 0 | 128–135 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ::lang() |
!empty($value) && ::validateAddress() && $result !== 0 | 131–143 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && $result !== 0 | 132–138 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ::lang() |
!empty($value) && ::validateAddress() && $result !== 0 | 133–146 | ->edebug(), ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && $result !== 0 | 134–141 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && $result !== 0 | 138–148 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), fwrite(), fwrite(), pclose(), ->doCallback(), ->edebug(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && $result !== 0 | 140–151 | ->edebug(), ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), escapeshellcmd(), ->edebug(), ->edebug(), ->edebug(), ->edebug(), popen(), ->edebug(), fwrite(), fwrite(), fwrite(), pclose(), ::parseAddresses(), ->edebug(), ::lang() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 269 | 63–151 | 19 | |
| 8.5 | 269 | 63–151 | 19 | |
| 8.4 | 269 | 63–151 | 19 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 275 | 66–157 | 19 | |
| 8.2 | 275 | 66–157 | 19 | |
| 8.1 | 275 | 66–157 | 19 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 276 | 66–158 | 19 |
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'); } $sendmailArgs = []; // CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped. // Also don't add the -f automatically unless it has been set either via Sender // or sendmail_path. Otherwise, it can introduce new problems. // @see http://github.com/PHPMailer/PHPMailer/issues/2298 if (!empty($this->Sender) && static::validateAddress($this->Sender) && self::isShellSafe($this->Sender)) { $sendmailArgs[] = '-f' . $this->Sender; } // Qmail doesn't accept all the sendmail parameters // @see https://github.com/PHPMailer/PHPMailer/issues/3189 if ($this->Mailer !== 'qmail') { $sendmailArgs[] = '-i'; $sendmailArgs[] = '-t'; } $resultArgs = (empty($sendmailArgs) ? '' : ' ' . implode(' ', $sendmailArgs)); $sendmail = trim(escapeshellcmd($this->Sendmail) . $resultArgs); $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(self::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, null, $this->CharSet); foreach ($addrinfo as $addr) { $this->doCallback( ($result === 0), [[$addr['address'], $addr['name']]], $this->cc, $this->bcc, $this->Subject, $body, $this->From, [] ); } $this->edebug("Result: " . ($result === 0 ? 'true' : 'false')); if (0 !== $result) { throw new Exception(self::lang('execute') . $this->Sendmail, self::STOP_CRITICAL); } } } else { $mail = @popen($sendmail, 'w'); if (!$mail) { throw new Exception(self::lang('execute') . $this->Sendmail, self::STOP_CRITICAL);Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.