You are here

public function PHPMailer::CreateBody in SMTP Authentication Support 7.2

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

Assembles the message body. Returns an empty string on failure. @access public

Return value

string The assembled message body

1 call to PHPMailer::CreateBody()
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 1147
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 CreateBody() {
  $body = '';
  if ($this->sign_key_file) {
    $body .= $this
      ->GetMailMIME();
  }
  $this
    ->SetWordWrap();
  switch ($this->message_type) {
    case 'alt':
      $body .= $this
        ->GetBoundary($this->boundary[1], '', 'text/plain', '');
      $body .= $this
        ->EncodeString($this->AltBody, $this->Encoding);
      $body .= $this->LE . $this->LE;
      $body .= $this
        ->GetBoundary($this->boundary[1], '', 'text/html', '');
      $body .= $this
        ->EncodeString($this->Body, $this->Encoding);
      $body .= $this->LE . $this->LE;
      $body .= $this
        ->EndBoundary($this->boundary[1]);
      break;
    case 'plain':
      $body .= $this
        ->EncodeString($this->Body, $this->Encoding);
      break;
    case 'attachments':
      if ($this->is_html) {
        $body .= $this
          ->GetBoundary($this->boundary[1], '', $this->is_html, '');
      }
      else {
        $body .= $this
          ->GetBoundary($this->boundary[1], '', '', '');
      }
      $body .= $this
        ->EncodeString($this->Body, $this->Encoding);
      $body .= $this->LE;
      $body .= $this
        ->AttachAll();
      break;
    case 'alt_attachments':
      $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
      $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE . $this->LE);
      $body .= $this
        ->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE;

      // Create text body
      $body .= $this
        ->EncodeString($this->AltBody, $this->Encoding);
      $body .= $this->LE . $this->LE;
      $body .= $this
        ->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE;

      // Create the HTML body
      $body .= $this
        ->EncodeString($this->Body, $this->Encoding);
      $body .= $this->LE . $this->LE;
      $body .= $this
        ->EndBoundary($this->boundary[2]);
      $body .= $this
        ->AttachAll();
      break;
  }
  if ($this
    ->IsError()) {
    $body = '';
  }
  elseif ($this->sign_key_file) {
    try {
      $file = tempnam('', 'mail');
      file_put_contents($file, $body);

      //TODO check this worked
      $signed = tempnam("", "signed");
      if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array(
        "file://" . $this->sign_key_file,
        $this->sign_key_pass,
      ), NULL)) {
        @unlink($file);
        @unlink($signed);
        $body = file_get_contents($signed);
      }
      else {
        @unlink($file);
        @unlink($signed);
        throw new phpmailerException(t('Signing Error: !err', array(
          '!err' => openssl_error_string(),
        )));
      }
    } catch (phpmailerException $e) {
      $body = '';
      if ($this->exceptions) {
        throw $e;
      }
    }
  }
  return $body;
}