PHPMailer::mailSend( string $header, string $body ): bool
- Source
wp-includes/PHPMailer/PHPMailer.php:2084
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::mailSend() 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
- 40–111
- 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 168.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 48 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost PHPMailer::mailSend() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($value) && !isset($old_from) | 40–45 | ::stripTrailingWSP(), ini_get() |
empty($value) && isset($old_from) | 44–49 | ::stripTrailingWSP(), ini_get(), ini_set() |
!empty($value) && !::validateAddress() && !isset($old_from) | 46–51 | ::stripTrailingWSP(), ini_get(), ::validateAddress() |
empty($value) && !empty($sendmail_from_value) && !isset($old_from) | 47–50 | ::stripTrailingWSP(), ini_get(), ini_get() |
empty($value) && !isset($old_from) | 48–53 | ::stripTrailingWSP(), ini_get(), ::lang() |
!empty($value) && !::validateAddress() && isset($old_from) | 50–55 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ini_set() |
empty($value) && !empty($sendmail_from_value) && isset($old_from) | 51–54 | ::stripTrailingWSP(), ini_get(), ini_get(), ini_set() |
empty($value) && isset($old_from) | 52–57 | ::stripTrailingWSP(), ini_get(), ini_set(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && !isset($old_from) | 53–56 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress() |
!empty($value) && !::validateAddress() && !isset($old_from) | 54–59 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::lang() |
empty($value) && !empty($sendmail_from_value) && !isset($old_from) | 55–58 | ::stripTrailingWSP(), ini_get(), ini_get(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && isset($old_from) | 57–60 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ini_set() |
36 further outcomes, up to 111 instructions
!empty($value) && !::validateAddress() && isset($old_from) | 58–63 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ini_set(), ::lang() |
empty($value) && !empty($sendmail_from_value) && isset($old_from) | 59–62 | ::stripTrailingWSP(), ini_get(), ini_get(), ini_set(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && !isset($old_from) | 61–64 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::lang() |
!empty($value) && ::validateAddress() && !isset($old_from) | 61–68 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set() |
empty($value) && !isset($old_from) | 64–71 | ::stripTrailingWSP(), ini_get(), ->mailPassthru(), ->doCallback() |
!empty($sendmail_from_value) && !::validateAddress() && isset($old_from) | 65–68 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ini_set(), ::lang() |
!empty($value) && ::validateAddress() && isset($old_from) | 65–72 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ini_set() |
empty($value) && isset($old_from) | 68–75 | ::stripTrailingWSP(), ini_get(), ->mailPassthru(), ->doCallback(), ini_set() |
!empty($sendmail_from_value) && ::validateAddress() && !isset($old_from) | 68–73 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set() |
!empty($value) && ::validateAddress() && !isset($old_from) | 69–76 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ::lang() |
!empty($value) && !::validateAddress() && !isset($old_from) | 70–77 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback() |
empty($value) && !empty($sendmail_from_value) && !isset($old_from) | 71–76 | ::stripTrailingWSP(), ini_get(), ini_get(), ->mailPassthru(), ->doCallback() |
empty($value) && !isset($old_from) | 72–79 | ::stripTrailingWSP(), ini_get(), ->mailPassthru(), ->doCallback(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && isset($old_from) | 72–77 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ini_set() |
!empty($value) && ::validateAddress() && isset($old_from) | 73–80 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ini_set(), ::lang() |
!empty($value) && !::validateAddress() && isset($old_from) | 74–81 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback(), ini_set() |
empty($value) && !empty($sendmail_from_value) && isset($old_from) | 75–80 | ::stripTrailingWSP(), ini_get(), ini_get(), ->mailPassthru(), ->doCallback(), ini_set() |
empty($value) && isset($old_from) | 76–83 | ::stripTrailingWSP(), ini_get(), ->mailPassthru(), ->doCallback(), ini_set(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && !isset($old_from) | 76–81 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && !isset($old_from) | 77–82 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback() |
!empty($value) && !::validateAddress() && !isset($old_from) | 78–85 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback(), ::lang() |
empty($value) && !empty($sendmail_from_value) && !isset($old_from) | 79–84 | ::stripTrailingWSP(), ini_get(), ini_get(), ->mailPassthru(), ->doCallback(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && isset($old_from) | 80–85 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ini_set(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && isset($old_from) | 81–86 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback(), ini_set() |
!empty($value) && !::validateAddress() && isset($old_from) | 82–89 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback(), ini_set(), ::lang() |
empty($value) && !empty($sendmail_from_value) && isset($old_from) | 83–88 | ::stripTrailingWSP(), ini_get(), ini_get(), ->mailPassthru(), ->doCallback(), ini_set(), ::lang() |
!empty($sendmail_from_value) && !::validateAddress() && !isset($old_from) | 85–90 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback(), ::lang() |
!empty($value) && ::validateAddress() && !isset($old_from) | 85–94 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback() |
!empty($sendmail_from_value) && !::validateAddress() && isset($old_from) | 89–94 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ->mailPassthru(), ->doCallback(), ini_set(), ::lang() |
!empty($value) && ::validateAddress() && isset($old_from) | 89–98 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback(), ini_set() |
!empty($sendmail_from_value) && ::validateAddress() && !isset($old_from) | 92–99 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback() |
!empty($value) && ::validateAddress() && !isset($old_from) | 93–102 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && isset($old_from) | 96–103 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback(), ini_set() |
!empty($value) && ::validateAddress() && isset($old_from) | 97–106 | ::stripTrailingWSP(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback(), ini_set(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && !isset($old_from) | 100–107 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback(), ::lang() |
!empty($sendmail_from_value) && ::validateAddress() && isset($old_from) | 104–111 | ::stripTrailingWSP(), ini_get(), ini_get(), ::validateAddress(), ::isShellSafe(), ini_get(), ini_set(), ->mailPassthru(), ->doCallback(), ini_set(), ::lang() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 168 | 40–111 | 16 | |
| 8.5 | 168 | 40–111 | 16 | |
| 8.4 | 168 | 40–111 | 16 | 10 fewer instructions than PHP 8.3 |
| 8.3 | 178 | 46–121 | 16 | |
| 8.2 | 178 | 46–121 | 16 | |
| 8.1 | 178 | 46–121 | 16 | |
| 7.4 | 178 | 46–121 | 16 |
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 · 9
- static::stripTrailingWSP()
- \PHPMailer\PHPMailer\PHPMailer::addrFormat()
- static::validateAddress()
- \PHPMailer\PHPMailer\PHPMailer::isShellSafe()
- \PHPMailer\PHPMailer\PHPMailer::mailPassthru()
- static::parseAddresses()
- \PHPMailer\PHPMailer\PHPMailer::doCallback()
- \PHPMailer\PHPMailer\Exception::__construct()
- \PHPMailer\PHPMailer\PHPMailer::lang()
Source code
protected function mailSend($header, $body) { $header = static::stripTrailingWSP($header) . static::$LE . static::$LE; $toArr = []; foreach ($this->to as $toaddr) { $toArr[] = $this->addrFormat($toaddr); } $to = trim(implode(', ', $toArr)); //If there are no To-addresses (e.g. when sending only to BCC-addresses) //the following should be added to get a correct DKIM-signature. //Compare with $this->preSend() if ($to === '') { $to = 'undisclosed-recipients:;'; } $params = null; //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 //CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped. //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'); } if (!empty($this->Sender) && static::validateAddress($this->Sender)) { $phpmailer_path = ini_get('sendmail_path'); if (self::isShellSafe($this->Sender) && strpos($phpmailer_path, ' -f') === false) { $params = sprintf('-f%s', $this->Sender); } $old_from = ini_get('sendmail_from'); ini_set('sendmail_from', $this->Sender); } $result = false; if ($this->SingleTo && count($toArr) > 1) { foreach ($toArr as $toAddr) { $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params); $addrinfo = static::parseAddresses($toAddr, null, $this->CharSet); foreach ($addrinfo as $addr) { $this->doCallback( $result, [[$addr['address'], $addr['name']]], $this->cc, $this->bcc, $this->Subject, $body, $this->From, [] ); } } } else { $result = $this->mailPassthru($to, $this->Subject, $body, $header, $params); $this->doCallback($result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From, []); } if (isset($old_from)) { ini_set('sendmail_from', $old_from); } if (!$result) { throw new Exception(self::lang('instantiate'), self::STOP_CRITICAL); } 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.