WordPress at a glance
function is not described


PHPMailer::mailSend() protected WP 1.0

Send mail using the PHP mail() function.

{} It's a method of the class: PHPMailer{}

No Hooks.




// protected - for code of main (parent) or child class
$result = $this->mailSend( $header, $body );
$header(string) (required)
The message headers
$body(string) (required)
The message body


Code of PHPMailer::mailSend() WP 5.7.2

protected function mailSend($header, $body)
    $header = static::stripTrailingWSP($header) . static::$LE . static::$LE;

    $toArr = [];
    foreach ($this->to as $toaddr) {
        $toArr[] = $this->addrFormat($toaddr);
    $to = implode(', ', $toArr);

    $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: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
    //Sendmail docs: http://www.sendmail.org/~ca/email/man/sendmail.html
    //Qmail docs: http://www.qmail.org/man/man8/qmail-inject.html
    //Example problem: https://www.drupal.org/node/1057954
    //CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
    if (empty($this->Sender) && !empty(ini_get('sendmail_from'))) {
        //PHP config has a sender address we can use
        $this->Sender = ini_get('sendmail_from');
    if (!empty($this->Sender) && static::validateAddress($this->Sender)) {
        if (self::isShellSafe($this->Sender)) {
            $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);
                [[$addrinfo['address'], $addrinfo['name']]],
    } 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($this->lang('instantiate'), self::STOP_CRITICAL);

    return true;