You are here

protected function PHPMailer::MailSend in SMTP Authentication Support 7

Same name and namespace in other branches
  1. 5 smtp.module \PHPMailer::MailSend()
  2. 7.2 smtp.phpmailer.inc \PHPMailer::MailSend()

Sends mail using the PHP mail() function.

@access protected

Parameters

string $header The message headers:

string $body The message body:

Return value

bool

1 call to PHPMailer::MailSend()
PHPMailer::Send in ./smtp.phpmailer.inc
Creates message and assigns Mailer. If the message is not sent successfully then it returns FALSE. Use the ErrorInfo variable to view description of the error.

File

./smtp.phpmailer.inc, line 619
The mail handler class in smtp module, based on code of the phpmailer library, customized and relicensed to GPLv2.

Class

PHPMailer
PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later @package PHPMailer @author Andy Prevost @author Marcus Bointon @copyright 2004 - 2009 Andy Prevost

Code

protected function MailSend($header, $body) {
  $toArr = array();
  foreach ($this->to as $t) {
    $toArr[] = $this
      ->AddrFormat($t);
  }
  $to = implode(', ', $toArr);
  $params = sprintf("-oi -f %s", $this->Sender);
  if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
    $old_from = ini_get('sendmail_from');
    ini_set('sendmail_from', $this->Sender);
    if ($this->SingleTo === TRUE && count($toArr) > 1) {
      foreach ($toArr as $val) {
        $rt = @mail($val, $this
          ->EncodeHeader($this
          ->SecureHeader($this->Subject)), $body, $header, $params);

        // implement call back function if it exists
        $isSent = $rt == 1 ? 1 : 0;
        $this
          ->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
      }
    }
    else {
      $rt = @mail($to, $this
        ->EncodeHeader($this
        ->SecureHeader($this->Subject)), $body, $header, $params);

      // implement call back function if it exists
      $isSent = $rt == 1 ? 1 : 0;
      $this
        ->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    }
  }
  else {
    if ($this->SingleTo === TRUE && count($toArr) > 1) {
      foreach ($toArr as $val) {
        $rt = @mail($val, $this
          ->EncodeHeader($this
          ->SecureHeader($this->Subject)), $body, $header, $params);

        // implement call back function if it exists
        $isSent = $rt == 1 ? 1 : 0;
        $this
          ->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
      }
    }
    else {
      $rt = @mail($to, $this
        ->EncodeHeader($this
        ->SecureHeader($this->Subject)), $body, $header);

      // implement call back function if it exists
      $isSent = $rt == 1 ? 1 : 0;
      $this
        ->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    }
  }
  if (isset($old_from)) {
    ini_set('sendmail_from', $old_from);
  }
  if (!$rt) {
    throw new phpmailerException(t('Could not instantiate mail function.'), self::STOP_CRITICAL);
  }
  return TRUE;
}