You are here

public function PHPMailer::CreateHeader in SMTP Authentication Support 7

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

Assembles message header. @access public

Return value

string The assembled header

1 call to PHPMailer::CreateHeader()
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 1037
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

public function CreateHeader() {
  $result = '';

  // Set the boundaries
  $uniq_id = md5(uniqid(REQUEST_TIME));
  $this->boundary[1] = 'b1_' . $uniq_id;
  $this->boundary[2] = 'b2_' . $uniq_id;
  $result .= $this
    ->HeaderLine('Date', self::RFCDate());
  if ($this->Sender == '') {
    $result .= $this
      ->HeaderLine('Return-Path', trim($this->From));
  }
  else {
    $result .= $this
      ->HeaderLine('Return-Path', trim($this->Sender));
  }

  // To be created automatically by mail()
  if ($this->Mailer != 'mail') {
    if ($this->SingleTo === TRUE) {
      foreach ($this->to as $t) {
        $this->SingleToArray[] = $this
          ->AddrFormat($t);
      }
    }
    else {
      if (count($this->to) > 0) {
        $result .= $this
          ->AddrAppend('To', $this->to);
      }
      elseif (count($this->cc) == 0) {
        $result .= $this
          ->HeaderLine('To', 'undisclosed-recipients:;');
      }
    }
  }
  $from = array();
  $from[0][0] = trim($this->From);
  $from[0][1] = $this->FromName;
  $result .= $this
    ->AddrAppend('From', $from);

  // sendmail and mail() extract Cc from the header before sending
  if (count($this->cc) > 0) {
    $result .= $this
      ->AddrAppend('Cc', $this->cc);
  }

  // sendmail and mail() extract Bcc from the header before sending
  if (($this->Mailer == 'sendmail' || $this->Mailer == 'mail') && count($this->bcc) > 0) {
    $result .= $this
      ->AddrAppend('Bcc', $this->bcc);
  }
  if (count($this->ReplyTo) > 0) {
    $result .= $this
      ->AddrAppend('Reply-to', $this->ReplyTo);
  }

  // mail() sets the subject itself
  if ($this->Mailer != 'mail') {
    $result .= $this
      ->HeaderLine('Subject', $this
      ->EncodeHeader($this
      ->SecureHeader($this->Subject)));
  }
  if ($this->MessageID != '') {
    $result .= $this
      ->HeaderLine('Message-ID', $this->MessageID);
  }
  else {
    $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this
      ->ServerHostname(), $this->LE);
  }
  $result .= $this
    ->HeaderLine('X-Priority', $this->Priority);
  $result .= $this
    ->HeaderLine('X-Mailer', 'PHPMailer ' . $this->Version . ' (phpmailer.sourceforge.net)');
  if ($this->ConfirmReadingTo != '') {
    $result .= $this
      ->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
  }

  // Add custom headers
  for ($index = 0; $index < count($this->CustomHeader); $index++) {
    $result .= $this
      ->HeaderLine(trim($this->CustomHeader[$index][0]), $this
      ->EncodeHeader(trim($this->CustomHeader[$index][1])));
  }
  if (!$this->sign_key_file) {
    $result .= $this
      ->HeaderLine('MIME-Version', '1.0');
    $result .= $this
      ->GetMailMIME();
  }
  return $result;
}