PHPMailer::smtpSend( string $header, string $body ): bool
- Source
wp-includes/PHPMailer/PHPMailer.php:2231
Description
Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
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::smtpSend() 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
- Light
- Scaling
- Scales with input
- Instructions
- 26–96
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
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 214.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 42 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost PHPMailer::smtpSend() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->smtpConnect() | 26 | ::stripTrailingWSP(), ->smtpConnect(), ::lang() |
->smtpConnect() && !->getServerExt() | 33 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ::lang() |
->smtpConnect() && !->mail() | 52–53 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ::lang(), ->getError(), ->setError() |
->smtpConnect() && ->getServerExt() && !->mail() | 57–58 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ::lang(), ->getError(), ->setError() |
->smtpConnect() && !->mail() | 58–59 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ::lang(), ->getError(), ->setError() |
->smtpConnect() && ->mail() && !->data() | 60–62 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->data(), ::lang(), issent() |
->smtpConnect() && ->mail() | 61–64 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->mail() | 63–66 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->getServerExt() && !->mail() | 63–64 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ::lang(), ->getError(), ->setError() |
->smtpConnect() && ->getServerExt() && ->mail() && !->data() | 65–67 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->data(), ::lang(), issent() |
->smtpConnect() && ->getServerExt() && ->mail() | 66–69 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->mail() && !->data() | 66–68 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->data(), ::lang(), issent() |
30 further outcomes, up to 96 instructions
->smtpConnect() && ->mail() && ->data() | 67–70 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->data(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->mail() | 67–70 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->getServerExt() && ->mail() | 68–71 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->mail() && ->data() | 69–72 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->mail() | 69–72 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->getServerExt() && ->mail() && !->data() | 71–73 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->data(), ::lang(), issent() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 72–75 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->data(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->getServerExt() && ->mail() | 72–75 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->mail() | 73–77 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->mail() && ->data() | 73–76 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 74–77 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->getServerExt() && ->mail() | 74–77 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->mail() | 75–79 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->mail() && ->data() | 75–78 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->getServerExt() && ->mail() | 78–82 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 78–81 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->reset() |
->smtpConnect() && ->mail() && ->data() | 79–83 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->data(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->mail() | 79–83 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() | 80–84 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 80–83 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close() |
->smtpConnect() && ->mail() && ->data() | 81–85 | ::stripTrailingWSP(), ->smtpConnect(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->mail() | 81–85 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 84–88 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->data(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() | 84–88 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->mail() && ->data() | 85–89 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 86–90 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() | 86–90 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->mail() && ->data() | 87–91 | ::stripTrailingWSP(), ->smtpConnect(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 90–94 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->reset(), ::lang() |
->smtpConnect() && ->getServerExt() && ->mail() && ->data() | 92–96 | ::stripTrailingWSP(), ->smtpConnect(), ->getServerExt(), ->xclient(), ->mail(), ->data(), ->getLastTransactionID(), ->quit(), ->close(), ::lang() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 213 | 26–96 | 19 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 214 | 26–96 | 19 | |
| 8.4 | 214 | 26–96 | 19 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 217 | 26–96 | 19 | |
| 8.2 | 217 | 26–96 | 19 | |
| 8.1 | 217 | 26–96 | 19 | |
| 7.4 | 217 | 26–96 | 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 · 6
- static::stripTrailingWSP()
- \PHPMailer\PHPMailer\PHPMailer::smtpConnect()
- \PHPMailer\PHPMailer\Exception::__construct()
- \PHPMailer\PHPMailer\PHPMailer::lang()
- \PHPMailer\PHPMailer\PHPMailer::setError()
- \PHPMailer\PHPMailer\PHPMailer::doCallback()
Source code
protected function smtpSend($header, $body) { $header = static::stripTrailingWSP($header) . static::$LE . static::$LE; $bad_rcpt = []; if (!$this->smtpConnect($this->SMTPOptions)) { throw new Exception(self::lang('smtp_connect_failed'), self::STOP_CRITICAL); } //If we have recipient addresses that need Unicode support, //but the server doesn't support it, stop here if ($this->UseSMTPUTF8 && !$this->smtp->getServerExt('SMTPUTF8')) { throw new Exception(self::lang('no_smtputf8'), self::STOP_CRITICAL); } //Sender already validated in preSend() if ('' === $this->Sender) { $smtp_from = $this->From; } else { $smtp_from = $this->Sender; } if (count($this->SMTPXClient)) { $this->smtp->xclient($this->SMTPXClient); } if (!$this->smtp->mail($smtp_from)) { $this->setError(self::lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError())); throw new Exception($this->ErrorInfo, self::STOP_CRITICAL); } $callbacks = []; //Attempt to send to all recipients foreach ([$this->to, $this->cc, $this->bcc] as $togroup) { foreach ($togroup as $to) { if (!$this->smtp->recipient($to[0], $this->dsn)) { $error = $this->smtp->getError(); $bad_rcpt[] = ['to' => $to[0], 'error' => $error['detail']]; $isSent = false; } else { $isSent = true; } $callbacks[] = ['issent' => $isSent, 'to' => $to[0], 'name' => $to[1]]; } } //Only send the DATA command if we have viable recipients if ((count($this->all_recipients) > count($bad_rcpt)) && !$this->smtp->data($header . $body)) { throw new Exception(self::lang('data_not_accepted'), self::STOP_CRITICAL); } $smtp_transaction_id = $this->smtp->getLastTransactionID(); if ($this->SMTPKeepAlive) { $this->smtp->reset(); } else { $this->smtp->quit(); $this->smtp->close(); } foreach ($callbacks as $cb) { $this->doCallback( $cb['issent'], [[$cb['to'], $cb['name']]], [], [], $this->Subject, $body, $this->From, ['smtp_transaction_id' => $smtp_transaction_id] ); } //Create error message for any bad addresses if (count($bad_rcpt) > 0) { $errstr = ''; foreach ($bad_rcpt as $bad) { $errstr .= $bad['to'] . ': ' . $bad['error']; } throw new Exception(self::lang('recipients_failed') . $errstr, self::STOP_CONTINUE); } return true; }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.