WordPress at a glance
function is not described

PHPMailer\PHPMailer

PHPMailer::sendmailSend() protected WP 1.0

Send mail using the $Sendmail program.

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

No Hooks.

Return

true|false. Nothing.

Usage

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

Notes

  • See: PHPMailer::$Sendmail

Code of PHPMailer::sendmailSend() WP 5.7.2

<?php
protected function sendmailSend($header, $body)
{
    if ($this->Mailer === 'qmail') {
        $this->edebug('Sending with qmail');
    } else {
        $this->edebug('Sending with sendmail');
    }
    $header = static::stripTrailingWSP($header) . static::$LE . static::$LE;
    //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
    if (empty($this->Sender) && !empty(ini_get('sendmail_from'))) {
        //PHP config has a sender address we can use
        $this->Sender = ini_get('sendmail_from');
    }
    //CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
    if (!empty($this->Sender) && static::validateAddress($this->Sender) && self::isShellSafe($this->Sender)) {
        if ($this->Mailer === 'qmail') {
            $sendmailFmt = '%s -f%s';
        } else {
            $sendmailFmt = '%s -oi -f%s -t';
        }
    } else {
        //allow sendmail to choose a default envelope sender. It may
        //seem preferable to force it to use the From header as with
        //SMTP, but that introduces new problems (see
        //<https://github.com/PHPMailer/PHPMailer/issues/2298>), and
        //it has historically worked this way.
        $sendmailFmt = '%s -oi -t';
    }

    $sendmail = sprintf($sendmailFmt, escapeshellcmd($this->Sendmail), $this->Sender);
    $this->edebug('Sendmail path: ' . $this->Sendmail);
    $this->edebug('Sendmail command: ' . $sendmail);
    $this->edebug('Envelope sender: ' . $this->Sender);
    $this->edebug("Headers: {$header}");

    if ($this->SingleTo) {
        foreach ($this->SingleToArray as $toAddr) {
            $mail = @popen($sendmail, 'w');
            if (!$mail) {
                throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
            }
            $this->edebug("To: {$toAddr}");
            fwrite($mail, 'To: ' . $toAddr . "\n");
            fwrite($mail, $header);
            fwrite($mail, $body);
            $result = pclose($mail);
            $addrinfo = static::parseAddresses($toAddr);
            $this->doCallback(
                ($result === 0),
                [[$addrinfo['address'], $addrinfo['name']]],
                $this->cc,
                $this->bcc,
                $this->Subject,
                $body,
                $this->From,
                []
            );
            $this->edebug("Result: " . ($result === 0 ? 'true' : 'false'));
            if (0 !== $result) {
                throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
            }
        }
    } else {
        $mail = @popen($sendmail, 'w');
        if (!$mail) {
            throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
        }
        fwrite($mail, $header);
        fwrite($mail, $body);
        $result = pclose($mail);
        $this->doCallback(
            ($result === 0),
            $this->to,
            $this->cc,
            $this->bcc,
            $this->Subject,
            $body,
            $this->From,
            []
        );
        $this->edebug("Result: " . ($result === 0 ? 'true' : 'false'));
        if (0 !== $result) {
            throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
        }
    }

    return true;
}