]> git.mxchange.org Git - mailer.git/blobdiff - inc/phpmailer/class.phpmailer.php
Added script template for cron jobs, fixed some checks on CSS/HTML mode
[mailer.git] / inc / phpmailer / class.phpmailer.php
index 6939fc2c8a3320ec239cabec75936aa0b6491c46..effe75ed44b102d330cb6d930204a75e77f7dabe 100644 (file)
@@ -2,7 +2,7 @@
 /*~ class.phpmailer.php
 .---------------------------------------------------------------------------.
 |  Software: PHPMailer - PHP email class                                    |
-|   Version: 2.0.3                                                          |
+|   Version: 2.0.4                                                          |
 |   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
 |      Info: http://phpmailer.sourceforge.net                               |
 |   Support: http://sourceforge.net/projects/phpmailer/                     |
@@ -28,7 +28,7 @@
  * PHPMailer - PHP email transport class
  * @package PHPMailer
  * @author Andy Prevost
- * @copyright 2004 - 2008 Andy Prevost
+ * @copyright 2004 - 2009 Andy Prevost
  */
 
 class PHPMailer {
@@ -95,7 +95,7 @@ class PHPMailer {
 
   /**
    * Sets the Body of the message.  This can be either an HTML or text body.
-   * If HTML then run IsHTML(true).
+   * If HTML then run IsHTML(TRUE).
    * @var string
    */
   var $Body              = '';
@@ -114,7 +114,7 @@ class PHPMailer {
    * characters.
    * @var int
    */
-  var $WordWrap          = '0';
+  var $WordWrap          = 0;
 
   /**
    * Method to send mail: ("mail", "sendmail", or "smtp").
@@ -139,7 +139,7 @@ class PHPMailer {
    * Holds PHPMailer version.
    * @var string
    */
-  var $Version           = "2.0.3";
+  var $Version           = "2.0.4";
 
   /**
    * Sets the email address that a reading confirmation will be sent.
@@ -156,7 +156,7 @@ class PHPMailer {
   var $Hostname          = '';
 
   /**
-   * Sets the message id to be used in the Message-Id header.
+   * Sets the message ID to be used in the Message-Id header.
    * If empty, a unique id will be generated.
    * @var string
    */
@@ -199,7 +199,7 @@ class PHPMailer {
    * Sets SMTP authentication. Utilizes the Username and Password variables.
    * @var bool
    */
-  var $SMTPAuth     = false;
+  var $SMTPAuth     = FALSE;
 
   /**
    * Sets SMTP username.
@@ -224,7 +224,7 @@ class PHPMailer {
    * Sets SMTP class debugging on or off.
    * @var bool
    */
-  var $SMTPDebug    = false;
+  var $SMTPDebug    = FALSE;
 
   /**
    * Prevents the SMTP connection from being closed after each mail
@@ -232,14 +232,14 @@ class PHPMailer {
    * requires an explicit call to SmtpClose().
    * @var bool
    */
-  var $SMTPKeepAlive = false;
+  var $SMTPKeepAlive = FALSE;
 
   /**
    * Provides the ability to have the TO field process individual
    * emails, instead of sending to entire TO addresses
    * @var bool
    */
-  var $SingleTo = false;
+  var $SingleTo = FALSE;
 
   /////////////////////////////////////////////////
   // PROPERTIES, PRIVATE
@@ -255,8 +255,8 @@ class PHPMailer {
   var $message_type    = '';
   var $boundary        = array();
   var $language        = array();
-  var $error_count     = '0';
-  var $LE              = "\r\n";
+  var $error_count     = 0;
+  var $LE              = "\n";
   var $sign_cert_file  = "";
   var $sign_key_file   = "";
   var $sign_key_pass   = "";
@@ -271,7 +271,7 @@ class PHPMailer {
    * @return void
    */
   function IsHTML($bool) {
-    if($bool == true) {
+    if($bool == TRUE) {
       $this->ContentType = 'text/html';
     } else {
       $this->ContentType = 'text/plain';
@@ -380,11 +380,11 @@ class PHPMailer {
   function Send() {
     $header = '';
     $body = '';
-    $result = true;
+    $result = TRUE;
 
     if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
       $this->SetError($this->Lang('provide_address'));
-      return false;
+      return FALSE;
     }
 
     /* Set whether the message is multipart/alternative */
@@ -392,13 +392,13 @@ class PHPMailer {
       $this->ContentType = 'multipart/alternative';
     }
 
-    $this->error_count = '0'; // reset errors
+    $this->error_count = 0; // reset errors
     $this->SetMessageType();
     $header .= $this->CreateHeader();
     $body = $this->CreateBody();
 
     if($body == '') {
-      return false;
+      return FALSE;
     }
 
     /* Choose the mailer */
@@ -416,7 +416,7 @@ class PHPMailer {
         $result = $this->MailSend($header, $body);
         break;
         //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
-        //$result = false;
+        //$result = FALSE;
         //break;
     }
 
@@ -437,7 +437,7 @@ class PHPMailer {
 
     if(!@$mail = popen($sendmail, 'w')) {
       $this->SetError($this->Lang('execute') . $this->Sendmail);
-      return false;
+      return FALSE;
     }
 
     fputs($mail, $header);
@@ -449,9 +449,9 @@ class PHPMailer {
     }
     if($result != 0) {
       $this->SetError($this->Lang('execute') . $this->Sendmail);
-      return false;
+      return FALSE;
     }
-    return true;
+    return TRUE;
   }
 
   /**
@@ -462,7 +462,7 @@ class PHPMailer {
   function MailSend($header, $body) {
 
     $to = '';
-    for($i = '0'; $i < count($this->to); $i++) {
+    for($i = 0; $i < count($this->to); $i++) {
       if($i != 0) { $to .= ', '; }
       $to .= $this->AddrFormat($this->to[$i]);
     }
@@ -473,7 +473,7 @@ class PHPMailer {
     if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
       $old_from = ini_get('sendmail_from');
       ini_set('sendmail_from', $this->Sender);
-      if ($this->SingleTo === true && count($toArr) > 1) {
+      if ($this->SingleTo === TRUE && count($toArr) > 1) {
         foreach ($toArr as $key => $val) {
           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
         }
@@ -481,7 +481,7 @@ class PHPMailer {
         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
       }
     } else {
-      if ($this->SingleTo === true && count($toArr) > 1) {
+      if ($this->SingleTo === TRUE && count($toArr) > 1) {
         foreach ($toArr as $key => $val) {
           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
         }
@@ -496,10 +496,10 @@ class PHPMailer {
 
     if(!$rt) {
       $this->SetError($this->Lang('instantiate'));
-      return false;
+      return FALSE;
     }
 
-    return true;
+    return TRUE;
   }
 
   /**
@@ -515,7 +515,7 @@ class PHPMailer {
     $bad_rcpt = array();
 
     if(!$this->SmtpConnect()) {
-      return false;
+      return FALSE;
     }
 
     $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
@@ -523,28 +523,28 @@ class PHPMailer {
       $error = $this->Lang('from_failed') . $smtp_from;
       $this->SetError($error);
       $this->smtp->Reset();
-      return false;
+      return FALSE;
     }
 
     /* Attempt to send attach all recipients */
-    for($i = '0'; $i < count($this->to); $i++) {
+    for($i = 0; $i < count($this->to); $i++) {
       if(!$this->smtp->Recipient($this->to[$i][0])) {
         $bad_rcpt[] = $this->to[$i][0];
       }
     }
-    for($i = '0'; $i < count($this->cc); $i++) {
+    for($i = 0; $i < count($this->cc); $i++) {
       if(!$this->smtp->Recipient($this->cc[$i][0])) {
         $bad_rcpt[] = $this->cc[$i][0];
       }
     }
-    for($i = '0'; $i < count($this->bcc); $i++) {
+    for($i = 0; $i < count($this->bcc); $i++) {
       if(!$this->smtp->Recipient($this->bcc[$i][0])) {
         $bad_rcpt[] = $this->bcc[$i][0];
       }
     }
 
     if(count($bad_rcpt) > 0) { // Create error message
-      for($i = '0'; $i < count($bad_rcpt); $i++) {
+      for($i = 0; $i < count($bad_rcpt); $i++) {
         if($i != 0) {
           $error .= ', ';
         }
@@ -553,21 +553,21 @@ class PHPMailer {
       $error = $this->Lang('recipients_failed') . $error;
       $this->SetError($error);
       $this->smtp->Reset();
-      return false;
+      return FALSE;
     }
 
     if(!$this->smtp->Data($header . $body)) {
       $this->SetError($this->Lang('data_not_accepted'));
       $this->smtp->Reset();
-      return false;
+      return FALSE;
     }
-    if($this->SMTPKeepAlive == true) {
+    if($this->SMTPKeepAlive == TRUE) {
       $this->smtp->Reset();
     } else {
       $this->SmtpClose();
     }
 
-    return true;
+    return TRUE;
   }
 
   /**
@@ -583,11 +583,11 @@ class PHPMailer {
 
     $this->smtp->do_debug = $this->SMTPDebug;
     $hosts = explode(';', $this->Host);
-    $index = '0';
+    $index = 0;
     $connection = ($this->smtp->Connected());
 
     /* Retry while there is no connection */
-    while($index < count($hosts) && $connection == false) {
+    while($index < count($hosts) && $connection == FALSE) {
       $hostinfo = array();
       if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
         $host = $hostinfo[1];
@@ -604,12 +604,12 @@ class PHPMailer {
           $this->smtp->Hello($this->ServerHostname());
         }
 
-        $connection = true;
+        $connection = TRUE;
         if($this->SMTPAuth) {
           if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
             $this->SetError($this->Lang('authenticate'));
             $this->smtp->Reset();
-            $connection = false;
+            $connection = FALSE;
           }
         }
       }
@@ -667,7 +667,7 @@ class PHPMailer {
     }
     $this->language = $PHPMAILER_LANG;
 
-    return true;
+    return TRUE;
   }
 
   /////////////////////////////////////////////////
@@ -714,7 +714,7 @@ class PHPMailer {
    * @access private
    * @return string
    */
-  function WrapText($message, $length, $qp_mode = false) {
+  function WrapText($message, $length, $qp_mode = FALSE) {
     $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
     // If utf-8 encoding is used, we will need to make sure we don't
     // split multibyte characters when we wrap
@@ -730,7 +730,7 @@ class PHPMailer {
     for ($i=0 ;$i < count($line); $i++) {
       $line_part = explode(' ', $line[$i]);
       $buf = '';
-      for ($e = '0'; $e<count($line_part); $e++) {
+      for ($e = 0; $e<count($line_part); $e++) {
         $word = $line_part[$e];
         if ($qp_mode and (strlen($word) > $length)) {
           $space_left = $length - strlen($buf) - 1;
@@ -773,7 +773,7 @@ class PHPMailer {
           }
         } else {
           $buf_o = $buf;
-          $buf .= ($e == '0') ? $word : (' ' . $word);
+          $buf .= ($e == 0) ? $word : (' ' . $word);
 
           if (strlen($buf) > $length and $buf_o != '') {
             $message .= $buf_o . $soft_break;
@@ -797,12 +797,12 @@ class PHPMailer {
    * @return int
    */
   function UTF8CharBoundary($encodedText, $maxLength) {
-    $foundSplitPos = false;
+    $foundSplitPos = FALSE;
     $lookBack = 3;
     while (!$foundSplitPos) {
       $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
       $encodedCharPos = strpos($lastChunk, "=");
-      if ($encodedCharPos !== false) {
+      if ($encodedCharPos !== FALSE) {
         // Found start of encoded character byte within $lookBack block.
         // Check the encoded byte value (the 2 chars after the '=')
         $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
@@ -810,19 +810,19 @@ class PHPMailer {
         if ($dec < 128) { // Single byte character.
           // If the encoded char was found at pos 0, it will fit
           // otherwise reduce maxLength to start of the encoded char
-          $maxLength = ($encodedCharPos == '0') ? $maxLength :
+          $maxLength = ($encodedCharPos == 0) ? $maxLength :
           $maxLength - ($lookBack - $encodedCharPos);
-          $foundSplitPos = true;
+          $foundSplitPos = TRUE;
         } elseif ($dec >= 192) { // First byte of a multi byte character
           // Reduce maxLength to split at start of character
           $maxLength = $maxLength - ($lookBack - $encodedCharPos);
-          $foundSplitPos = true;
+          $foundSplitPos = TRUE;
         } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
           $lookBack += 3;
         }
       } else {
         // No encoded character found
-        $foundSplitPos = true;
+        $foundSplitPos = TRUE;
       }
     }
     return $maxLength;
@@ -874,7 +874,7 @@ class PHPMailer {
     if($this->Mailer != 'mail') {
       if(count($this->to) > 0) {
         $result .= $this->AddrAppend('To', $this->to);
-      } elseif (count($this->cc) == '0') {
+      } elseif (count($this->cc) == 0) {
         $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
       }
     }
@@ -904,9 +904,9 @@ class PHPMailer {
     }
 
     if($this->MessageID != '') {
-      $result .= $this->HeaderLine('Message-Id',$this->MessageID);
+      $result .= $this->HeaderLine('Message-ID',$this->MessageID);
     } else {
-      $result .= sprintf("Message-Id: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
+      $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
     }
     $result .= $this->HeaderLine('X-Priority', $this->Priority);
     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
@@ -916,7 +916,7 @@ class PHPMailer {
     }
 
     // Add custom headers
-    for($index = '0'; $index < count($this->CustomHeader); $index++) {
+    for($index = 0; $index < count($this->CustomHeader); $index++) {
       $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
     }
     if (!$this->sign_key_file) {
@@ -1124,7 +1124,7 @@ class PHPMailer {
   function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
     if(!@is_file($path)) {
       $this->SetError($this->Lang('file_access') . $path);
-      return false;
+      return FALSE;
     }
 
     $filename = basename($path);
@@ -1138,11 +1138,11 @@ class PHPMailer {
     $this->attachment[$cur][2] = $name;
     $this->attachment[$cur][3] = $encoding;
     $this->attachment[$cur][4] = $type;
-    $this->attachment[$cur][5] = false; // isStringAttachment
+    $this->attachment[$cur][5] = FALSE; // isStringAttachment
     $this->attachment[$cur][6] = 'attachment';
-    $this->attachment[$cur][7] = '0';
+    $this->attachment[$cur][7] = 0;
 
-    return true;
+    return TRUE;
   }
 
   /**
@@ -1156,7 +1156,7 @@ class PHPMailer {
     $mime = array();
 
     /* Add all attachments */
-    for($i = '0'; $i < count($this->attachment); $i++) {
+    for($i = 0; $i < count($this->attachment); $i++) {
       /* Check for string attachment */
       $bString = $this->attachment[$i][5];
       if ($bString) {
@@ -1177,7 +1177,7 @@ class PHPMailer {
       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
 
       if($disposition == 'inline') {
-        $mime[] = sprintf("Content-Id: <%s>%s", $cid, $this->LE);
+        $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
       }
 
       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
@@ -1262,7 +1262,7 @@ class PHPMailer {
    * @return string
    */
   function EncodeHeader ($str, $position = 'text') {
-    $x = '0';
+    $x = 0;
 
     switch (strtolower($position)) {
       case 'phrase':
@@ -1286,7 +1286,7 @@ class PHPMailer {
         break;
     }
 
-    if ($x == '0') {
+    if ($x == 0) {
       return ($str);
     }
 
@@ -1306,7 +1306,7 @@ class PHPMailer {
     } else {
       $encoding = 'Q';
       $encoded = $this->EncodeQ($str, $position);
-      $encoded = $this->WrapText($encoded, $maxlen, true);
+      $encoded = $this->WrapText($encoded, $maxlen, TRUE);
       $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
     }
 
@@ -1351,8 +1351,8 @@ class PHPMailer {
     // Base64 has a 4:3 ratio
     $offset = $avgLength = floor($length * $ratio * .75);
 
-    for ($i = '0'; $i < $mb_length; $i += $offset) {
-      $lookBack = '0';
+    for ($i = 0; $i < $mb_length; $i += $offset) {
+      $lookBack = 0;
 
       do {
         $offset = $avgLength - $lookBack;
@@ -1375,7 +1375,7 @@ class PHPMailer {
    * @access private
    * @return string
    */
-  function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
+  function EncodeQP( $input = '', $line_max = 76, $space_conv = FALSE ) {
     $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
     $eol = "\r\n";
@@ -1384,10 +1384,10 @@ class PHPMailer {
     while( list(, $line) = each($lines) ) {
       $linlen = strlen($line);
       $newline = '';
-      for($i = '0'; $i < $linlen; $i++) {
+      for($i = 0; $i < $linlen; $i++) {
         $c = substr( $line, $i, 1 );
         $dec = ord( $c );
-        if ( ( $i == '0' ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
+        if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
           $c = '=2E';
         }
         if ( $dec == 32 ) {
@@ -1463,9 +1463,9 @@ class PHPMailer {
     $this->attachment[$cur][2] = $filename;
     $this->attachment[$cur][3] = $encoding;
     $this->attachment[$cur][4] = $type;
-    $this->attachment[$cur][5] = true; // isString
+    $this->attachment[$cur][5] = TRUE; // isString
     $this->attachment[$cur][6] = 'attachment';
-    $this->attachment[$cur][7] = '0';
+    $this->attachment[$cur][7] = 0;
   }
 
   /**
@@ -1474,7 +1474,7 @@ class PHPMailer {
    * image type.  For JPEG images use "image/jpeg" and for GIF images
    * use "image/gif".
    * @param string $path Path to the attachment.
-   * @param string $cid Content id of the attachment.  Use this to identify
+   * @param string $cid Content ID of the attachment.  Use this to identify
    *        the Id for accessing the image in an HTML form.
    * @param string $name Overrides the attachment name.
    * @param string $encoding File encoding (see $Encoding).
@@ -1485,7 +1485,7 @@ class PHPMailer {
 
     if(!@is_file($path)) {
       $this->SetError($this->Lang('file_access') . $path);
-      return false;
+      return FALSE;
     }
 
     $filename = basename($path);
@@ -1500,11 +1500,11 @@ class PHPMailer {
     $this->attachment[$cur][2] = $name;
     $this->attachment[$cur][3] = $encoding;
     $this->attachment[$cur][4] = $type;
-    $this->attachment[$cur][5] = false;
+    $this->attachment[$cur][5] = FALSE;
     $this->attachment[$cur][6] = 'inline';
     $this->attachment[$cur][7] = $cid;
 
-    return true;
+    return TRUE;
   }
 
   /**
@@ -1513,10 +1513,10 @@ class PHPMailer {
    * @return bool
    */
   function InlineImageExists() {
-    $result = false;
-    for($i = '0'; $i < count($this->attachment); $i++) {
+    $result = FALSE;
+    for($i = 0; $i < count($this->attachment); $i++) {
       if($this->attachment[$i][6] == 'inline') {
-        $result = true;
+        $result = TRUE;
         break;
       }
     }
@@ -1731,7 +1731,7 @@ class PHPMailer {
         }
       }
     }
-    $this->IsHTML(true);
+    $this->IsHTML(TRUE);
     $this->Body = $message;
     $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
     if ( !empty($textMsg) && empty($this->AltBody) ) {
@@ -1855,7 +1855,7 @@ class PHPMailer {
       $this->$name = $value;
     } else {
       $this->SetError('Cannot set or reset variable ' . $name);
-      return false;
+      return FALSE;
     }
   }
 
@@ -1874,7 +1874,7 @@ class PHPMailer {
       fclose($fp);
       return $return;
     } else {
-      return false;
+      return FALSE;
     }
   }