You are here

function PHPMailer::CreateHeader in SMTP Authentication Support 5

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

Assembles message header. @access private

Return value

string

1 call to PHPMailer::CreateHeader()
PHPMailer::Send in ./smtp.module
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.module, line 1222
Enables drupal to send email directly to an SMTP server using authentication. Uses the PHPMailer class by Brent R. Matzelle.

Class

PHPMailer
PHPMailer - PHP email transport class @package PHPMailer @author Brent R. Matzelle @copyright 2001 - 2003 Brent R. Matzelle

Code

function CreateHeader() {
  $result = "";

  // Set the boundaries
  $uniq_id = md5(uniqid(time()));
  $this->boundary[1] = "b1_" . $uniq_id;
  $this->boundary[2] = "b2_" . $uniq_id;
  $result .= $this
    ->HeaderLine("Date", $this
    ->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 (count($this->to) > 0) {
      $result .= $this
        ->AddrAppend("To", $this->to);
    }
    else {
      if (count($this->cc) == 0) {
        $result .= $this
          ->HeaderLine("To", "undisclosed-recipients:;");
      }
    }
    if (count($this->cc) > 0) {
      $result .= $this
        ->AddrAppend("Cc", $this->cc);
    }
  }
  $from = array();
  $from[0][0] = trim($this->From);
  $from[0][1] = $this->FromName;
  $result .= $this
    ->AddrAppend("From", $from);

  // 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(trim($this->Subject)));
  }
  $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 [version " . $this->Version . "]");
  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->CustomHeader[$index][0] ? $this
      ->HeaderLine(trim($this->CustomHeader[$index][0]), $this
      ->EncodeHeader(trim($this->CustomHeader[$index][1]))) : '';
  }
  $result .= $this
    ->HeaderLine("MIME-Version", "1.0");
  switch ($this->message_type) {
    case "plain":
      $result .= $this
        ->HeaderLine("Content-Transfer-Encoding", $this->Encoding);
      $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
      break;
    case "attachments":

    // fall through
    case "alt_attachments":
      if ($this
        ->InlineImageExists()) {
        $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", "multipart/related", $this->LE, $this->LE, $this->boundary[1], $this->LE);
      }
      else {
        $result .= $this
          ->HeaderLine("Content-Type", "multipart/mixed;");
        $result .= $this
          ->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
      }
      break;
    case "alt":
      $result .= $this
        ->HeaderLine("Content-Type", "multipart/alternative;");
      $result .= $this
        ->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
      break;
    case "pre":

      // Content-Type header already added before passing to phpmailer(), leave it alone
      break;
  }
  if ($this->Mailer != "mail") {
    $result .= $this->LE . $this->LE;
  }
  return $result;
}