Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-phpmailer.php

    r18107 r11341  
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.1                                                            |
    6 |   Contact: via sourceforge.net support pages (also www.worxware.com)      |
     5|   Version: 2.0.4                                                          |
     6|   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
    77|      Info: http://phpmailer.sourceforge.net                               |
    88|   Support: http://sourceforge.net/projects/phpmailer/                     |
    99| ------------------------------------------------------------------------- |
    10 |     Admin: Andy Prevost (project admininistrator)                         |
    11 |   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
    12 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
    13 |   Founder: Brent R. Matzelle (original founder)                           |
    14 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               |
     10|    Author: Andy Prevost (project admininistrator)                         |
     11|    Author: Brent R. Matzelle (original founder)                           |
     12| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved.               |
    1513| Copyright (c) 2001-2003, Brent R. Matzelle                                |
    1614| ------------------------------------------------------------------------- |
     
    2119| FITNESS FOR A PARTICULAR PURPOSE.                                         |
    2220| ------------------------------------------------------------------------- |
    23 | We offer a number of paid services (www.worxware.com):                    |
     21| We offer a number of paid services (www.codeworxtech.com):                |
    2422| - Web Hosting on highly optimized fast and secure servers                 |
    2523| - Technology Consulting                                                   |
    2624| - Oursourcing (highly qualified programmers and graphic designers)        |
    2725'---------------------------------------------------------------------------'
    28 */
    29 
     26 */
    3027/**
    3128 * PHPMailer - PHP email transport class
    32  * NOTE: Requires PHP version 5 or later
    3329 * @package PHPMailer
    3430 * @author Andy Prevost
    35  * @author Marcus Bointon
    3631 * @copyright 2004 - 2009 Andy Prevost
    37  * @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $
    38  * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
    3932 */
    40 
    41 if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
    4233
    4334class PHPMailer {
     
    5142   * @var int
    5243   */
    53   public $Priority          = 3;
     44  var $Priority          = 3;
    5445
    5546  /**
     
    5748   * @var string
    5849   */
    59   public $CharSet           = 'iso-8859-1';
     50  var $CharSet           = 'iso-8859-1';
    6051
    6152  /**
     
    6354   * @var string
    6455   */
    65   public $ContentType       = 'text/plain';
    66 
    67   /**
    68    * Sets the Encoding of the message. Options for this are
    69    *  "8bit", "7bit", "binary", "base64", and "quoted-printable".
    70    * @var string
    71    */
    72   public $Encoding          = '8bit';
     56  var $ContentType        = 'text/plain';
     57
     58  /**
     59   * Sets the Encoding of the message. Options for this are "8bit",
     60   * "7bit", "binary", "base64", and "quoted-printable".
     61   * @var string
     62   */
     63  var $Encoding          = '8bit';
    7364
    7465  /**
     
    7667   * @var string
    7768   */
    78   public $ErrorInfo         = '';
     69  var $ErrorInfo         = '';
    7970
    8071  /**
     
    8273   * @var string
    8374   */
    84   public $From              = 'root@localhost';
     75  var $From              = 'root@localhost';
    8576
    8677  /**
     
    8879   * @var string
    8980   */
    90   public $FromName          = 'Root User';
     81  var $FromName          = 'Root User';
    9182
    9283  /**
     
    9586   * @var string
    9687   */
    97   public $Sender            = '';
     88  var $Sender            = '';
    9889
    9990  /**
     
    10192   * @var string
    10293   */
    103   public $Subject           = '';
     94  var $Subject           = '';
    10495
    10596  /**
     
    10899   * @var string
    109100   */
    110   public $Body              = '';
     101  var $Body              = '';
    111102
    112103  /**
     
    117108   * @var string
    118109   */
    119   public $AltBody           = '';
     110  var $AltBody           = '';
    120111
    121112  /**
     
    124115   * @var int
    125116   */
    126   public $WordWrap          = 0;
     117  var $WordWrap          = 0;
    127118
    128119  /**
     
    130121   * @var string
    131122   */
    132   public $Mailer            = 'mail';
     123  var $Mailer            = 'mail';
    133124
    134125  /**
     
    136127   * @var string
    137128   */
    138   public $Sendmail          = '/usr/sbin/sendmail';
    139 
    140   /**
    141    * Path to PHPMailer plugins.  Useful if the SMTP class
     129  var $Sendmail          = '/usr/sbin/sendmail';
     130
     131  /**
     132   * Path to PHPMailer plugins.  This is now only useful if the SMTP class
    142133   * is in a different directory than the PHP include path.
    143134   * @var string
    144135   */
    145   public $PluginDir         = '';
     136  var $PluginDir         = '';
     137
     138  /**
     139   * Holds PHPMailer version.
     140   * @var string
     141   */
     142  var $Version           = "2.0.4";
    146143
    147144  /**
     
    149146   * @var string
    150147   */
    151   public $ConfirmReadingTo  = '';
     148  var $ConfirmReadingTo  = '';
    152149
    153150  /**
     
    157154   * @var string
    158155   */
    159   public $Hostname          = '';
     156  var $Hostname          = '';
    160157
    161158  /**
     
    164161   * @var string
    165162   */
    166   public $MessageID         = '';
     163  var $MessageID         = '';
    167164
    168165  /////////////////////////////////////////////////
     
    178175   * @var string
    179176   */
    180   public $Host          = 'localhost';
     177  var $Host        = 'localhost';
    181178
    182179  /**
     
    184181   * @var int
    185182   */
    186   public $Port          = 25;
     183  var $Port        = 25;
    187184
    188185  /**
     
    190187   * @var string
    191188   */
    192   public $Helo          = '';
     189  var $Helo        = '';
    193190
    194191  /**
     
    197194   * @var string
    198195   */
    199   public $SMTPSecure    = '';
     196  var $SMTPSecure = "";
    200197
    201198  /**
     
    203200   * @var bool
    204201   */
    205   public $SMTPAuth      = false;
     202  var $SMTPAuth     = false;
    206203
    207204  /**
     
    209206   * @var string
    210207   */
    211   public $Username      = '';
     208  var $Username     = '';
    212209
    213210  /**
     
    215212   * @var string
    216213   */
    217   public $Password      = '';
    218 
    219   /**
    220    * Sets the SMTP server timeout in seconds.
    221    * This function will not work with the win32 version.
     214  var $Password     = '';
     215
     216  /**
     217   * Sets the SMTP server timeout in seconds. This function will not
     218   * work with the win32 version.
    222219   * @var int
    223220   */
    224   public $Timeout       = 10;
     221  var $Timeout      = 10;
    225222
    226223  /**
     
    228225   * @var bool
    229226   */
    230   public $SMTPDebug     = false;
     227  var $SMTPDebug    = false;
    231228
    232229  /**
     
    236233   * @var bool
    237234   */
    238   public $SMTPKeepAlive = false;
     235  var $SMTPKeepAlive = false;
    239236
    240237  /**
     
    243240   * @var bool
    244241   */
    245   public $SingleTo      = false;
    246 
    247    /**
    248    * If SingleTo is true, this provides the array to hold the email addresses
    249    * @var bool
    250    */
    251   public $SingleToArray = array();
    252 
    253  /**
    254    * Provides the ability to change the line ending
    255    * @var string
    256    */
    257   public $LE              = "\n";
    258 
    259   /**
    260    * Used with DKIM DNS Resource Record
    261    * @var string
    262    */
    263   public $DKIM_selector   = 'phpmailer';
    264 
    265   /**
    266    * Used with DKIM DNS Resource Record
    267    * optional, in format of email address 'you@yourdomain.com'
    268    * @var string
    269    */
    270   public $DKIM_identity   = '';
    271 
    272   /**
    273    * Used with DKIM DNS Resource Record
    274    * optional, in format of email address 'you@yourdomain.com'
    275    * @var string
    276    */
    277   public $DKIM_domain     = '';
    278 
    279   /**
    280    * Used with DKIM DNS Resource Record
    281    * optional, in format of email address 'you@yourdomain.com'
    282    * @var string
    283    */
    284   public $DKIM_private    = '';
    285 
    286   /**
    287    * Callback Action function name
    288    * the function that handles the result of the send email action. Parameters:
    289    *   bool    $result        result of the send action
    290    *   string  $to            email address of the recipient
    291    *   string  $cc            cc email addresses
    292    *   string  $bcc           bcc email addresses
    293    *   string  $subject       the subject
    294    *   string  $body          the email body
    295    * @var string
    296    */
    297   public $action_function = ''; //'callbackAction';
    298 
    299   /**
    300    * Sets the PHPMailer Version number
    301    * @var string
    302    */
    303   public $Version         = '5.1';
     242  var $SingleTo = false;
    304243
    305244  /////////////////////////////////////////////////
    306   // PROPERTIES, PRIVATE AND PROTECTED
     245  // PROPERTIES, PRIVATE
    307246  /////////////////////////////////////////////////
    308247
    309   private   $smtp           = NULL;
    310   private   $to             = array();
    311   private   $cc             = array();
    312   private   $bcc            = array();
    313   private   $ReplyTo        = array();
    314   private   $all_recipients = array();
    315   private   $attachment     = array();
    316   private   $CustomHeader   = array();
    317   private   $message_type   = '';
    318   private   $boundary       = array();
    319   protected $language       = array();
    320   private   $error_count    = 0;
    321   private   $sign_cert_file = "";
    322   private   $sign_key_file  = "";
    323   private   $sign_key_pass  = "";
    324   private   $exceptions     = false;
    325 
    326   /////////////////////////////////////////////////
    327   // CONSTANTS
    328   /////////////////////////////////////////////////
    329 
    330   const STOP_MESSAGE  = 0; // message only, continue processing
    331   const STOP_CONTINUE = 1; // message?, likely ok to continue processing
    332   const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
     248  var $smtp            = NULL;
     249  var $to              = array();
     250  var $cc              = array();
     251  var $bcc             = array();
     252  var $ReplyTo         = array();
     253  var $attachment      = array();
     254  var $CustomHeader    = array();
     255  var $message_type    = '';
     256  var $boundary        = array();
     257  var $language        = array();
     258  var $error_count     = 0;
     259  var $LE              = "\n";
     260  var $sign_cert_file  = "";
     261  var $sign_key_file   = "";
     262  var $sign_key_pass   = "";
    333263
    334264  /////////////////////////////////////////////////
     
    337267
    338268  /**
    339    * Constructor
    340    * @param boolean $exceptions Should we throw external exceptions?
    341    */
    342   public function __construct($exceptions = false) {
    343     $this->exceptions = ($exceptions == true);
    344   }
    345 
    346   /**
    347269   * Sets message type to HTML.
    348    * @param bool $ishtml
    349    * @return void
    350    */
    351   public function IsHTML($ishtml = true) {
    352     if ($ishtml) {
     270   * @param bool $bool
     271   * @return void
     272   */
     273  function IsHTML($bool) {
     274    if($bool == true) {
    353275      $this->ContentType = 'text/html';
    354276    } else {
     
    361283   * @return void
    362284   */
    363   public function IsSMTP() {
     285  function IsSMTP() {
    364286    $this->Mailer = 'smtp';
    365287  }
     
    369291   * @return void
    370292   */
    371   public function IsMail() {
     293  function IsMail() {
    372294    $this->Mailer = 'mail';
    373295  }
     
    377299   * @return void
    378300   */
    379   public function IsSendmail() {
    380     if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
    381       $this->Sendmail = '/var/qmail/bin/sendmail';
    382     }
     301  function IsSendmail() {
    383302    $this->Mailer = 'sendmail';
    384303  }
     
    388307   * @return void
    389308   */
    390   public function IsQmail() {
    391     if (stristr(ini_get('sendmail_path'), 'qmail')) {
    392       $this->Sendmail = '/var/qmail/bin/sendmail';
    393     }
     309  function IsQmail() {
     310    $this->Sendmail = '/var/qmail/bin/sendmail';
    394311    $this->Mailer = 'sendmail';
    395312  }
     
    403320   * @param string $address
    404321   * @param string $name
    405    * @return boolean true on success, false if address already used
    406    */
    407   public function AddAddress($address, $name = '') {
    408     return $this->AddAnAddress('to', $address, $name);
    409   }
    410 
    411   /**
    412    * Adds a "Cc" address.
    413    * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
     322   * @return void
     323   */
     324  function AddAddress($address, $name = '') {
     325    $cur = count($this->to);
     326    $this->to[$cur][0] = trim($address);
     327    $this->to[$cur][1] = $name;
     328  }
     329
     330  /**
     331   * Adds a "Cc" address. Note: this function works
     332   * with the SMTP mailer on win32, not with the "mail"
     333   * mailer.
    414334   * @param string $address
    415335   * @param string $name
    416    * @return boolean true on success, false if address already used
    417    */
    418   public function AddCC($address, $name = '') {
    419     return $this->AddAnAddress('cc', $address, $name);
    420   }
    421 
    422   /**
    423    * Adds a "Bcc" address.
    424    * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
     336   * @return void
     337   */
     338  function AddCC($address, $name = '') {
     339    $cur = count($this->cc);
     340    $this->cc[$cur][0] = trim($address);
     341    $this->cc[$cur][1] = $name;
     342  }
     343
     344  /**
     345   * Adds a "Bcc" address. Note: this function works
     346   * with the SMTP mailer on win32, not with the "mail"
     347   * mailer.
    425348   * @param string $address
    426349   * @param string $name
    427    * @return boolean true on success, false if address already used
    428    */
    429   public function AddBCC($address, $name = '') {
    430     return $this->AddAnAddress('bcc', $address, $name);
    431   }
    432 
    433   /**
    434    * Adds a "Reply-to" address.
     350   * @return void
     351   */
     352  function AddBCC($address, $name = '') {
     353    $cur = count($this->bcc);
     354    $this->bcc[$cur][0] = trim($address);
     355    $this->bcc[$cur][1] = $name;
     356  }
     357
     358  /**
     359   * Adds a "Reply-To" address.
    435360   * @param string $address
    436361   * @param string $name
    437    * @return boolean
    438    */
    439   public function AddReplyTo($address, $name = '') {
    440     return $this->AddAnAddress('ReplyTo', $address, $name);
    441   }
    442 
    443   /**
    444    * Adds an address to one of the recipient arrays
    445    * Addresses that have been added already return false, but do not throw exceptions
    446    * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
    447    * @param string $address The email address to send to
    448    * @param string $name
    449    * @return boolean true on success, false if address already used or invalid in some way
    450    * @access private
    451    */
    452   private function AddAnAddress($kind, $address, $name = '') {
    453     if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
    454       echo 'Invalid recipient array: ' . $kind;
    455       return false;
    456     }
    457     $address = trim($address);
    458     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    459     if (!self::ValidateAddress($address)) {
    460       $this->SetError($this->Lang('invalid_address').': '. $address);
    461       if ($this->exceptions) {
    462         throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    463       }
    464       echo $this->Lang('invalid_address').': '.$address;
    465       return false;
    466     }
    467     if ($kind != 'ReplyTo') {
    468       if (!isset($this->all_recipients[strtolower($address)])) {
    469         array_push($this->$kind, array($address, $name));
    470         $this->all_recipients[strtolower($address)] = true;
    471         return true;
    472       }
    473     } else {
    474       if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
    475         $this->ReplyTo[strtolower($address)] = array($address, $name);
    476       return true;
    477     }
    478   }
    479   return false;
    480 }
    481 
    482 /**
    483  * Set the From and FromName properties
    484  * @param string $address
    485  * @param string $name
    486  * @return boolean
    487  */
    488   public function SetFrom($address, $name = '',$auto=1) {
    489     $address = trim($address);
    490     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    491     if (!self::ValidateAddress($address)) {
    492       $this->SetError($this->Lang('invalid_address').': '. $address);
    493       if ($this->exceptions) {
    494         throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    495       }
    496       echo $this->Lang('invalid_address').': '.$address;
    497       return false;
    498     }
    499     $this->From = $address;
    500     $this->FromName = $name;
    501     if ($auto) {
    502       if (empty($this->ReplyTo)) {
    503         $this->AddAnAddress('ReplyTo', $address, $name);
    504       }
    505       if (empty($this->Sender)) {
    506         $this->Sender = $address;
    507       }
    508     }
    509     return true;
    510   }
    511 
    512   /**
    513    * Check that a string looks roughly like an email address should
    514    * Static so it can be used without instantiation
    515    * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
    516    * Conforms approximately to RFC2822
    517    * @link http://www.hexillion.com/samples/#Regex Original pattern found here
    518    * @param string $address The email address to check
    519    * @return boolean
    520    * @static
    521    * @access public
    522    */
    523   public static function ValidateAddress($address) {
    524     if (function_exists('filter_var')) { //Introduced in PHP 5.2
    525       if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
    526         return false;
    527       } else {
    528         return true;
    529       }
    530     } else {
    531       return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
    532     }
     362   * @return void
     363   */
     364  function AddReplyTo($address, $name = '') {
     365    $cur = count($this->ReplyTo);
     366    $this->ReplyTo[$cur][0] = trim($address);
     367    $this->ReplyTo[$cur][1] = $name;
    533368  }
    534369
     
    543378   * @return bool
    544379   */
    545   public function Send() {
    546     try {
    547       if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
    548         throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
    549       }
    550 
    551       // Set whether the message is multipart/alternative
    552       if(!empty($this->AltBody)) {
    553         $this->ContentType = 'multipart/alternative';
    554       }
    555 
    556       $this->error_count = 0; // reset errors
    557       $this->SetMessageType();
    558       $header = $this->CreateHeader();
    559       $body = $this->CreateBody();
    560 
    561       if (empty($this->Body)) {
    562         throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
    563       }
    564 
    565       // digitally sign with DKIM if enabled
    566       if ($this->DKIM_domain && $this->DKIM_private) {
    567         $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
    568         $header = str_replace("\r\n","\n",$header_dkim) . $header;
    569       }
    570 
    571       // Choose the mailer and send through it
    572       switch($this->Mailer) {
    573         case 'sendmail':
    574           return $this->SendmailSend($header, $body);
    575         case 'smtp':
    576           return $this->SmtpSend($header, $body);
    577         default:
    578           return $this->MailSend($header, $body);
    579       }
    580 
    581     } catch (phpmailerException $e) {
    582       $this->SetError($e->getMessage());
    583       if ($this->exceptions) {
    584         throw $e;
    585       }
    586       echo $e->getMessage()."\n";
     380  function Send() {
     381    $header = '';
     382    $body = '';
     383    $result = true;
     384
     385    if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
     386      $this->SetError($this->Lang('provide_address'));
    587387      return false;
    588388    }
     389
     390    /* Set whether the message is multipart/alternative */
     391    if(!empty($this->AltBody)) {
     392      $this->ContentType = 'multipart/alternative';
     393    }
     394
     395    $this->error_count = 0; // reset errors
     396    $this->SetMessageType();
     397    $header .= $this->CreateHeader();
     398    $body = $this->CreateBody();
     399
     400    if($body == '') {
     401      return false;
     402    }
     403
     404    /* Choose the mailer */
     405    switch($this->Mailer) {
     406      case 'sendmail':
     407        $result = $this->SendmailSend($header, $body);
     408        break;
     409      case 'smtp':
     410        $result = $this->SmtpSend($header, $body);
     411        break;
     412      case 'mail':
     413        $result = $this->MailSend($header, $body);
     414        break;
     415      default:
     416        $result = $this->MailSend($header, $body);
     417        break;
     418        //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
     419        //$result = false;
     420        //break;
     421    }
     422
     423    return $result;
    589424  }
    590425
    591426  /**
    592427   * Sends mail using the $Sendmail program.
    593    * @param string $header The message headers
    594    * @param string $body The message body
    595    * @access protected
     428   * @access private
    596429   * @return bool
    597430   */
    598   protected function SendmailSend($header, $body) {
     431  function SendmailSend($header, $body) {
    599432    if ($this->Sender != '') {
    600433      $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
     
    602435      $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
    603436    }
    604     if ($this->SingleTo === true) {
    605       foreach ($this->SingleToArray as $key => $val) {
    606         if(!@$mail = popen($sendmail, 'w')) {
    607           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
    608         }
    609         fputs($mail, "To: " . $val . "\n");
    610         fputs($mail, $header);
    611         fputs($mail, $body);
    612         $result = pclose($mail);
    613         // implement call back function if it exists
    614         $isSent = ($result == 0) ? 1 : 0;
    615         $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
    616         if($result != 0) {
    617           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
    618         }
    619       }
    620     } else {
    621       if(!@$mail = popen($sendmail, 'w')) {
    622         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
    623       }
    624       fputs($mail, $header);
    625       fputs($mail, $body);
    626       $result = pclose($mail);
    627       // implement call back function if it exists
    628       $isSent = ($result == 0) ? 1 : 0;
    629       $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
    630       if($result != 0) {
    631         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
    632       }
     437
     438    if(!@$mail = popen($sendmail, 'w')) {
     439      $this->SetError($this->Lang('execute') . $this->Sendmail);
     440      return false;
     441    }
     442
     443    fputs($mail, $header);
     444    fputs($mail, $body);
     445
     446    $result = pclose($mail);
     447    if (version_compare(phpversion(), '4.2.3') == -1) {
     448      $result = $result >> 8 & 0xFF;
     449    }
     450    if($result != 0) {
     451      $this->SetError($this->Lang('execute') . $this->Sendmail);
     452      return false;
    633453    }
    634454    return true;
     
    637457  /**
    638458   * Sends mail using the PHP mail() function.
    639    * @param string $header The message headers
    640    * @param string $body The message body
    641    * @access protected
     459   * @access private
    642460   * @return bool
    643461   */
    644   protected function MailSend($header, $body) {
    645     $toArr = array();
    646     foreach($this->to as $t) {
    647       $toArr[] = $this->AddrFormat($t);
    648     }
    649     $to = implode(', ', $toArr);
     462  function MailSend($header, $body) {
     463
     464    $to = '';
     465    for($i = 0; $i < count($this->to); $i++) {
     466      if($i != 0) { $to .= ', '; }
     467      $to .= $this->AddrFormat($this->to[$i]);
     468    }
     469
     470    $toArr = split(',', $to);
    650471
    651472    $params = sprintf("-oi -f %s", $this->Sender);
    652     if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
     473    if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
    653474      $old_from = ini_get('sendmail_from');
    654475      ini_set('sendmail_from', $this->Sender);
     
    656477        foreach ($toArr as $key => $val) {
    657478          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
    658           // implement call back function if it exists
    659           $isSent = ($rt == 1) ? 1 : 0;
    660           $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
    661479        }
    662480      } else {
    663481        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
    664         // implement call back function if it exists
    665         $isSent = ($rt == 1) ? 1 : 0;
    666         $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
    667482      }
    668483    } else {
     
    670485        foreach ($toArr as $key => $val) {
    671486          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
    672           // implement call back function if it exists
    673           $isSent = ($rt == 1) ? 1 : 0;
    674           $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
    675487        }
    676488      } else {
    677489        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
    678         // implement call back function if it exists
    679         $isSent = ($rt == 1) ? 1 : 0;
    680         $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
    681       }
    682     }
     490      }
     491    }
     492
    683493    if (isset($old_from)) {
    684494      ini_set('sendmail_from', $old_from);
    685495    }
     496
    686497    if(!$rt) {
    687       throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
    688     }
     498      $this->SetError($this->Lang('instantiate'));
     499      return false;
     500    }
     501
    689502    return true;
    690503  }
    691504
    692505  /**
    693    * Sends mail via SMTP using PhpSMTP
    694    * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
    695    * @param string $header The message headers
    696    * @param string $body The message body
    697    * @uses SMTP
    698    * @access protected
     506   * Sends mail via SMTP using PhpSMTP (Author:
     507   * Chris Ryan).  Returns bool.  Returns false if there is a
     508   * bad MAIL FROM, RCPT, or DATA input.
     509   * @access private
    699510   * @return bool
    700511   */
    701   protected function SmtpSend($header, $body) {
    702     require_once $this->PluginDir . 'class-smtp.php';
     512  function SmtpSend($header, $body) {
     513    include_once($this->PluginDir . 'class-smtp.php');
     514    $error = '';
    703515    $bad_rcpt = array();
    704516
    705517    if(!$this->SmtpConnect()) {
    706       throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
    707     }
     518      return false;
     519    }
     520
    708521    $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
    709522    if(!$this->smtp->Mail($smtp_from)) {
    710       throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
    711     }
    712 
    713     // Attempt to send attach all recipients
    714     foreach($this->to as $to) {
    715       if (!$this->smtp->Recipient($to[0])) {
    716         $bad_rcpt[] = $to[0];
    717         // implement call back function if it exists
    718         $isSent = 0;
    719         $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
    720       } else {
    721         // implement call back function if it exists
    722         $isSent = 1;
    723         $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
    724       }
    725     }
    726     foreach($this->cc as $cc) {
    727       if (!$this->smtp->Recipient($cc[0])) {
    728         $bad_rcpt[] = $cc[0];
    729         // implement call back function if it exists
    730         $isSent = 0;
    731         $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
    732       } else {
    733         // implement call back function if it exists
    734         $isSent = 1;
    735         $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
    736       }
    737     }
    738     foreach($this->bcc as $bcc) {
    739       if (!$this->smtp->Recipient($bcc[0])) {
    740         $bad_rcpt[] = $bcc[0];
    741         // implement call back function if it exists
    742         $isSent = 0;
    743         $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
    744       } else {
    745         // implement call back function if it exists
    746         $isSent = 1;
    747         $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
    748       }
    749     }
    750 
    751 
    752     if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses
    753       $badaddresses = implode(', ', $bad_rcpt);
    754       throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
    755     }
     523      $error = $this->Lang('from_failed') . $smtp_from;
     524      $this->SetError($error);
     525      $this->smtp->Reset();
     526      return false;
     527    }
     528
     529    /* Attempt to send attach all recipients */
     530    for($i = 0; $i < count($this->to); $i++) {
     531      if(!$this->smtp->Recipient($this->to[$i][0])) {
     532        $bad_rcpt[] = $this->to[$i][0];
     533      }
     534    }
     535    for($i = 0; $i < count($this->cc); $i++) {
     536      if(!$this->smtp->Recipient($this->cc[$i][0])) {
     537        $bad_rcpt[] = $this->cc[$i][0];
     538      }
     539    }
     540    for($i = 0; $i < count($this->bcc); $i++) {
     541      if(!$this->smtp->Recipient($this->bcc[$i][0])) {
     542        $bad_rcpt[] = $this->bcc[$i][0];
     543      }
     544    }
     545
     546    if(count($bad_rcpt) > 0) { // Create error message
     547      for($i = 0; $i < count($bad_rcpt); $i++) {
     548        if($i != 0) {
     549          $error .= ', ';
     550        }
     551        $error .= $bad_rcpt[$i];
     552      }
     553      $error = $this->Lang('recipients_failed') . $error;
     554      $this->SetError($error);
     555      $this->smtp->Reset();
     556      return false;
     557    }
     558
    756559    if(!$this->smtp->Data($header . $body)) {
    757       throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
     560      $this->SetError($this->Lang('data_not_accepted'));
     561      $this->smtp->Reset();
     562      return false;
    758563    }
    759564    if($this->SMTPKeepAlive == true) {
    760565      $this->smtp->Reset();
    761     }
     566    } else {
     567      $this->SmtpClose();
     568    }
     569
    762570    return true;
    763571  }
    764572
    765573  /**
    766    * Initiates a connection to an SMTP server.
    767    * Returns false if the operation failed.
    768    * @uses SMTP
    769    * @access public
     574   * Initiates a connection to an SMTP server.  Returns false if the
     575   * operation failed.
     576   * @access private
    770577   * @return bool
    771578   */
    772   public function SmtpConnect() {
    773     if(is_null($this->smtp)) {
     579  function SmtpConnect() {
     580    if($this->smtp == NULL) {
    774581      $this->smtp = new SMTP();
    775582    }
     
    778585    $hosts = explode(';', $this->Host);
    779586    $index = 0;
    780     $connection = $this->smtp->Connected();
    781 
    782     // Retry while there is no connection
    783     try {
    784       while($index < count($hosts) && !$connection) {
    785         $hostinfo = array();
    786         if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
    787           $host = $hostinfo[1];
    788           $port = $hostinfo[2];
     587    $connection = ($this->smtp->Connected());
     588
     589    /* Retry while there is no connection */
     590    while($index < count($hosts) && $connection == false) {
     591      $hostinfo = array();
     592      if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
     593        $host = $hostinfo[1];
     594        $port = $hostinfo[2];
     595      } else {
     596        $host = $hosts[$index];
     597        $port = $this->Port;
     598      }
     599
     600      if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
     601        if ($this->Helo != '') {
     602          $this->smtp->Hello($this->Helo);
    789603        } else {
    790           $host = $hosts[$index];
    791           $port = $this->Port;
     604          $this->smtp->Hello($this->ServerHostname());
    792605        }
    793606
    794         $tls = ($this->SMTPSecure == 'tls');
    795         $ssl = ($this->SMTPSecure == 'ssl');
    796 
    797         if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
    798 
    799           $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
    800           $this->smtp->Hello($hello);
    801 
    802           if ($tls) {
    803             if (!$this->smtp->StartTLS()) {
    804               throw new phpmailerException($this->Lang('tls'));
    805             }
    806 
    807             //We must resend HELO after tls negotiation
    808             $this->smtp->Hello($hello);
    809           }
    810 
    811           $connection = true;
    812           if ($this->SMTPAuth) {
    813             if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
    814               throw new phpmailerException($this->Lang('authenticate'));
    815             }
     607        $connection = true;
     608        if($this->SMTPAuth) {
     609          if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
     610            $this->SetError($this->Lang('authenticate'));
     611            $this->smtp->Reset();
     612            $connection = false;
    816613          }
    817614        }
    818         $index++;
    819         if (!$connection) {
    820           throw new phpmailerException($this->Lang('connect_host'));
    821         }
    822       }
    823     } catch (phpmailerException $e) {
    824       $this->smtp->Reset();
    825       throw $e;
    826     }
    827     return true;
     615      }
     616      $index++;
     617    }
     618    if(!$connection) {
     619      $this->SetError($this->Lang('connect_host'));
     620    }
     621
     622    return $connection;
    828623  }
    829624
     
    832627   * @return void
    833628   */
    834   public function SmtpClose() {
    835     if(!is_null($this->smtp)) {
     629  function SmtpClose() {
     630    if($this->smtp != NULL) {
    836631      if($this->smtp->Connected()) {
    837632        $this->smtp->Quit();
     
    842637
    843638  /**
    844   * Sets the language for all class error messages.
    845   * Returns false if it cannot load the language file.  The default language is English.
    846   * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
    847   * @param string $lang_path Path to the language file directory
    848   * @access public
    849   */
    850   function SetLanguage($langcode = 'en', $lang_path = 'language/') {
    851     //Define full set of translatable strings
    852     $PHPMAILER_LANG = array(
    853       'provide_address' => 'You must provide at least one recipient email address.',
    854       'mailer_not_supported' => ' mailer is not supported.',
    855       'execute' => 'Could not execute: ',
    856       'instantiate' => 'Could not instantiate mail function.',
    857       'authenticate' => 'SMTP Error: Could not authenticate.',
    858       'from_failed' => 'The following From address failed: ',
    859       'recipients_failed' => 'SMTP Error: The following recipients failed: ',
    860       'data_not_accepted' => 'SMTP Error: Data not accepted.',
    861       'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
    862       'file_access' => 'Could not access file: ',
    863       'file_open' => 'File Error: Could not open file: ',
    864       'encoding' => 'Unknown encoding: ',
    865       'signing' => 'Signing Error: ',
    866       'smtp_error' => 'SMTP server error: ',
    867       'empty_message' => 'Message body empty',
    868       'invalid_address' => 'Invalid address',
    869       'variable_set' => 'Cannot set or reset variable: '
    870     );
    871     //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
    872     $l = true;
    873     if ($langcode != 'en') { //There is no English translation file
    874       $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
     639   * Sets the language for all class error messages.  Returns false
     640   * if it cannot load the language file.  The default language type
     641   * is English.
     642   * @param string $lang_type Type of language (e.g. Portuguese: "br")
     643   * @param string $lang_path Path to the language file directory
     644   * @access public
     645   * @return bool
     646   */
     647  function SetLanguage($lang_type, $lang_path = 'language/') {
     648    if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
     649      include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
     650    } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
     651      include($lang_path.'phpmailer.lang-en.php');
     652    } else {
     653      $PHPMAILER_LANG = array();
     654      $PHPMAILER_LANG["provide_address"]      = 'You must provide at least one ' .
     655      $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
     656      $PHPMAILER_LANG["execute"]              = 'Could not execute: ';
     657      $PHPMAILER_LANG["instantiate"]          = 'Could not instantiate mail function.';
     658      $PHPMAILER_LANG["authenticate"]         = 'SMTP Error: Could not authenticate.';
     659      $PHPMAILER_LANG["from_failed"]          = 'The following From address failed: ';
     660      $PHPMAILER_LANG["recipients_failed"]    = 'SMTP Error: The following ' .
     661      $PHPMAILER_LANG["data_not_accepted"]    = 'SMTP Error: Data not accepted.';
     662      $PHPMAILER_LANG["connect_host"]         = 'SMTP Error: Could not connect to SMTP host.';
     663      $PHPMAILER_LANG["file_access"]          = 'Could not access file: ';
     664      $PHPMAILER_LANG["file_open"]            = 'File Error: Could not open file: ';
     665      $PHPMAILER_LANG["encoding"]             = 'Unknown encoding: ';
     666      $PHPMAILER_LANG["signing"]              = 'Signing Error: ';
    875667    }
    876668    $this->language = $PHPMAILER_LANG;
    877     return ($l == true); //Returns false if language not found
    878   }
    879 
    880   /**
    881   * Return the current array of language strings
    882   * @return array
    883   */
    884   public function GetTranslations() {
    885     return $this->language;
     669
     670    return true;
    886671  }
    887672
     
    892677  /**
    893678   * Creates recipient headers.
    894    * @access public
    895    * @return string
    896    */
    897   public function AddrAppend($type, $addr) {
     679   * @access private
     680   * @return string
     681   */
     682  function AddrAppend($type, $addr) {
    898683    $addr_str = $type . ': ';
    899     $addresses = array();
    900     foreach ($addr as $a) {
    901       $addresses[] = $this->AddrFormat($a);
    902     }
    903     $addr_str .= implode(', ', $addresses);
     684    $addr_str .= $this->AddrFormat($addr[0]);
     685    if(count($addr) > 1) {
     686      for($i = 1; $i < count($addr); $i++) {
     687        $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
     688      }
     689    }
    904690    $addr_str .= $this->LE;
    905691
     
    909695  /**
    910696   * Formats an address correctly.
    911    * @access public
    912    * @return string
    913    */
    914   public function AddrFormat($addr) {
    915     if (empty($addr[1])) {
    916       return $this->SecureHeader($addr[0]);
     697   * @access private
     698   * @return string
     699   */
     700  function AddrFormat($addr) {
     701    if(empty($addr[1])) {
     702      $formatted = $this->SecureHeader($addr[0]);
    917703    } else {
    918       return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
    919     }
     704      $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
     705    }
     706
     707    return $formatted;
    920708  }
    921709
     
    924712   * automatically perform wrapping and for quoted-printable.
    925713   * Original written by philippe.
    926    * @param string $message The message to wrap
    927    * @param integer $length The line length to wrap to
    928    * @param boolean $qp_mode Whether to run in Quoted-Printable mode
    929    * @access public
    930    * @return string
    931    */
    932   public function WrapText($message, $length, $qp_mode = false) {
     714   * @access private
     715   * @return string
     716   */
     717  function WrapText($message, $length, $qp_mode = false) {
    933718    $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
    934719    // If utf-8 encoding is used, we will need to make sure we don't
     
    1007792   * quoted (printable) encoded string.
    1008793   * Original written by Colin Brown.
    1009    * @access public
     794   * @access private
    1010795   * @param string $encodedText utf-8 QP text
    1011796   * @param int    $maxLength   find last character boundary prior to this length
    1012797   * @return int
    1013798   */
    1014   public function UTF8CharBoundary($encodedText, $maxLength) {
     799  function UTF8CharBoundary($encodedText, $maxLength) {
    1015800    $foundSplitPos = false;
    1016801    $lookBack = 3;
     
    1044829  }
    1045830
    1046 
    1047831  /**
    1048832   * Set the body wrapping.
    1049    * @access public
    1050    * @return void
    1051    */
    1052   public function SetWordWrap() {
     833   * @access private
     834   * @return void
     835   */
     836  function SetWordWrap() {
    1053837    if($this->WordWrap < 1) {
    1054838      return;
     
    1057841    switch($this->message_type) {
    1058842      case 'alt':
     843        /* fall through */
    1059844      case 'alt_attachments':
    1060845        $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
     
    1068853  /**
    1069854   * Assembles message header.
    1070    * @access public
    1071    * @return string The assembled header
    1072    */
    1073   public function CreateHeader() {
     855   * @access private
     856   * @return string
     857   */
     858  function CreateHeader() {
    1074859    $result = '';
    1075860
    1076     // Set the boundaries
     861    /* Set the boundaries */
    1077862    $uniq_id = md5(uniqid(time()));
    1078863    $this->boundary[1] = 'b1_' . $uniq_id;
    1079864    $this->boundary[2] = 'b2_' . $uniq_id;
    1080865
    1081     $result .= $this->HeaderLine('Date', self::RFCDate());
     866    $result .= $this->HeaderLine('Date', $this->RFCDate());
    1082867    if($this->Sender == '') {
    1083868      $result .= $this->HeaderLine('Return-Path', trim($this->From));
     
    1086871    }
    1087872
    1088     // To be created automatically by mail()
     873    /* To be created automatically by mail() */
    1089874    if($this->Mailer != 'mail') {
    1090       if ($this->SingleTo === true) {
    1091         foreach($this->to as $t) {
    1092           $this->SingleToArray[] = $this->AddrFormat($t);
    1093         }
    1094       } else {
    1095         if(count($this->to) > 0) {
    1096           $result .= $this->AddrAppend('To', $this->to);
    1097         } elseif (count($this->cc) == 0) {
    1098           $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
    1099         }
     875      if(count($this->to) > 0) {
     876        $result .= $this->AddrAppend('To', $this->to);
     877      } elseif (count($this->cc) == 0) {
     878        $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
    1100879      }
    1101880    }
     
    1106885    $result .= $this->AddrAppend('From', $from);
    1107886
    1108     // sendmail and mail() extract Cc from the header before sending
    1109     if(count($this->cc) > 0) {
     887    /* sendmail and mail() extract Cc from the header before sending */
     888    if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
    1110889      $result .= $this->AddrAppend('Cc', $this->cc);
    1111890    }
    1112891
    1113     // sendmail and mail() extract Bcc from the header before sending
     892    /* sendmail and mail() extract Bcc from the header before sending */
    1114893    if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
    1115894      $result .= $this->AddrAppend('Bcc', $this->bcc);
     
    1117896
    1118897    if(count($this->ReplyTo) > 0) {
    1119       $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
    1120     }
    1121 
    1122     // mail() sets the subject itself
     898      $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
     899    }
     900
     901    /* mail() sets the subject itself */
    1123902    if($this->Mailer != 'mail') {
    1124903      $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
     
    1131910    }
    1132911    $result .= $this->HeaderLine('X-Priority', $this->Priority);
    1133     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
     912    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
    1134913
    1135914    if($this->ConfirmReadingTo != '') {
     
    1151930  /**
    1152931   * Returns the message MIME.
    1153    * @access public
    1154    * @return string
    1155    */
    1156   public function GetMailMIME() {
     932   * @access private
     933   * @return string
     934   */
     935  function GetMailMIME() {
    1157936    $result = '';
    1158937    switch($this->message_type) {
     
    1162941        break;
    1163942      case 'attachments':
     943        /* fall through */
    1164944      case 'alt_attachments':
    1165945        if($this->InlineImageExists()){
     
    1185965  /**
    1186966   * Assembles the message body.  Returns an empty string on failure.
    1187    * @access public
    1188    * @return string The assembled message body
    1189    */
    1190   public function CreateBody() {
    1191     $body = '';
    1192 
     967   * @access private
     968   * @return string
     969   */
     970  function CreateBody() {
     971    $result = '';
    1193972    if ($this->sign_key_file) {
    1194       $body .= $this->GetMailMIME();
     973      $result .= $this->GetMailMIME();
    1195974    }
    1196975
     
    1199978    switch($this->message_type) {
    1200979      case 'alt':
    1201         $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
    1202         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
    1203         $body .= $this->LE.$this->LE;
    1204         $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
    1205         $body .= $this->EncodeString($this->Body, $this->Encoding);
    1206         $body .= $this->LE.$this->LE;
    1207         $body .= $this->EndBoundary($this->boundary[1]);
     980        $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
     981        $result .= $this->EncodeString($this->AltBody, $this->Encoding);
     982        $result .= $this->LE.$this->LE;
     983        $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
     984        $result .= $this->EncodeString($this->Body, $this->Encoding);
     985        $result .= $this->LE.$this->LE;
     986        $result .= $this->EndBoundary($this->boundary[1]);
    1208987        break;
    1209988      case 'plain':
    1210         $body .= $this->EncodeString($this->Body, $this->Encoding);
     989        $result .= $this->EncodeString($this->Body, $this->Encoding);
    1211990        break;
    1212991      case 'attachments':
    1213         $body .= $this->GetBoundary($this->boundary[1], '', '', '');
    1214         $body .= $this->EncodeString($this->Body, $this->Encoding);
    1215         $body .= $this->LE;
    1216         $body .= $this->AttachAll();
     992        $result .= $this->GetBoundary($this->boundary[1], '', '', '');
     993        $result .= $this->EncodeString($this->Body, $this->Encoding);
     994        $result .= $this->LE;
     995        $result .= $this->AttachAll();
    1217996        break;
    1218997      case 'alt_attachments':
    1219         $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
    1220         $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
    1221         $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
    1222         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
    1223         $body .= $this->LE.$this->LE;
    1224         $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
    1225         $body .= $this->EncodeString($this->Body, $this->Encoding);
    1226         $body .= $this->LE.$this->LE;
    1227         $body .= $this->EndBoundary($this->boundary[2]);
    1228         $body .= $this->AttachAll();
    1229         break;
    1230     }
    1231 
    1232     if ($this->IsError()) {
    1233       $body = '';
    1234     } elseif ($this->sign_key_file) {
    1235       try {
    1236         $file = tempnam('', 'mail');
    1237         file_put_contents($file, $body); //TODO check this worked
    1238         $signed = tempnam("", "signed");
    1239         if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
    1240           @unlink($file);
    1241           @unlink($signed);
    1242           $body = file_get_contents($signed);
    1243         } else {
    1244           @unlink($file);
    1245           @unlink($signed);
    1246           throw new phpmailerException($this->Lang("signing").openssl_error_string());
     998        $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
     999        $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
     1000        $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
     1001        $result .= $this->EncodeString($this->AltBody, $this->Encoding);
     1002        $result .= $this->LE.$this->LE;
     1003        $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
     1004        $result .= $this->EncodeString($this->Body, $this->Encoding);
     1005        $result .= $this->LE.$this->LE;
     1006        $result .= $this->EndBoundary($this->boundary[2]);
     1007        $result .= $this->AttachAll();
     1008        break;
     1009    }
     1010
     1011    if($this->IsError()) {
     1012      $result = '';
     1013    } else if ($this->sign_key_file) {
     1014      $file = tempnam("", "mail");
     1015      $fp = fopen($file, "w");
     1016      fwrite($fp, $result);
     1017      fclose($fp);
     1018      $signed = tempnam("", "signed");
     1019
     1020      if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
     1021        $fp = fopen($signed, "r");
     1022        $result = fread($fp, filesize($this->sign_key_file));
     1023        $result = '';
     1024        while(!feof($fp)){
     1025          $result = $result . fread($fp, 1024);
    12471026        }
    1248       } catch (phpmailerException $e) {
    1249         $body = '';
    1250         if ($this->exceptions) {
    1251           throw $e;
    1252         }
    1253       }
    1254     }
    1255 
    1256     return $body;
     1027        fclose($fp);
     1028      } else {
     1029        $this->SetError($this->Lang("signing").openssl_error_string());
     1030        $result = '';
     1031      }
     1032
     1033      unlink($file);
     1034      unlink($signed);
     1035    }
     1036
     1037    return $result;
    12571038  }
    12581039
     
    12611042   * @access private
    12621043   */
    1263   private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
     1044  function GetBoundary($boundary, $charSet, $contentType, $encoding) {
    12641045    $result = '';
    12651046    if($charSet == '') {
     
    12851066   * @access private
    12861067   */
    1287   private function EndBoundary($boundary) {
     1068  function EndBoundary($boundary) {
    12881069    return $this->LE . '--' . $boundary . '--' . $this->LE;
    12891070  }
     
    12941075   * @return void
    12951076   */
    1296   private function SetMessageType() {
     1077  function SetMessageType() {
    12971078    if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
    12981079      $this->message_type = 'plain';
     
    13101091  }
    13111092
    1312   /**
    1313    *  Returns a formatted header line.
    1314    * @access public
    1315    * @return string
    1316    */
    1317   public function HeaderLine($name, $value) {
     1093  /* Returns a formatted header line.
     1094   * @access private
     1095   * @return string
     1096   */
     1097  function HeaderLine($name, $value) {
    13181098    return $name . ': ' . $value . $this->LE;
    13191099  }
     
    13211101  /**
    13221102   * Returns a formatted mail line.
    1323    * @access public
    1324    * @return string
    1325    */
    1326   public function TextLine($value) {
     1103   * @access private
     1104   * @return string
     1105   */
     1106  function TextLine($value) {
    13271107    return $value . $this->LE;
    13281108  }
     
    13421122   * @return bool
    13431123   */
    1344   public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    1345     try {
    1346       if ( !@is_file($path) ) {
    1347         throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
    1348       }
    1349       $filename = basename($path);
    1350       if ( $name == '' ) {
    1351         $name = $filename;
    1352       }
    1353 
    1354       $this->attachment[] = array(
    1355         0 => $path,
    1356         1 => $filename,
    1357         2 => $name,
    1358         3 => $encoding,
    1359         4 => $type,
    1360         5 => false,  // isStringAttachment
    1361         6 => 'attachment',
    1362         7 => 0
    1363       );
    1364 
    1365     } catch (phpmailerException $e) {
    1366       $this->SetError($e->getMessage());
    1367       if ($this->exceptions) {
    1368         throw $e;
    1369       }
    1370       echo $e->getMessage()."\n";
    1371       if ( $e->getCode() == self::STOP_CRITICAL ) {
    1372         return false;
    1373       }
    1374     }
     1124  function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
     1125    if(!@is_file($path)) {
     1126      $this->SetError($this->Lang('file_access') . $path);
     1127      return false;
     1128    }
     1129
     1130    $filename = basename($path);
     1131    if($name == '') {
     1132      $name = $filename;
     1133    }
     1134
     1135    $cur = count($this->attachment);
     1136    $this->attachment[$cur][0] = $path;
     1137    $this->attachment[$cur][1] = $filename;
     1138    $this->attachment[$cur][2] = $name;
     1139    $this->attachment[$cur][3] = $encoding;
     1140    $this->attachment[$cur][4] = $type;
     1141    $this->attachment[$cur][5] = false; // isStringAttachment
     1142    $this->attachment[$cur][6] = 'attachment';
     1143    $this->attachment[$cur][7] = 0;
     1144
    13751145    return true;
    1376   }
    1377 
    1378   /**
    1379   * Return the current array of attachments
    1380   * @return array
    1381   */
    1382   public function GetAttachments() {
    1383     return $this->attachment;
    13841146  }
    13851147
     
    13901152   * @return string
    13911153   */
    1392   private function AttachAll() {
    1393     // Return text of body
     1154  function AttachAll() {
     1155    /* Return text of body */
    13941156    $mime = array();
    1395     $cidUniq = array();
    1396     $incl = array();
    1397 
    1398     // Add all attachments
    1399     foreach ($this->attachment as $attachment) {
    1400       // Check for string attachment
    1401       $bString = $attachment[5];
     1157
     1158    /* Add all attachments */
     1159    for($i = 0; $i < count($this->attachment); $i++) {
     1160      /* Check for string attachment */
     1161      $bString = $this->attachment[$i][5];
    14021162      if ($bString) {
    1403         $string = $attachment[0];
     1163        $string = $this->attachment[$i][0];
    14041164      } else {
    1405         $path = $attachment[0];
    1406       }
    1407 
    1408       if (in_array($attachment[0], $incl)) { continue; }
    1409       $filename    = $attachment[1];
    1410       $name        = $attachment[2];
    1411       $encoding    = $attachment[3];
    1412       $type        = $attachment[4];
    1413       $disposition = $attachment[6];
    1414       $cid         = $attachment[7];
    1415       $incl[]      = $attachment[0];
    1416       if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
    1417       $cidUniq[$cid] = true;
     1165        $path = $this->attachment[$i][0];
     1166      }
     1167
     1168      $filename    = $this->attachment[$i][1];
     1169      $name        = $this->attachment[$i][2];
     1170      $encoding    = $this->attachment[$i][3];
     1171      $type        = $this->attachment[$i][4];
     1172      $disposition = $this->attachment[$i][6];
     1173      $cid         = $this->attachment[$i][7];
    14181174
    14191175      $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
     
    14271183      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
    14281184
    1429       // Encode as string attachment
     1185      /* Encode as string attachment */
    14301186      if($bString) {
    14311187        $mime[] = $this->EncodeString($string, $encoding);
     
    14491205
    14501206  /**
    1451    * Encodes attachment in requested format.
    1452    * Returns an empty string on failure.
    1453    * @param string $path The full path to the file
    1454    * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
    1455    * @see EncodeFile()
    1456    * @access private
    1457    * @return string
    1458    */
    1459   private function EncodeFile($path, $encoding = 'base64') {
    1460     try {
    1461       if (!is_readable($path)) {
    1462         throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
    1463       }
    1464       if (function_exists('get_magic_quotes')) {
    1465         function get_magic_quotes() {
    1466           return false;
    1467         }
    1468       }
    1469       if (PHP_VERSION < 6) {
    1470         $magic_quotes = get_magic_quotes_runtime();
    1471         set_magic_quotes_runtime(0);
    1472       }
    1473       $file_buffer  = file_get_contents($path);
    1474       $file_buffer  = $this->EncodeString($file_buffer, $encoding);
    1475       if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
    1476       return $file_buffer;
    1477     } catch (Exception $e) {
    1478       $this->SetError($e->getMessage());
     1207   * Encodes attachment in requested format.  Returns an
     1208   * empty string on failure.
     1209   * @access private
     1210   * @return string
     1211   */
     1212  function EncodeFile ($path, $encoding = 'base64') {
     1213    if(!@$fd = fopen($path, 'rb')) {
     1214      $this->SetError($this->Lang('file_open') . $path);
    14791215      return '';
    14801216    }
    1481   }
    1482 
    1483   /**
    1484    * Encodes string to requested format.
    1485    * Returns an empty string on failure.
    1486    * @param string $str The text to encode
    1487    * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
    1488    * @access public
    1489    * @return string
    1490    */
    1491   public function EncodeString ($str, $encoding = 'base64') {
     1217    $magic_quotes = get_magic_quotes_runtime();
     1218    set_magic_quotes_runtime(0);
     1219    $file_buffer = fread($fd, filesize($path));
     1220    $file_buffer = $this->EncodeString($file_buffer, $encoding);
     1221    fclose($fd);
     1222    set_magic_quotes_runtime($magic_quotes);
     1223
     1224    return $file_buffer;
     1225  }
     1226
     1227  /**
     1228   * Encodes string to requested format. Returns an
     1229   * empty string on failure.
     1230   * @access private
     1231   * @return string
     1232   */
     1233  function EncodeString ($str, $encoding = 'base64') {
    14921234    $encoded = '';
    14931235    switch(strtolower($encoding)) {
    14941236      case 'base64':
     1237        /* chunk_split is found in PHP >= 3.0.6 */
    14951238        $encoded = chunk_split(base64_encode($str), 76, $this->LE);
    14961239        break;
     
    14981241      case '8bit':
    14991242        $encoded = $this->FixEOL($str);
    1500         //Make sure it ends with a line break
    15011243        if (substr($encoded, -(strlen($this->LE))) != $this->LE)
    15021244          $encoded .= $this->LE;
     
    15161258
    15171259  /**
    1518    * Encode a header string to best (shortest) of Q, B, quoted or none.
    1519    * @access public
    1520    * @return string
    1521    */
    1522   public function EncodeHeader($str, $position = 'text') {
     1260   * Encode a header string to best of Q, B, quoted or none.
     1261   * @access private
     1262   * @return string
     1263   */
     1264  function EncodeHeader ($str, $position = 'text') {
    15231265    $x = 0;
    15241266
     
    15261268      case 'phrase':
    15271269        if (!preg_match('/[\200-\377]/', $str)) {
    1528           // Can't use addslashes as we don't know what value has magic_quotes_sybase
     1270          /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
    15291271          $encoded = addcslashes($str, "\0..\37\177\\\"");
    15301272          if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
     
    15381280      case 'comment':
    15391281        $x = preg_match_all('/[()"]/', $str, $matches);
    1540         // Fall-through
     1282        /* Fall-through */
    15411283      case 'text':
    15421284      default:
     
    15501292
    15511293    $maxlen = 75 - 7 - strlen($this->CharSet);
    1552     // Try to select the encoding which should produce the shortest output
     1294    /* Try to select the encoding which should produce the shortest output */
    15531295    if (strlen($str)/3 < $x) {
    15541296      $encoding = 'B';
    15551297      if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
    1556         // Use a custom function which correctly encodes and wraps long
    1557         // multibyte strings without breaking lines within a character
     1298     // Use a custom function which correctly encodes and wraps long
     1299     // multibyte strings without breaking lines within a character
    15581300        $encoded = $this->Base64EncodeWrapMB($str);
    15591301      } else {
     
    15771319  /**
    15781320   * Checks if a string contains multibyte characters.
    1579    * @access public
     1321   * @access private
    15801322   * @param string $str multi-byte text to wrap encode
    15811323   * @return bool
    15821324   */
    1583   public function HasMultiBytes($str) {
     1325  function HasMultiBytes($str) {
    15841326    if (function_exists('mb_strlen')) {
    15851327      return (strlen($str) > mb_strlen($str, $this->CharSet));
    15861328    } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
    1587       return false;
     1329      return False;
    15881330    }
    15891331  }
     
    15931335   * without breaking lines within a character.
    15941336   * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
    1595    * @access public
     1337   * @access private
    15961338   * @param string $str multi-byte text to wrap encode
    15971339   * @return string
    15981340   */
    1599   public function Base64EncodeWrapMB($str) {
     1341  function Base64EncodeWrapMB($str) {
    16001342    $start = "=?".$this->CharSet."?B?";
    16011343    $end = "?=";
     
    16301372
    16311373  /**
    1632   * Encode string to quoted-printable.
    1633   * Only uses standard PHP, slow, but will always work
    1634   * @access public
    1635   * @param string $string the text to encode
    1636   * @param integer $line_max Number of chars allowed on a line before wrapping
    1637   * @return string
    1638   */
    1639   public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
     1374   * Encode string to quoted-printable.
     1375   * @access private
     1376   * @return string
     1377   */
     1378  function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
    16401379    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
    16411380    $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
     
    16791418
    16801419  /**
    1681   * Encode string to RFC2045 (6.7) quoted-printable format
    1682   * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
    1683   * Also results in same content as you started with after decoding
    1684   * @see EncodeQPphp()
    1685   * @access public
    1686   * @param string $string the text to encode
    1687   * @param integer $line_max Number of chars allowed on a line before wrapping
    1688   * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
    1689   * @return string
    1690   * @author Marcus Bointon
    1691   */
    1692   public function EncodeQP($string, $line_max = 76, $space_conv = false) {
    1693     if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
    1694       return quoted_printable_encode($string);
    1695     }
    1696     $filters = stream_get_filters();
    1697     if (!in_array('convert.*', $filters)) { //Got convert stream filter?
    1698       return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
    1699     }
    1700     $fp = fopen('php://temp/', 'r+');
    1701     $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
    1702     $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
    1703     $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
    1704     fputs($fp, $string);
    1705     rewind($fp);
    1706     $out = stream_get_contents($fp);
    1707     stream_filter_remove($s);
    1708     $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
    1709     fclose($fp);
    1710     return $out;
     1420   * Callback for converting to "=XX".
     1421   * @access private
     1422   * @return string
     1423   */
     1424  function EncodeQ_callback ($matches) {
     1425    return sprintf('=%02X', ord($matches[1]));
    17111426  }
    17121427
    17131428  /**
    17141429   * Encode string to q encoding.
    1715    * @link http://tools.ietf.org/html/rfc2047
    1716    * @param string $str the text to encode
    1717    * @param string $position Where the text is going to be used, see the RFC for what that means
    1718    * @access public
    1719    * @return string
    1720    */
    1721   public function EncodeQ ($str, $position = 'text') {
    1722     // There should not be any EOL in the string
    1723     $encoded = preg_replace('/[\r\n]*/', '', $str);
     1430   * @access private
     1431   * @return string
     1432   */
     1433  function EncodeQ ($str, $position = 'text') {
     1434    /* There should not be any EOL in the string */
     1435    $encoded = preg_replace("/[\r\n]/", '', $str);
    17241436
    17251437    switch (strtolower($position)) {
    17261438      case 'phrase':
    1727         $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
     1439        $encoded = preg_replace_callback("/([^A-Za-z0-9!*+\/ -])/",
     1440                                         array('PHPMailer', 'EncodeQ_callback'), $encoded);
    17281441        break;
    17291442      case 'comment':
    1730         $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
     1443        $encoded = preg_replace_callback("/([\(\)\"])/",
     1444                                         array('PHPMailer', 'EncodeQ_callback'), $encoded);
     1445        break;
    17311446      case 'text':
    17321447      default:
    1733         // Replace every high ascii, control =, ? and _ characters
    1734         //TODO using /e (equivalent to eval()) is probably not a good idea
    1735         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
    1736               "'='.sprintf('%02X', ord('\\1'))", $encoded);
    1737         break;
    1738     }
    1739 
    1740     // Replace every spaces to _ (more readable than =20)
     1448        /* Replace every high ascii, control =, ? and _ characters */
     1449        $encoded = preg_replace_callback('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
     1450                                         array('PHPMailer', 'EncodeQ_callback'), $encoded);
     1451        break;
     1452    }
     1453
     1454    /* Replace every spaces to _ (more readable than =20) */
    17411455    $encoded = str_replace(' ', '_', $encoded);
    17421456
     
    17541468   * @return void
    17551469   */
    1756   public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
    1757     // Append to $attachment array
    1758     $this->attachment[] = array(
    1759       0 => $string,
    1760       1 => $filename,
    1761       2 => basename($filename),
    1762       3 => $encoding,
    1763       4 => $type,
    1764       5 => true,  // isStringAttachment
    1765       6 => 'attachment',
    1766       7 => 0
    1767     );
     1470  function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
     1471    /* Append to $attachment array */
     1472    $cur = count($this->attachment);
     1473    $this->attachment[$cur][0] = $string;
     1474    $this->attachment[$cur][1] = $filename;
     1475    $this->attachment[$cur][2] = $filename;
     1476    $this->attachment[$cur][3] = $encoding;
     1477    $this->attachment[$cur][4] = $type;
     1478    $this->attachment[$cur][5] = true; // isString
     1479    $this->attachment[$cur][6] = 'attachment';
     1480    $this->attachment[$cur][7] = 0;
    17681481  }
    17691482
     
    17811494   * @return bool
    17821495   */
    1783   public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    1784 
    1785     if ( !@is_file($path) ) {
     1496  function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
     1497
     1498    if(!@is_file($path)) {
    17861499      $this->SetError($this->Lang('file_access') . $path);
    17871500      return false;
     
    17891502
    17901503    $filename = basename($path);
    1791     if ( $name == '' ) {
     1504    if($name == '') {
    17921505      $name = $filename;
    17931506    }
    17941507
    1795     // Append to $attachment array
    1796     $this->attachment[] = array(
    1797       0 => $path,
    1798       1 => $filename,
    1799       2 => $name,
    1800       3 => $encoding,
    1801       4 => $type,
    1802       5 => false,  // isStringAttachment
    1803       6 => 'inline',
    1804       7 => $cid
    1805     );
     1508    /* Append to $attachment array */
     1509    $cur = count($this->attachment);
     1510    $this->attachment[$cur][0] = $path;
     1511    $this->attachment[$cur][1] = $filename;
     1512    $this->attachment[$cur][2] = $name;
     1513    $this->attachment[$cur][3] = $encoding;
     1514    $this->attachment[$cur][4] = $type;
     1515    $this->attachment[$cur][5] = false;
     1516    $this->attachment[$cur][6] = 'inline';
     1517    $this->attachment[$cur][7] = $cid;
    18061518
    18071519    return true;
     
    18101522  /**
    18111523   * Returns true if an inline attachment is present.
    1812    * @access public
     1524   * @access private
    18131525   * @return bool
    18141526   */
    1815   public function InlineImageExists() {
    1816     foreach($this->attachment as $attachment) {
    1817       if ($attachment[6] == 'inline') {
    1818         return true;
    1819       }
    1820     }
    1821     return false;
     1527  function InlineImageExists() {
     1528    $result = false;
     1529    for($i = 0; $i < count($this->attachment); $i++) {
     1530      if($this->attachment[$i][6] == 'inline') {
     1531        $result = true;
     1532        break;
     1533      }
     1534    }
     1535
     1536    return $result;
    18221537  }
    18231538
     
    18301545   * @return void
    18311546   */
    1832   public function ClearAddresses() {
    1833     foreach($this->to as $to) {
    1834       unset($this->all_recipients[strtolower($to[0])]);
    1835     }
     1547  function ClearAddresses() {
    18361548    $this->to = array();
    18371549  }
     
    18411553   * @return void
    18421554   */
    1843   public function ClearCCs() {
    1844     foreach($this->cc as $cc) {
    1845       unset($this->all_recipients[strtolower($cc[0])]);
    1846     }
     1555  function ClearCCs() {
    18471556    $this->cc = array();
    18481557  }
     
    18521561   * @return void
    18531562   */
    1854   public function ClearBCCs() {
    1855     foreach($this->bcc as $bcc) {
    1856       unset($this->all_recipients[strtolower($bcc[0])]);
    1857     }
     1563  function ClearBCCs() {
    18581564    $this->bcc = array();
    18591565  }
     
    18631569   * @return void
    18641570   */
    1865   public function ClearReplyTos() {
     1571  function ClearReplyTos() {
    18661572    $this->ReplyTo = array();
    18671573  }
     
    18721578   * @return void
    18731579   */
    1874   public function ClearAllRecipients() {
     1580  function ClearAllRecipients() {
    18751581    $this->to = array();
    18761582    $this->cc = array();
    18771583    $this->bcc = array();
    1878     $this->all_recipients = array();
    18791584  }
    18801585
     
    18841589   * @return void
    18851590   */
    1886   public function ClearAttachments() {
     1591  function ClearAttachments() {
    18871592    $this->attachment = array();
    18881593  }
     
    18921597   * @return void
    18931598   */
    1894   public function ClearCustomHeaders() {
     1599  function ClearCustomHeaders() {
    18951600    $this->CustomHeader = array();
    18961601  }
     
    19021607  /**
    19031608   * Adds the error message to the error container.
    1904    * @access protected
    1905    * @return void
    1906    */
    1907   protected function SetError($msg) {
     1609   * Returns void.
     1610   * @access private
     1611   * @return void
     1612   */
     1613  function SetError($msg) {
    19081614    $this->error_count++;
    1909     if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
    1910       $lasterror = $this->smtp->getError();
    1911       if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
    1912         $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
    1913       }
    1914     }
    19151615    $this->ErrorInfo = $msg;
    19161616  }
     
    19181618  /**
    19191619   * Returns the proper RFC 822 formatted date.
    1920    * @access public
    1921    * @return string
    1922    * @static
    1923    */
    1924   public static function RFCDate() {
     1620   * @access private
     1621   * @return string
     1622   */
     1623  function RFCDate() {
    19251624    $tz = date('Z');
    19261625    $tzs = ($tz < 0) ? '-' : '+';
     
    19331632
    19341633  /**
     1634   * Returns the appropriate server variable.  Should work with both
     1635   * PHP 4.1.0+ as well as older versions.  Returns an empty string
     1636   * if nothing is found.
     1637   * @access private
     1638   * @return mixed
     1639   */
     1640  function ServerVar($varName) {
     1641    global $HTTP_SERVER_VARS;
     1642    global $HTTP_ENV_VARS;
     1643
     1644    if(!isset($_SERVER)) {
     1645      $_SERVER = $HTTP_SERVER_VARS;
     1646      if(!isset($_SERVER['REMOTE_ADDR'])) {
     1647        $_SERVER = $HTTP_ENV_VARS; // must be Apache
     1648      }
     1649    }
     1650
     1651    if(isset($_SERVER[$varName])) {
     1652      return $_SERVER[$varName];
     1653    } else {
     1654      return '';
     1655    }
     1656  }
     1657
     1658  /**
    19351659   * Returns the server hostname or 'localhost.localdomain' if unknown.
    19361660   * @access private
    19371661   * @return string
    19381662   */
    1939   private function ServerHostname() {
    1940     if (!empty($this->Hostname)) {
     1663  function ServerHostname() {
     1664    if ($this->Hostname != '') {
    19411665      $result = $this->Hostname;
    1942     } elseif (isset($_SERVER['SERVER_NAME'])) {
    1943       $result = $_SERVER['SERVER_NAME'];
     1666    } elseif ($this->ServerVar('SERVER_NAME') != '') {
     1667      $result = $this->ServerVar('SERVER_NAME');
    19441668    } else {
    19451669      $result = 'localhost.localdomain';
     
    19541678   * @return string
    19551679   */
    1956   private function Lang($key) {
     1680  function Lang($key) {
    19571681    if(count($this->language) < 1) {
    19581682      $this->SetLanguage('en'); // set the default language
     
    19681692  /**
    19691693   * Returns true if an error occurred.
    1970    * @access public
    19711694   * @return bool
    19721695   */
    1973   public function IsError() {
     1696  function IsError() {
    19741697    return ($this->error_count > 0);
    19751698  }
     
    19801703   * @return string
    19811704   */
    1982   private function FixEOL($str) {
     1705  function FixEOL($str) {
    19831706    $str = str_replace("\r\n", "\n", $str);
    19841707    $str = str_replace("\r", "\n", $str);
     
    19891712  /**
    19901713   * Adds a custom header.
    1991    * @access public
    1992    * @return void
    1993    */
    1994   public function AddCustomHeader($custom_header) {
     1714   * @return void
     1715   */
     1716  function AddCustomHeader($custom_header) {
    19951717    $this->CustomHeader[] = explode(':', $custom_header, 2);
    19961718  }
     
    20011723   * @return $message
    20021724   */
    2003   public function MsgHTML($message, $basedir = '') {
     1725  function MsgHTML($message,$basedir='') {
    20041726    preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
    20051727    if(isset($images[2])) {
    20061728      foreach($images[2] as $i => $url) {
    20071729        // do not change urls for absolute images (thanks to corvuscorax)
    2008         if (!preg_match('#^[A-z]+://#',$url)) {
     1730        if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
    20091731          $filename = basename($url);
    20101732          $directory = dirname($url);
    20111733          ($directory == '.')?$directory='':'';
    20121734          $cid = 'cid:' . md5($filename);
    2013           $ext = pathinfo($filename, PATHINFO_EXTENSION);
    2014           $mimeType  = self::_mime_types($ext);
     1735          $fileParts = split("\.", $filename);
     1736          $ext = $fileParts[1];
     1737          $mimeType = $this->_mime_types($ext);
    20151738          if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
    20161739          if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
     
    20241747    $this->Body = $message;
    20251748    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
    2026     if (!empty($textMsg) && empty($this->AltBody)) {
     1749    if ( !empty($textMsg) && empty($this->AltBody) ) {
    20271750      $this->AltBody = html_entity_decode($textMsg);
    20281751    }
    2029     if (empty($this->AltBody)) {
    2030       $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
    2031     }
    2032   }
    2033 
    2034   /**
    2035    * Gets the MIME type of the embedded or inline image
    2036    * @param string File extension
    2037    * @access public
    2038    * @return string MIME type of ext
    2039    * @static
    2040    */
    2041   public static function _mime_types($ext = '') {
     1752    if ( empty($this->AltBody) ) {
     1753      $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
     1754    }
     1755  }
     1756
     1757  /**
     1758   * Gets the mime type of the embedded or inline image
     1759   * @access private
     1760   * @return mime type of ext
     1761   */
     1762  function _mime_types($ext = '') {
    20421763    $mimes = array(
     1764      'ai'    =>  'application/postscript',
     1765      'aif'   =>  'audio/x-aiff',
     1766      'aifc'  =>  'audio/x-aiff',
     1767      'aiff'  =>  'audio/x-aiff',
     1768      'avi'   =>  'video/x-msvideo',
     1769      'bin'   =>  'application/macbinary',
     1770      'bmp'   =>  'image/bmp',
     1771      'class' =>  'application/octet-stream',
     1772      'cpt'   =>  'application/mac-compactpro',
     1773      'css'   =>  'text/css',
     1774      'dcr'   =>  'application/x-director',
     1775      'dir'   =>  'application/x-director',
     1776      'dll'   =>  'application/octet-stream',
     1777      'dms'   =>  'application/octet-stream',
     1778      'doc'   =>  'application/msword',
     1779      'dvi'   =>  'application/x-dvi',
     1780      'dxr'   =>  'application/x-director',
     1781      'eml'   =>  'message/rfc822',
     1782      'eps'   =>  'application/postscript',
     1783      'exe'   =>  'application/octet-stream',
     1784      'gif'   =>  'image/gif',
     1785      'gtar'  =>  'application/x-gtar',
     1786      'htm'   =>  'text/html',
     1787      'html'  =>  'text/html',
     1788      'jpe'   =>  'image/jpeg',
     1789      'jpeg'  =>  'image/jpeg',
     1790      'jpg'   =>  'image/jpeg',
    20431791      'hqx'   =>  'application/mac-binhex40',
    2044       'cpt'   =>  'application/mac-compactpro',
    2045       'doc'   =>  'application/msword',
    2046       'bin'   =>  'application/macbinary',
    2047       'dms'   =>  'application/octet-stream',
     1792      'js'    =>  'application/x-javascript',
    20481793      'lha'   =>  'application/octet-stream',
     1794      'log'   =>  'text/plain',
    20491795      'lzh'   =>  'application/octet-stream',
    2050       'exe'   =>  'application/octet-stream',
    2051       'class' =>  'application/octet-stream',
    2052       'psd'   =>  'application/octet-stream',
    2053       'so'    =>  'application/octet-stream',
    2054       'sea'   =>  'application/octet-stream',
    2055       'dll'   =>  'application/octet-stream',
     1796      'mid'   =>  'audio/midi',
     1797      'midi'  =>  'audio/midi',
     1798      'mif'   =>  'application/vnd.mif',
     1799      'mov'   =>  'video/quicktime',
     1800      'movie' =>  'video/x-sgi-movie',
     1801      'mp2'   =>  'audio/mpeg',
     1802      'mp3'   =>  'audio/mpeg',
     1803      'mpe'   =>  'video/mpeg',
     1804      'mpeg'  =>  'video/mpeg',
     1805      'mpg'   =>  'video/mpeg',
     1806      'mpga'  =>  'audio/mpeg',
    20561807      'oda'   =>  'application/oda',
    20571808      'pdf'   =>  'application/pdf',
    2058       'ai'    =>  'application/postscript',
    2059       'eps'   =>  'application/postscript',
     1809      'php'   =>  'application/x-httpd-php',
     1810      'php3'  =>  'application/x-httpd-php',
     1811      'php4'  =>  'application/x-httpd-php',
     1812      'phps'  =>  'application/x-httpd-php-source',
     1813      'phtml' =>  'application/x-httpd-php',
     1814      'png'   =>  'image/png',
     1815      'ppt'   =>  'application/vnd.ms-powerpoint',
    20601816      'ps'    =>  'application/postscript',
    2061       'smi'   =>  'application/smil',
    2062       'smil'  =>  'application/smil',
    2063       'mif'   =>  'application/vnd.mif',
    2064       'xls'   =>  'application/vnd.ms-excel',
    2065       'ppt'   =>  'application/vnd.ms-powerpoint',
    2066       'wbxml' =>  'application/vnd.wap.wbxml',
    2067       'wmlc'  =>  'application/vnd.wap.wmlc',
    2068       'dcr'   =>  'application/x-director',
    2069       'dir'   =>  'application/x-director',
    2070       'dxr'   =>  'application/x-director',
    2071       'dvi'   =>  'application/x-dvi',
    2072       'gtar'  =>  'application/x-gtar',
    2073       'php'   =>  'application/x-httpd-php',
    2074       'php4'  =>  'application/x-httpd-php',
    2075       'php3'  =>  'application/x-httpd-php',
    2076       'phtml' =>  'application/x-httpd-php',
    2077       'phps'  =>  'application/x-httpd-php-source',
    2078       'js'    =>  'application/x-javascript',
    2079       'swf'   =>  'application/x-shockwave-flash',
    2080       'sit'   =>  'application/x-stuffit',
    2081       'tar'   =>  'application/x-tar',
    2082       'tgz'   =>  'application/x-tar',
    2083       'xhtml' =>  'application/xhtml+xml',
    2084       'xht'   =>  'application/xhtml+xml',
    2085       'zip'   =>  'application/zip',
    2086       'mid'   =>  'audio/midi',
    2087       'midi'  =>  'audio/midi',
    2088       'mpga'  =>  'audio/mpeg',
    2089       'mp2'   =>  'audio/mpeg',
    2090       'mp3'   =>  'audio/mpeg',
    2091       'aif'   =>  'audio/x-aiff',
    2092       'aiff'  =>  'audio/x-aiff',
    2093       'aifc'  =>  'audio/x-aiff',
     1817      'psd'   =>  'application/octet-stream',
     1818      'qt'    =>  'video/quicktime',
     1819      'ra'    =>  'audio/x-realaudio',
    20941820      'ram'   =>  'audio/x-pn-realaudio',
    20951821      'rm'    =>  'audio/x-pn-realaudio',
    20961822      'rpm'   =>  'audio/x-pn-realaudio-plugin',
    2097       'ra'    =>  'audio/x-realaudio',
     1823      'rtf'   =>  'text/rtf',
     1824      'rtx'   =>  'text/richtext',
    20981825      'rv'    =>  'video/vnd.rn-realvideo',
     1826      'sea'   =>  'application/octet-stream',
     1827      'shtml' =>  'text/html',
     1828      'sit'   =>  'application/x-stuffit',
     1829      'so'    =>  'application/octet-stream',
     1830      'smi'   =>  'application/smil',
     1831      'smil'  =>  'application/smil',
     1832      'swf'   =>  'application/x-shockwave-flash',
     1833      'tar'   =>  'application/x-tar',
     1834      'text'  =>  'text/plain',
     1835      'txt'   =>  'text/plain',
     1836      'tgz'   =>  'application/x-tar',
     1837      'tif'   =>  'image/tiff',
     1838      'tiff'  =>  'image/tiff',
    20991839      'wav'   =>  'audio/x-wav',
    2100       'bmp'   =>  'image/bmp',
    2101       'gif'   =>  'image/gif',
    2102       'jpeg'  =>  'image/jpeg',
    2103       'jpg'   =>  'image/jpeg',
    2104       'jpe'   =>  'image/jpeg',
    2105       'png'   =>  'image/png',
    2106       'tiff'  =>  'image/tiff',
    2107       'tif'   =>  'image/tiff',
    2108       'css'   =>  'text/css',
    2109       'html'  =>  'text/html',
    2110       'htm'   =>  'text/html',
    2111       'shtml' =>  'text/html',
    2112       'txt'   =>  'text/plain',
    2113       'text'  =>  'text/plain',
    2114       'log'   =>  'text/plain',
    2115       'rtx'   =>  'text/richtext',
    2116       'rtf'   =>  'text/rtf',
     1840      'wbxml' =>  'application/vnd.wap.wbxml',
     1841      'wmlc'  =>  'application/vnd.wap.wmlc',
     1842      'word'  =>  'application/msword',
     1843      'xht'   =>  'application/xhtml+xml',
     1844      'xhtml' =>  'application/xhtml+xml',
     1845      'xl'    =>  'application/excel',
     1846      'xls'   =>  'application/vnd.ms-excel',
    21171847      'xml'   =>  'text/xml',
    21181848      'xsl'   =>  'text/xml',
    2119       'mpeg'  =>  'video/mpeg',
    2120       'mpg'   =>  'video/mpeg',
    2121       'mpe'   =>  'video/mpeg',
    2122       'qt'    =>  'video/quicktime',
    2123       'mov'   =>  'video/quicktime',
    2124       'avi'   =>  'video/x-msvideo',
    2125       'movie' =>  'video/x-sgi-movie',
    2126       'doc'   =>  'application/msword',
    2127       'word'  =>  'application/msword',
    2128       'xl'    =>  'application/excel',
    2129       'eml'   =>  'message/rfc822'
     1849      'zip'   =>  'application/zip'
    21301850    );
    2131     return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
    2132   }
    2133 
    2134   /**
    2135   * Set (or reset) Class Objects (variables)
    2136   *
    2137   * Usage Example:
    2138   * $page->set('X-Priority', '3');
    2139   *
    2140   * @access public
    2141   * @param string $name Parameter Name
    2142   * @param mixed $value Parameter Value
    2143   * NOTE: will not work with arrays, there are no arrays to set/reset
    2144   * @todo Should this not be using __set() magic function?
    2145   */
    2146   public function set($name, $value = '') {
    2147     try {
    2148       if (isset($this->$name) ) {
    2149         $this->$name = $value;
    2150       } else {
    2151         throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
    2152       }
    2153     } catch (Exception $e) {
    2154       $this->SetError($e->getMessage());
    2155       if ($e->getCode() == self::STOP_CRITICAL) {
    2156         return false;
    2157       }
    2158     }
    2159     return true;
     1851    return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
     1852  }
     1853
     1854  /**
     1855   * Set (or reset) Class Objects (variables)
     1856   *
     1857   * Usage Example:
     1858   * $page->set('X-Priority', '3');
     1859   *
     1860   * @access public
     1861   * @param string $name Parameter Name
     1862   * @param mixed $value Parameter Value
     1863   * NOTE: will not work with arrays, there are no arrays to set/reset
     1864   */
     1865  function set ( $name, $value = '' ) {
     1866    if ( isset($this->$name) ) {
     1867      $this->$name = $value;
     1868    } else {
     1869      $this->SetError('Cannot set or reset variable ' . $name);
     1870      return false;
     1871    }
     1872  }
     1873
     1874  /**
     1875   * Read a file from a supplied filename and return it.
     1876   *
     1877   * @access public
     1878   * @param string $filename Parameter File Name
     1879   */
     1880  function getFile($filename) {
     1881    $return = '';
     1882    if ($fp = fopen($filename, 'rb')) {
     1883      while (!feof($fp)) {
     1884        $return .= fread($fp, 1024);
     1885      }
     1886      fclose($fp);
     1887      return $return;
     1888    } else {
     1889      return false;
     1890    }
    21601891  }
    21611892
    21621893  /**
    21631894   * Strips newlines to prevent header injection.
    2164    * @access public
     1895   * @access private
    21651896   * @param string $str String
    21661897   * @return string
    21671898   */
    2168   public function SecureHeader($str) {
    2169     $str = str_replace("\r", '', $str);
    2170     $str = str_replace("\n", '', $str);
    2171     return trim($str);
     1899  function SecureHeader($str) {
     1900    $str = trim($str);
     1901    $str = str_replace("\r", "", $str);
     1902    $str = str_replace("\n", "", $str);
     1903    return $str;
    21721904  }
    21731905
     
    21791911   * @param string $key_pass Password for private key
    21801912   */
    2181   public function Sign($cert_filename, $key_filename, $key_pass) {
     1913  function Sign($cert_filename, $key_filename, $key_pass) {
    21821914    $this->sign_cert_file = $cert_filename;
    21831915    $this->sign_key_file = $key_filename;
     
    21851917  }
    21861918
    2187   /**
    2188    * Set the private key file and password to sign the message.
    2189    *
    2190    * @access public
    2191    * @param string $key_filename Parameter File Name
    2192    * @param string $key_pass Password for private key
    2193    */
    2194   public function DKIM_QP($txt) {
    2195     $tmp="";
    2196     $line="";
    2197     for ($i=0;$i<strlen($txt);$i++) {
    2198       $ord=ord($txt[$i]);
    2199       if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
    2200         $line.=$txt[$i];
    2201       } else {
    2202         $line.="=".sprintf("%02X",$ord);
    2203       }
    2204     }
    2205     return $line;
    2206   }
    2207 
    2208   /**
    2209    * Generate DKIM signature
    2210    *
    2211    * @access public
    2212    * @param string $s Header
    2213    */
    2214   public function DKIM_Sign($s) {
    2215     $privKeyStr = file_get_contents($this->DKIM_private);
    2216     if ($this->DKIM_passphrase!='') {
    2217       $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
    2218     } else {
    2219       $privKey = $privKeyStr;
    2220     }
    2221     if (openssl_sign($s, $signature, $privKey)) {
    2222       return base64_encode($signature);
    2223     }
    2224   }
    2225 
    2226   /**
    2227    * Generate DKIM Canonicalization Header
    2228    *
    2229    * @access public
    2230    * @param string $s Header
    2231    */
    2232   public function DKIM_HeaderC($s) {
    2233     $s=preg_replace("/\r\n\s+/"," ",$s);
    2234     $lines=explode("\r\n",$s);
    2235     foreach ($lines as $key=>$line) {
    2236       list($heading,$value)=explode(":",$line,2);
    2237       $heading=strtolower($heading);
    2238       $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
    2239       $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
    2240     }
    2241     $s=implode("\r\n",$lines);
    2242     return $s;
    2243   }
    2244 
    2245   /**
    2246    * Generate DKIM Canonicalization Body
    2247    *
    2248    * @access public
    2249    * @param string $body Message Body
    2250    */
    2251   public function DKIM_BodyC($body) {
    2252     if ($body == '') return "\r\n";
    2253     // stabilize line endings
    2254     $body=str_replace("\r\n","\n",$body);
    2255     $body=str_replace("\n","\r\n",$body);
    2256     // END stabilize line endings
    2257     while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
    2258       $body=substr($body,0,strlen($body)-2);
    2259     }
    2260     return $body;
    2261   }
    2262 
    2263   /**
    2264    * Create the DKIM header, body, as new header
    2265    *
    2266    * @access public
    2267    * @param string $headers_line Header lines
    2268    * @param string $subject Subject
    2269    * @param string $body Body
    2270    */
    2271   public function DKIM_Add($headers_line,$subject,$body) {
    2272     $DKIMsignatureType    = 'rsa-sha1'; // Signature & hash algorithms
    2273     $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
    2274     $DKIMquery            = 'dns/txt'; // Query method
    2275     $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
    2276     $subject_header       = "Subject: $subject";
    2277     $headers              = explode("\r\n",$headers_line);
    2278     foreach($headers as $header) {
    2279       if (strpos($header,'From:') === 0) {
    2280         $from_header=$header;
    2281       } elseif (strpos($header,'To:') === 0) {
    2282         $to_header=$header;
    2283       }
    2284     }
    2285     $from     = str_replace('|','=7C',$this->DKIM_QP($from_header));
    2286     $to       = str_replace('|','=7C',$this->DKIM_QP($to_header));
    2287     $subject  = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
    2288     $body     = $this->DKIM_BodyC($body);
    2289     $DKIMlen  = strlen($body) ; // Length of body
    2290     $DKIMb64  = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
    2291     $ident    = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";";
    2292     $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n".
    2293                 "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n".
    2294                 "\th=From:To:Subject;\r\n".
    2295                 "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n".
    2296                 "\tz=$from\r\n".
    2297                 "\t|$to\r\n".
    2298                 "\t|$subject;\r\n".
    2299                 "\tbh=" . $DKIMb64 . ";\r\n".
    2300                 "\tb=";
    2301     $toSign   = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
    2302     $signed   = $this->DKIM_Sign($toSign);
    2303     return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
    2304   }
    2305 
    2306   protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
    2307     if (!empty($this->action_function) && function_exists($this->action_function)) {
    2308       $params = array($isSent,$to,$cc,$bcc,$subject,$body);
    2309       call_user_func_array($this->action_function,$params);
    2310     }
    2311   }
    23121919}
    23131920
    2314 class phpmailerException extends Exception {
    2315   public function errorMessage() {
    2316     $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
    2317     return $errorMsg;
    2318   }
    2319 }
    23201921?>
Note: See TracChangeset for help on using the changeset viewer.