protected function PHPMailer::mailSend

5.x PHPMailer.php protected PHPMailer::mailSend($header, $body)

Send mail using the PHP mail() function.

Parameters

string $header The message headers:

string $body The message body:

Return value

bool

Throws

Exception

See also

http://www.php.net/manual/en/book.mail.php

1 call to PHPMailer::mailSend()
PHPMailer::postSend in inc/PHPMailer/src/PHPMailer.php
Actually send a message via the selected mechanism.

File

inc/PHPMailer/src/PHPMailer.php, line 1703

Class

PHPMailer
PHPMailer - PHP email creation and transport class.

Namespace

PHPMailer\PHPMailer

Code

protected function mailSend($header, $body) 
 {
  $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
  if (!empty($this->Sender) and static::validateAddress($this->Sender)) {
    //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 (self::isShellSafe($this->Sender)) {
      $params = sprintf('-f%s', $this->Sender);
    }
  }
  if (!empty($this->Sender) and static::validateAddress($this->Sender)) {
    $old_from = ini_get('sendmail_from');
    ini_set('sendmail_from', $this->Sender);
  }
  $result = false;
  if ($this->SingleTo and count($toArr) > 1) {
    foreach ($toArr as $toAddr) {
      $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
      $this->doCallback($result, [$toAddr], $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($this->lang('instantiate'), self::STOP_CRITICAL);
  }

  return true;
}