wppaste
WordPress

PHPMailer::getMailMIME(): string

Source
wp-includes/PHPMailer/PHPMailer.php:2953
Get the message MIME type headers.

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.

Return value

string

Performance profile

How much work a call to PHPMailer::getMailMIME() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
32–60

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

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 one call costs · 6 distinct outcomes

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

WhenInstructionsCalls it makes
->validateEncoding()32–51->headerLine(), ->textLine(), ->validateEncoding()
->validateEncoding()34–54->secureHeader(), ->secureHeader(), ->textLine(), ->validateEncoding()
!->validateEncoding()36–50->headerLine(), ->textLine(), ->validateEncoding(), ::lang()
!->validateEncoding()38–53->secureHeader(), ->secureHeader(), ->textLine(), ->validateEncoding(), ::lang()
->validateEncoding()40–57->headerLine(), ->textLine(), ->validateEncoding(), ->headerLine()
->validateEncoding()42–60->secureHeader(), ->secureHeader(), ->textLine(), ->validateEncoding(), ->headerLine()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12532–6012
8.512532–6012
8.412532–6012
8.312532–6012
8.212532–60121 more instruction than PHP 8.1
8.112432–5912
7.412432–5912

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

  • \PHPMailer\PHPMailer\PHPMailer::headerLine()
  • \PHPMailer\PHPMailer\PHPMailer::textLine()
  • \PHPMailer\PHPMailer\PHPMailer::secureHeader()
  • \PHPMailer\PHPMailer\PHPMailer::validateEncoding()
  • \PHPMailer\PHPMailer\Exception::__construct()
  • \PHPMailer\PHPMailer\PHPMailer::lang()

Source code

    public function getMailMIME()    {        $result = '';        $ismultipart = true;        switch ($this->message_type) {            case 'inline':                $result .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_RELATED . ';');                $result .= $this->textLine(' boundary="' . $this->boundary[1] . '"');                break;            case 'attach':            case 'inline_attach':            case 'alt_attach':            case 'alt_inline_attach':                $result .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_MIXED . ';');                $result .= $this->textLine(' boundary="' . $this->boundary[1] . '"');                break;            case 'alt':            case 'alt_inline':                $result .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_ALTERNATIVE . ';');                $result .= $this->textLine(' boundary="' . $this->boundary[1] . '"');                break;            default:                //Catches case 'plain': and case '':                $result .= $this->textLine(                    'Content-Type: ' .                    $this->secureHeader($this->ContentType) .                    '; charset=' . $this->secureHeader($this->CharSet)                );                $ismultipart = false;                break;        }        if (!$this->validateEncoding($this->Encoding)) {            throw new Exception(self::lang('encoding') . $this->Encoding);        }        //RFC1341 part 5 says 7bit is assumed if not specified        if (static::ENCODING_7BIT !== $this->Encoding) {            //RFC 2045 section 6.4 says multipart MIME parts may only use 7bit, 8bit, or binary CTE            if ($ismultipart) {                if (static::ENCODING_8BIT === $this->Encoding) {                    $result .= $this->headerLine('Content-Transfer-Encoding', static::ENCODING_8BIT);                }                //The only remaining alternatives are quoted-printable and base64, which are both 7bit compatible            } else {                $result .= $this->headerLine('Content-Transfer-Encoding', $this->Encoding);            }        }         return $result;    }

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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.