PHPMailer::preSend(): bool
- Source
wp-includes/PHPMailer/PHPMailer.php:1542
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.
Return value
bool
Performance profile
How much work a call to PHPMailer::preSend() 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
- 42–154
- Plugin surface
- None
- Called by
- 0
Reads or writes the filesystem via file_exists().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 255.
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
file_exists()called directly
What one call costs · 18 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost PHPMailer::preSend() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 42–46 | ::setLE(), array_merge(), ->lang() |
empty($value) | 53–61 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->lang() |
empty($value) | 66–82 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader() |
!empty($address_kind) && !::validateAddress() | 77–83 | ::setLE(), array_merge(), ->punyencodeAddress(), ::validateAddress(), ->lang(), ->setError(), ->edebug() |
!::isPermittedPath() | 78–88 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ::isPermittedPath() |
::isPermittedPath() && !file_exists() | 83–93 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ::isPermittedPath(), file_exists() |
empty($value) | 90–106 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->headerLine() |
empty($value) | 93–109 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->addrAppend(), ->secureHeader(), ->encodeHeader(), ->headerLine() |
!::isPermittedPath() | 102–112 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ::isPermittedPath() |
!empty($value) | 104–114 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->secureHeader(), ->encodeHeader(), ->DKIM_Add(), ::stripTrailingWSP(), ::normalizeBreaks() |
!::isPermittedPath() | 105–115 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->addrAppend(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ::isPermittedPath() |
::isPermittedPath() && !file_exists() | 107–117 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ::isPermittedPath(), file_exists() |
6 further outcomes, up to 154 instructions
::isPermittedPath() && !file_exists() | 110–120 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->addrAppend(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ::isPermittedPath(), file_exists() |
::isPermittedPath() && file_exists() | 117–127 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ::isPermittedPath(), file_exists(), ->secureHeader(), ->encodeHeader(), ->DKIM_Add(), ::stripTrailingWSP(), ::normalizeBreaks() |
!empty($value) | 128–138 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->DKIM_Add(), ::stripTrailingWSP(), ::normalizeBreaks() |
!empty($value) | 131–141 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->addrAppend(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->DKIM_Add(), ::stripTrailingWSP(), ::normalizeBreaks() |
::isPermittedPath() && file_exists() | 141–151 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->headerLine(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ::isPermittedPath(), file_exists(), ->secureHeader(), ->encodeHeader(), ->DKIM_Add(), ::stripTrailingWSP(), ::normalizeBreaks() |
::isPermittedPath() && file_exists() | 144–154 | ::setLE(), array_merge(), ->alternativeExists(), ->setMessageType(), ->createBody(), ->createHeader(), ->addrAppend(), ->secureHeader(), ->encodeHeader(), ->headerLine(), ::isPermittedPath(), file_exists(), ->secureHeader(), ->encodeHeader(), ->DKIM_Add(), ::stripTrailingWSP(), ::normalizeBreaks() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 255 | 42–154 | 23 | |
| 8.5 | 255 | 42–154 | 23 | |
| 8.4 | 255 | 42–154 | 23 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 260 | 42–156 | 23 | |
| 8.2 | 260 | 42–156 | 23 | |
| 8.1 | 260 | 42–156 | 23 | 5 fewer instructions than PHP 7.4 |
| 7.4 | 265 | 42–162 | 25 |
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 · 20
- stripos()
- static::setLE()
- \PHPMailer\PHPMailer\PHPMailer::lang()
- \PHPMailer\PHPMailer\PHPMailer::punyencodeAddress()
- \PHPMailer\PHPMailer\Exception::__construct()
- static::validateAddress()
- \PHPMailer\PHPMailer\PHPMailer::setError()
- \PHPMailer\PHPMailer\PHPMailer::edebug()
- \PHPMailer\PHPMailer\PHPMailer::alternativeExists()
- \PHPMailer\PHPMailer\PHPMailer::setMessageType()
- \PHPMailer\PHPMailer\PHPMailer::createBody()
- \PHPMailer\PHPMailer\PHPMailer::createHeader()
Show all 20
- \PHPMailer\PHPMailer\PHPMailer::addrAppend()
- \PHPMailer\PHPMailer\PHPMailer::headerLine()
- \PHPMailer\PHPMailer\PHPMailer::encodeHeader()
- \PHPMailer\PHPMailer\PHPMailer::secureHeader()
- static::isPermittedPath()
- \PHPMailer\PHPMailer\PHPMailer::DKIM_Add()
- static::stripTrailingWSP()
- static::normalizeBreaks()
Source code
public function preSend() { if ( 'smtp' === $this->Mailer || ('mail' === $this->Mailer && (\PHP_VERSION_ID >= 80000 || stripos(PHP_OS, 'WIN') === 0)) ) { //SMTP mandates RFC-compliant line endings //and it's also used with mail() on Windows static::setLE(self::CRLF); } else { //Maintain backward compatibility with legacy Linux command line mailers static::setLE(PHP_EOL); } //Check for buggy PHP versions that add a header with an incorrect line break if ( 'mail' === $this->Mailer && ((\PHP_VERSION_ID >= 70000 && \PHP_VERSION_ID < 70017) || (\PHP_VERSION_ID >= 70100 && \PHP_VERSION_ID < 70103)) && ini_get('mail.add_x_header') === '1' && stripos(PHP_OS, 'WIN') === 0 ) { trigger_error($this->lang('buggy_php'), E_USER_WARNING); } try { $this->error_count = 0; //Reset errors $this->mailHeader = ''; //Dequeue recipient and Reply-To addresses with IDN foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) { $params[1] = $this->punyencodeAddress($params[1]); call_user_func_array([$this, 'addAnAddress'], $params); } if (count($this->to) + count($this->cc) + count($this->bcc) < 1) { throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL); } //Validate From, Sender, and ConfirmReadingTo addresses foreach (['From', 'Sender', 'ConfirmReadingTo'] as $address_kind) { if ($this->{$address_kind} === null) { $this->{$address_kind} = ''; continue; } $this->{$address_kind} = trim($this->{$address_kind}); if (empty($this->{$address_kind})) { continue; } $this->{$address_kind} = $this->punyencodeAddress($this->{$address_kind}); if (!static::validateAddress($this->{$address_kind})) { $error_message = sprintf( '%s (%s): %s', $this->lang('invalid_address'), $address_kind, $this->{$address_kind} ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { throw new Exception($error_message); } return false; } } //Set whether the message is multipart/alternative if ($this->alternativeExists()) { $this->ContentType = static::CONTENT_TYPE_MULTIPART_ALTERNATIVE; } $this->setMessageType(); //Refuse to send an empty message unless we are specifically allowing it if (!$this->AllowEmpty && empty($this->Body)) { throw new Exception($this->lang('empty_message'), self::STOP_CRITICAL); } //Trim subject consistently $this->Subject = trim($this->Subject); //Create body before headers in case body makes changes to headers (e.g. altering transfer encoding) $this->MIMEHeader = '';Changelog
Unchanged from 6.7.10 through 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.11 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.