Changeset 23522 for trunk/wp-includes/class-phpmailer.php
- Timestamp:
- 02/28/2013 06:33:13 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-phpmailer.php
r21128 r23522 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.2. 1|5 | Version: 5.2.4 | 6 6 | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | 7 7 | ------------------------------------------------------------------------- | … … 24 24 25 25 /** 26 * PHPMailer - PHP email transport class26 * PHPMailer - PHP email creation and transport class 27 27 * NOTE: Requires PHP version 5 or later 28 28 * @package PHPMailer … … 32 32 * @copyright 2010 - 2012 Jim Jagielski 33 33 * @copyright 2004 - 2009 Andy Prevost 34 * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $35 34 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 36 35 */ … … 38 37 if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); 39 38 39 /** 40 * PHP email creation and transport class 41 * @package PHPMailer 42 */ 40 43 class PHPMailer { 41 44 … … 93 96 */ 94 97 public $Sender = ''; 98 99 /** 100 * Sets the Return-Path of the message. If empty, it will 101 * be set to either From or Sender. 102 * @var string 103 */ 104 public $ReturnPath = ''; 95 105 96 106 /** … … 131 141 132 142 /** 133 * Stores the complete sent MIME message (Body and Headers)143 * Stores the extra header list which CreateHeader() doesn't fold in 134 144 * @var string 135 145 * @access protected 136 146 */ 137 protected $ SentMIMEMessage= '';147 protected $mailHeader = ''; 138 148 139 149 /** … … 157 167 158 168 /** 169 * Determine if mail() uses a fully sendmail compatible MTA that 170 * supports sendmail's "-oi -f" options 171 * @var boolean 172 */ 173 public $UseSendmailOptions = true; 174 175 /** 159 176 * Path to PHPMailer plugins. Useful if the SMTP class 160 177 * is in a different directory than the PHP include path. … … 184 201 public $MessageID = ''; 185 202 203 /** 204 * Sets the message Date to be used in the Date header. 205 * If empty, the current date will be added. 206 * @var string 207 */ 208 public $MessageDate = ''; 209 186 210 ///////////////////////////////////////////////// 187 211 // PROPERTIES FOR SMTP … … 189 213 190 214 /** 191 * Sets the SMTP hosts. All hosts must be separated by a 215 * Sets the SMTP hosts. 216 * 217 * All hosts must be separated by a 192 218 * semicolon. You can also specify a different port 193 219 * for each host by using this format: [hostname:port] … … 211 237 212 238 /** 213 * Sets connection prefix. 214 * Options are "", "ssl" or "tls" 239 * Sets connection prefix. Options are "", "ssl" or "tls" 215 240 * @var string 216 241 */ … … 234 259 */ 235 260 public $Password = ''; 261 262 /** 263 * Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM (default LOGIN) 264 * @var string 265 */ 266 public $AuthType = ''; 267 268 /** 269 * Sets SMTP realm. 270 * @var string 271 */ 272 public $Realm = ''; 273 274 /** 275 * Sets SMTP workstation. 276 * @var string 277 */ 278 public $Workstation = ''; 236 279 237 280 /** … … 247 290 */ 248 291 public $SMTPDebug = false; 292 293 /** 294 * Sets the function/method to use for debugging output. 295 * Right now we only honor "echo" or "error_log" 296 * @var string 297 */ 298 public $Debugoutput = "echo"; 249 299 250 300 /** … … 270 320 271 321 /** 272 * Provides the ability to change the line ending 322 * Provides the ability to change the generic line ending 323 * NOTE: The default remains '\n'. We force CRLF where we KNOW 324 * it must be used via self::CRLF 273 325 * @var string 274 326 */ 275 327 public $LE = "\n"; 276 328 277 /** 278 * Used with DKIM DNS Resource Record 279 * @var string 280 */ 281 public $DKIM_selector = 'phpmailer'; 282 283 /** 284 * Used with DKIM DNS Resource Record 285 * optional, in format of email address 'you@yourdomain.com' 329 /** 330 * Used with DKIM Signing 331 * required parameter if DKIM is enabled 332 * 333 * domain selector example domainkey 334 * @var string 335 */ 336 public $DKIM_selector = ''; 337 338 /** 339 * Used with DKIM Signing 340 * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email 286 341 * @var string 287 342 */ … … 289 344 290 345 /** 291 * Used with DKIM DNS Resource Record 346 * Used with DKIM Signing 347 * optional parameter if your private key requires a passphras 292 348 * @var string 293 349 */ … … 295 351 296 352 /** 297 * Used with DKIM DNS Resource Record298 * optional, in format of email address 'you@yourdomain.com'353 * Used with DKIM Singing 354 * required if DKIM is enabled, in format of email address 'domain.com' 299 355 * @var string 300 356 */ … … 302 358 303 359 /** 304 * Used with DKIM DNS Resource Record305 * optional, in format of email address 'you@yourdomain.com'360 * Used with DKIM Signing 361 * required if DKIM is enabled, path to private key file 306 362 * @var string 307 363 */ … … 309 365 310 366 /** 311 * Callback Action function name 312 * the function that handles the result of the send email action. Parameters: 367 * Callback Action function name. 368 * The function that handles the result of the send email action. 369 * It is called out by Send() for each email sent. 370 * 371 * Value can be: 372 * - 'function_name' for function names 373 * - 'Class::Method' for static method calls 374 * - array($object, 'Method') for calling methods on $object 375 * See http://php.net/is_callable manual page for more details. 376 * 377 * Parameters: 313 378 * bool $result result of the send action 314 379 * string $to email address of the recipient … … 317 382 * string $subject the subject 318 383 * string $body the email body 384 * string $from email address of sender 319 385 * @var string 320 386 */ … … 325 391 * @var string 326 392 */ 327 public $Version = '5.2. 1';393 public $Version = '5.2.4'; 328 394 329 395 /** 330 396 * What to use in the X-Mailer header 331 * @var string 397 * @var string NULL for default, whitespace for None, or actual string to use 332 398 */ 333 399 public $XMailer = ''; … … 337 403 ///////////////////////////////////////////////// 338 404 339 protected $smtp = NULL; 405 /** 406 * @var SMTP An instance of the SMTP sender class 407 * @access protected 408 */ 409 protected $smtp = null; 410 /** 411 * @var array An array of 'to' addresses 412 * @access protected 413 */ 340 414 protected $to = array(); 415 /** 416 * @var array An array of 'cc' addresses 417 * @access protected 418 */ 341 419 protected $cc = array(); 420 /** 421 * @var array An array of 'bcc' addresses 422 * @access protected 423 */ 342 424 protected $bcc = array(); 425 /** 426 * @var array An array of reply-to name and address 427 * @access protected 428 */ 343 429 protected $ReplyTo = array(); 430 /** 431 * @var array An array of all kinds of addresses: to, cc, bcc, replyto 432 * @access protected 433 */ 344 434 protected $all_recipients = array(); 435 /** 436 * @var array An array of attachments 437 * @access protected 438 */ 345 439 protected $attachment = array(); 440 /** 441 * @var array An array of custom headers 442 * @access protected 443 */ 346 444 protected $CustomHeader = array(); 445 /** 446 * @var string The message's MIME type 447 * @access protected 448 */ 347 449 protected $message_type = ''; 450 /** 451 * @var array An array of MIME boundary strings 452 * @access protected 453 */ 348 454 protected $boundary = array(); 455 /** 456 * @var array An array of available languages 457 * @access protected 458 */ 349 459 protected $language = array(); 460 /** 461 * @var integer The number of errors encountered 462 * @access protected 463 */ 350 464 protected $error_count = 0; 465 /** 466 * @var string The filename of a DKIM certificate file 467 * @access protected 468 */ 351 469 protected $sign_cert_file = ''; 470 /** 471 * @var string The filename of a DKIM key file 472 * @access protected 473 */ 352 474 protected $sign_key_file = ''; 475 /** 476 * @var string The password of a DKIM key 477 * @access protected 478 */ 353 479 protected $sign_key_pass = ''; 480 /** 481 * @var boolean Whether to throw exceptions for errors 482 * @access protected 483 */ 354 484 protected $exceptions = false; 355 485 … … 361 491 const STOP_CONTINUE = 1; // message?, likely ok to continue processing 362 492 const STOP_CRITICAL = 2; // message, plus full stop, critical error reached 363 493 const CRLF = "\r\n"; // SMTP RFC specified EOL 494 364 495 ///////////////////////////////////////////////// 365 496 // METHODS, VARIABLES 366 497 ///////////////////////////////////////////////// 498 499 /** 500 * Calls actual mail() function, but in a safe_mode aware fashion 501 * Also, unless sendmail_path points to sendmail (or something that 502 * claims to be sendmail), don't pass params (not a perfect fix, 503 * but it will do) 504 * @param string $to To 505 * @param string $subject Subject 506 * @param string $body Message Body 507 * @param string $header Additional Header(s) 508 * @param string $params Params 509 * @access private 510 * @return bool 511 */ 512 private function mail_passthru($to, $subject, $body, $header, $params) { 513 if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) { 514 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header); 515 } else { 516 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params); 517 } 518 return $rt; 519 } 520 521 /** 522 * Outputs debugging info via user-defined method 523 * @param string $str 524 */ 525 private function edebug($str) { 526 if ($this->Debugoutput == "error_log") { 527 error_log($str); 528 } else { 529 echo $str; 530 } 531 } 367 532 368 533 /** … … 477 642 * @param string $address The email address to send to 478 643 * @param string $name 644 * @throws phpmailerException 479 645 * @return boolean true on success, false if address already used or invalid in some way 480 646 * @access protected … … 486 652 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 653 } 488 489 echo $this->Lang('Invalid recipient array').': '.$kind;654 if ($this->SMTPDebug) { 655 $this->edebug($this->Lang('Invalid recipient array').': '.$kind); 490 656 } 491 657 return false; … … 493 659 $address = trim($address); 494 660 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 495 if (! self::ValidateAddress($address)) {661 if (!$this->ValidateAddress($address)) { 496 662 $this->SetError($this->Lang('invalid_address').': '. $address); 497 663 if ($this->exceptions) { 498 664 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 499 665 } 500 501 echo $this->Lang('invalid_address').': '.$address;666 if ($this->SMTPDebug) { 667 $this->edebug($this->Lang('invalid_address').': '.$address); 502 668 } 503 669 return false; … … 522 688 * @param string $address 523 689 * @param string $name 690 * @param int $auto Also set Reply-To and Sender 691 * @throws phpmailerException 524 692 * @return boolean 525 693 */ … … 527 695 $address = trim($address); 528 696 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 529 if (! self::ValidateAddress($address)) {697 if (!$this->ValidateAddress($address)) { 530 698 $this->SetError($this->Lang('invalid_address').': '. $address); 531 699 if ($this->exceptions) { 532 700 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 533 701 } 534 535 echo $this->Lang('invalid_address').': '.$address;702 if ($this->SMTPDebug) { 703 $this->edebug($this->Lang('invalid_address').': '.$address); 536 704 } 537 705 return false; … … 552 720 /** 553 721 * Check that a string looks roughly like an email address should 554 * Static so it can be used without instantiation 555 * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator 556 * Conforms approximately to RFC2822 557 * @link http://www.hexillion.com/samples/#Regex Original pattern found here 722 * Static so it can be used without instantiation, public so people can overload 723 * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is 724 * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to 725 * not allow a@b type valid addresses :( 726 * Some Versions of PHP break on the regex though, likely due to PCRE, so use 727 * the older validation method for those users. (http://php.net/manual/en/pcre.installation.php) 728 * @link http://squiloople.com/2009/12/20/email-address-validation/ 729 * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice. 558 730 * @param string $address The email address to check 559 731 * @return boolean … … 562 734 */ 563 735 public static function ValidateAddress($address) { 564 if (function_exists('filter_var')) { //Introduced in PHP 5.2 565 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { 566 return false; 567 } else { 568 return true; 569 } 736 if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) { 737 return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address); 738 } elseif (function_exists('filter_var')) { //Introduced in PHP 5.2 739 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { 740 return false; 741 } else { 742 return true; 743 } 570 744 } else { 571 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);572 745 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); 746 } 573 747 } 574 748 … … 581 755 * not sent successfully then it returns false. Use the ErrorInfo 582 756 * variable to view description of the error. 757 * @throws phpmailerException 583 758 * @return bool 584 759 */ … … 588 763 return $this->PostSend(); 589 764 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage= '';765 $this->mailHeader = ''; 591 766 $this->SetError($e->getMessage()); 592 767 if ($this->exceptions) { … … 597 772 } 598 773 599 protected function PreSend() { 774 /** 775 * Prep mail by constructing all message entities 776 * @throws phpmailerException 777 * @return bool 778 */ 779 public function PreSend() { 600 780 try { 601 $mailHeader = "";781 $this->mailHeader = ""; 602 782 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 603 783 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); … … 620 800 621 801 // To capture the complete message when using mail(), create 622 802 // an extra header list which CreateHeader() doesn't fold in 623 803 if ($this->Mailer == 'mail') { 624 804 if (count($this->to) > 0) { 625 $ mailHeader .= $this->AddrAppend("To", $this->to);805 $this->mailHeader .= $this->AddrAppend("To", $this->to); 626 806 } else { 627 $ mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");807 $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 808 } 629 $ mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));809 $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 810 // if(count($this->cc) > 0) { 631 // $ mailHeader .= $this->AddrAppend("Cc", $this->cc);811 // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 812 // } 633 813 } 634 814 635 815 // digitally sign with DKIM if enabled 636 if ( $this->DKIM_domain && $this->DKIM_private) {816 if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) { 637 817 $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody); 638 818 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 819 } 640 820 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);642 821 return true; 643 822 … … 651 830 } 652 831 653 protected function PostSend() { 832 /** 833 * Actual Email transport function 834 * Send the email via the selected mechanism 835 * @throws phpmailerException 836 * @return bool 837 */ 838 public function PostSend() { 654 839 try { 655 840 // Choose the mailer and send through it … … 664 849 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 665 850 } 666 667 851 } catch (phpmailerException $e) { 668 852 $this->SetError($e->getMessage()); … … 670 854 throw $e; 671 855 } 672 673 echo $e->getMessage()."\n";674 } 675 return false;676 }856 if ($this->SMTPDebug) { 857 $this->edebug($e->getMessage()."\n"); 858 } 859 } 860 return false; 677 861 } 678 862 … … 681 865 * @param string $header The message headers 682 866 * @param string $body The message body 867 * @throws phpmailerException 683 868 * @access protected 684 869 * @return bool … … 686 871 protected function SendmailSend($header, $body) { 687 872 if ($this->Sender != '') { 688 $sendmail = sprintf("%s -oi -f 873 $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); 689 874 } else { 690 875 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 691 876 } 692 877 if ($this->SingleTo === true) { 693 foreach ($this->SingleToArray as $ key => $val) {878 foreach ($this->SingleToArray as $val) { 694 879 if(!@$mail = popen($sendmail, 'w')) { 695 880 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); … … 727 912 * @param string $header The message headers 728 913 * @param string $body The message body 914 * @throws phpmailerException 729 915 * @access protected 730 916 * @return bool … … 740 926 $params = "-oi "; 741 927 } else { 742 $params = sprintf("-oi -f 928 $params = sprintf("-oi -f%s", $this->Sender); 743 929 } 744 930 if ($this->Sender != '' and !ini_get('safe_mode')) { 745 931 $old_from = ini_get('sendmail_from'); 746 932 ini_set('sendmail_from', $this->Sender); 747 if ($this->SingleTo === true && count($toArr) > 1) { 748 foreach ($toArr as $key => $val) { 749 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 750 // implement call back function if it exists 751 $isSent = ($rt == 1) ? 1 : 0; 752 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 753 } 754 } else { 755 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 933 } 934 $rt = false; 935 if ($this->SingleTo === true && count($toArr) > 1) { 936 foreach ($toArr as $val) { 937 $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params); 756 938 // implement call back function if it exists 757 939 $isSent = ($rt == 1) ? 1 : 0; 758 $this->doCallback($isSent, $ to, $this->cc, $this->bcc, $this->Subject, $body);940 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 759 941 } 760 942 } else { 761 if ($this->SingleTo === true && count($toArr) > 1) { 762 foreach ($toArr as $key => $val) { 763 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); 764 // implement call back function if it exists 765 $isSent = ($rt == 1) ? 1 : 0; 766 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 767 } 768 } else { 769 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); 770 // implement call back function if it exists 771 $isSent = ($rt == 1) ? 1 : 0; 772 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 773 } 943 $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params); 944 // implement call back function if it exists 945 $isSent = ($rt == 1) ? 1 : 0; 946 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 774 947 } 775 948 if (isset($old_from)) { … … 787 960 * @param string $header The message headers 788 961 * @param string $body The message body 962 * @throws phpmailerException 789 963 * @uses SMTP 790 964 * @access protected … … 800 974 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; 801 975 if(!$this->smtp->Mail($smtp_from)) { 802 throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); 976 $this->SetError($this->Lang('from_failed') . $smtp_from . " : " . implode(",",$this->smtp->getError())) ; 977 throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL); 803 978 } 804 979 … … 851 1026 if($this->SMTPKeepAlive == true) { 852 1027 $this->smtp->Reset(); 1028 } else { 1029 $this->smtp->Quit(); 1030 $this->smtp->Close(); 853 1031 } 854 1032 return true; … … 860 1038 * @uses SMTP 861 1039 * @access public 1040 * @throws phpmailerException 862 1041 * @return bool 863 1042 */ 864 1043 public function SmtpConnect() { 865 1044 if(is_null($this->smtp)) { 866 $this->smtp = new SMTP(); 867 } 868 1045 $this->smtp = new SMTP; 1046 } 1047 1048 $this->smtp->Timeout = $this->Timeout; 869 1049 $this->smtp->do_debug = $this->SMTPDebug; 870 1050 $hosts = explode(';', $this->Host); … … 894 1074 if ($tls) { 895 1075 if (!$this->smtp->StartTLS()) { 896 throw new phpmailerException($this->Lang(' tls'));1076 throw new phpmailerException($this->Lang('connect_host')); 897 1077 } 898 1078 … … 903 1083 $connection = true; 904 1084 if ($this->SMTPAuth) { 905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 1085 if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, 1086 $this->Realm, $this->Workstation)) { 906 1087 throw new phpmailerException($this->Lang('authenticate')); 907 1088 } … … 909 1090 } 910 1091 $index++; 911 912 913 1092 if (!$connection) { 1093 throw new phpmailerException($this->Lang('connect_host')); 1094 } 914 1095 } 915 1096 } catch (phpmailerException $e) { 916 1097 $this->smtp->Reset(); 917 1098 if ($this->exceptions) { 918 1099 throw $e; 919 1100 } … … 927 1108 */ 928 1109 public function SmtpClose() { 929 if (!is_null($this->smtp)) {1110 if ($this->smtp !== null) { 930 1111 if($this->smtp->Connected()) { 931 1112 $this->smtp->Quit(); … … 940 1121 * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") 941 1122 * @param string $lang_path Path to the language file directory 1123 * @return bool 942 1124 * @access public 943 1125 */ … … 945 1127 //Define full set of translatable strings 946 1128 $PHPMAILER_LANG = array( 947 'provide_address' => 'You must provide at least one recipient email address.', 1129 'authenticate' => 'SMTP Error: Could not authenticate.', 1130 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 1131 'data_not_accepted' => 'SMTP Error: Data not accepted.', 1132 'empty_message' => 'Message body empty', 1133 'encoding' => 'Unknown encoding: ', 1134 'execute' => 'Could not execute: ', 1135 'file_access' => 'Could not access file: ', 1136 'file_open' => 'File Error: Could not open file: ', 1137 'from_failed' => 'The following From address failed: ', 1138 'instantiate' => 'Could not instantiate mail function.', 1139 'invalid_address' => 'Invalid address', 948 1140 'mailer_not_supported' => ' mailer is not supported.', 949 'execute' => 'Could not execute: ', 950 'instantiate' => 'Could not instantiate mail function.', 951 'authenticate' => 'SMTP Error: Could not authenticate.', 952 'from_failed' => 'The following From address failed: ', 953 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 954 'data_not_accepted' => 'SMTP Error: Data not accepted.', 955 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 956 'file_access' => 'Could not access file: ', 957 'file_open' => 'File Error: Could not open file: ', 958 'encoding' => 'Unknown encoding: ', 959 'signing' => 'Signing Error: ', 960 'smtp_error' => 'SMTP server error: ', 961 'empty_message' => 'Message body empty', 962 'invalid_address' => 'Invalid address', 963 'variable_set' => 'Cannot set or reset variable: ' 1141 'provide_address' => 'You must provide at least one recipient email address.', 1142 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 1143 'signing' => 'Signing Error: ', 1144 'smtp_connect_failed' => 'SMTP Connect() failed.', 1145 'smtp_error' => 'SMTP server error: ', 1146 'variable_set' => 'Cannot set or reset variable: ' 964 1147 ); 965 1148 //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! … … 987 1170 * Creates recipient headers. 988 1171 * @access public 1172 * @param string $type 1173 * @param array $addr 989 1174 * @return string 990 1175 */ … … 1004 1189 * Formats an address correctly. 1005 1190 * @access public 1191 * @param string $addr 1006 1192 * @return string 1007 1193 */ … … 1029 1215 // split multibyte characters when we wrap 1030 1216 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 1217 $lelen = strlen($this->LE); 1218 $crlflen = strlen(self::CRLF); 1031 1219 1032 1220 $message = $this->FixEOL($message); 1033 if (substr($message, - 1) == $this->LE) {1034 $message = substr($message, 0, - 1);1035 } 1036 1037 $line = explode($this->LE, $message); 1221 if (substr($message, -$lelen) == $this->LE) { 1222 $message = substr($message, 0, -$lelen); 1223 } 1224 1225 $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE 1038 1226 $message = ''; 1039 1227 for ($i = 0 ;$i < count($line); $i++) { … … 1043 1231 $word = $line_part[$e]; 1044 1232 if ($qp_mode and (strlen($word) > $length)) { 1045 $space_left = $length - strlen($buf) - 1;1233 $space_left = $length - strlen($buf) - $crlflen; 1046 1234 if ($e != 0) { 1047 1235 if ($space_left > 20) { … … 1057 1245 $word = substr($word, $len); 1058 1246 $buf .= ' ' . $part; 1059 $message .= $buf . sprintf("=%s", $this->LE);1247 $message .= $buf . sprintf("=%s", self::CRLF); 1060 1248 } else { 1061 1249 $message .= $buf . $soft_break; … … 1076 1264 1077 1265 if (strlen($word) > 0) { 1078 $message .= $part . sprintf("=%s", $this->LE);1266 $message .= $part . sprintf("=%s", self::CRLF); 1079 1267 } else { 1080 1268 $buf = $part; … … 1091 1279 } 1092 1280 } 1093 $message .= $buf . $this->LE;1281 $message .= $buf . self::CRLF; 1094 1282 } 1095 1283 … … 1176 1364 $this->boundary[3] = 'b3_' . $uniq_id; 1177 1365 1178 $result .= $this->HeaderLine('Date', self::RFCDate()); 1179 if($this->Sender == '') { 1366 if ($this->MessageDate == '') { 1367 $result .= $this->HeaderLine('Date', self::RFCDate()); 1368 } else { 1369 $result .= $this->HeaderLine('Date', $this->MessageDate); 1370 } 1371 1372 if ($this->ReturnPath) { 1373 $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath)); 1374 } elseif ($this->Sender == '') { 1180 1375 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 1181 1376 } else { … … 1196 1391 } 1197 1392 } 1198 1393 } 1199 1394 1200 1395 $from = array(); … … 1228 1423 } 1229 1424 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1230 if ($this->XMailer) {1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer);1425 if ($this->XMailer == '') { 1426 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1232 1427 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1428 $myXmailer = trim($this->XMailer); 1429 if ($myXmailer) { 1430 $result .= $this->HeaderLine('X-Mailer', $myXmailer); 1431 } 1234 1432 } 1235 1433 … … 1258 1456 $result = ''; 1259 1457 switch($this->message_type) { 1260 case 'plain':1261 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);1262 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');1263 break;1264 1458 case 'inline': 1265 1459 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); … … 1278 1472 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1279 1473 break; 1474 default: 1475 // Catches case 'plain': and case '': 1476 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1477 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 1478 break; 1280 1479 } 1281 1480 1282 1481 if($this->Mailer != 'mail') { 1283 $result .= $this->LE .$this->LE;1482 $result .= $this->LE; 1284 1483 } 1285 1484 … … 1293 1492 */ 1294 1493 public function GetSentMIMEMessage() { 1295 return $this-> SentMIMEMessage;1494 return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody; 1296 1495 } 1297 1496 … … 1300 1499 * Assembles the message body. Returns an empty string on failure. 1301 1500 * @access public 1501 * @throws phpmailerException 1302 1502 * @return string The assembled message body 1303 1503 */ … … 1306 1506 1307 1507 if ($this->sign_key_file) { 1308 $body .= $this->GetMailMIME() ;1508 $body .= $this->GetMailMIME().$this->LE; 1309 1509 } 1310 1510 … … 1312 1512 1313 1513 switch($this->message_type) { 1314 case 'plain':1315 $body .= $this->EncodeString($this->Body, $this->Encoding);1316 break;1317 1514 case 'inline': 1318 1515 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); … … 1399 1596 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1400 1597 break; 1598 default: 1599 // catch case 'plain' and case '' 1600 $body .= $this->EncodeString($this->Body, $this->Encoding); 1601 break; 1401 1602 } 1402 1603 … … 1431 1632 * Returns the start of a message boundary. 1432 1633 * @access protected 1634 * @param string $boundary 1635 * @param string $charSet 1636 * @param string $contentType 1637 * @param string $encoding 1433 1638 * @return string 1434 1639 */ … … 1445 1650 } 1446 1651 $result .= $this->TextLine('--' . $boundary); 1447 $result .= sprintf("Content-Type: %s; charset= \"%s\"", $contentType, $charSet);1652 $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet); 1448 1653 $result .= $this->LE; 1449 1654 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); … … 1456 1661 * Returns the end of a message boundary. 1457 1662 * @access protected 1663 * @param string $boundary 1458 1664 * @return string 1459 1665 */ … … 1479 1685 * Returns a formatted header line. 1480 1686 * @access public 1687 * @param string $name 1688 * @param string $value 1481 1689 * @return string 1482 1690 */ … … 1488 1696 * Returns a formatted mail line. 1489 1697 * @access public 1698 * @param string $value 1490 1699 * @return string 1491 1700 */ … … 1506 1715 * @param string $encoding File encoding (see $Encoding). 1507 1716 * @param string $type File extension (MIME) type. 1717 * @throws phpmailerException 1508 1718 * @return bool 1509 1719 */ … … 1534 1744 throw $e; 1535 1745 } 1536 1537 echo $e->getMessage()."\n";1746 if ($this->SMTPDebug) { 1747 $this->edebug($e->getMessage()."\n"); 1538 1748 } 1539 1749 if ( $e->getCode() == self::STOP_CRITICAL ) { … … 1556 1766 * Returns an empty string on failure. 1557 1767 * @access protected 1768 * @param string $disposition_type 1769 * @param string $boundary 1558 1770 * @return string 1559 1771 */ … … 1569 1781 if($attachment[6] == $disposition_type) { 1570 1782 // Check for string attachment 1783 $string = ''; 1784 $path = ''; 1571 1785 $bString = $attachment[5]; 1572 1786 if ($bString) { … … 1625 1839 * @param string $path The full path to the file 1626 1840 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' 1841 * @throws phpmailerException 1627 1842 * @see EncodeFile() 1628 1843 * @access protected … … 1634 1849 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 1635 1850 } 1636 if (function_exists('get_magic_quotes')) {1637 function get_magic_quotes() {1638 return false;1639 }1640 }1641 1642 1851 // if (!function_exists('get_magic_quotes')) { 1852 // function get_magic_quotes() { 1853 // return false; 1854 // } 1855 // } 1856 $magic_quotes = get_magic_quotes_runtime(); 1857 if ($magic_quotes) { 1643 1858 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 1859 set_magic_quotes_runtime(0); 1645 1860 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 1648 1861 ini_set('magic_quotes_runtime', 0); 1862 } 1863 } 1649 1864 $file_buffer = file_get_contents($path); 1650 1865 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1651 1866 if ($magic_quotes) { 1652 1867 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 1868 set_magic_quotes_runtime($magic_quotes); 1654 1869 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 1657 1870 ini_set('magic_quotes_runtime', $magic_quotes); 1871 } 1872 } 1658 1873 return $file_buffer; 1659 1874 } catch (Exception $e) { … … 1700 1915 * Encode a header string to best (shortest) of Q, B, quoted or none. 1701 1916 * @access public 1917 * @param string $str 1918 * @param string $position 1702 1919 * @return string 1703 1920 */ … … 1738 1955 // Use a custom function which correctly encodes and wraps long 1739 1956 // multibyte strings without breaking lines within a character 1740 $encoded = $this->Base64EncodeWrapMB($str );1957 $encoded = $this->Base64EncodeWrapMB($str, "\n"); 1741 1958 } else { 1742 1959 $encoded = base64_encode($str); … … 1748 1965 $encoded = $this->EncodeQ($str, $position); 1749 1966 $encoded = $this->WrapText($encoded, $maxlen, true); 1750 $encoded = str_replace('='. $this->LE, "\n", trim($encoded));1967 $encoded = str_replace('='.self::CRLF, "\n", trim($encoded)); 1751 1968 } 1752 1969 … … 1777 1994 * @access public 1778 1995 * @param string $str multi-byte text to wrap encode 1996 * @param string $lf string to use as linefeed/end-of-line 1779 1997 * @return string 1780 1998 */ 1781 public function Base64EncodeWrapMB($str ) {1999 public function Base64EncodeWrapMB($str, $lf=null) { 1782 2000 $start = "=?".$this->CharSet."?B?"; 1783 2001 $end = "?="; 1784 2002 $encoded = ""; 2003 if ($lf === null) { 2004 $lf = $this->LE; 2005 } 1785 2006 1786 2007 $mb_length = mb_strlen($str, $this->CharSet); … … 1803 2024 while (strlen($chunk) > $length); 1804 2025 1805 $encoded .= $chunk . $ this->LE;2026 $encoded .= $chunk . $lf; 1806 2027 } 1807 2028 1808 2029 // Chomp the last linefeed 1809 $encoded = substr($encoded, 0, -strlen($ this->LE));2030 $encoded = substr($encoded, 0, -strlen($lf)); 1810 2031 return $encoded; 1811 2032 } … … 1815 2036 * Only uses standard PHP, slow, but will always work 1816 2037 * @access public 1817 * @param string $string the text to encode2038 * @param string $input 1818 2039 * @param integer $line_max Number of chars allowed on a line before wrapping 2040 * @param bool $space_conv 2041 * @internal param string $string the text to encode 1819 2042 * @return string 1820 2043 */ … … 1841 2064 } 1842 2065 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 1843 $h2 = floor($dec/16);1844 $h1 = floor($dec%16);2066 $h2 = (integer)floor($dec/16); 2067 $h1 = (integer)floor($dec%16); 1845 2068 $c = $escape.$hex[$h2].$hex[$h1]; 1846 2069 } … … 1902 2125 */ 1903 2126 public function EncodeQ($str, $position = 'text') { 1904 // 1905 $encoded = preg_replace('/[\r\n]*/', '', $str);1906 2127 //There should not be any EOL in the string 2128 $pattern=""; 2129 $encoded = str_replace(array("\r", "\n"), '', $str); 1907 2130 switch (strtolower($position)) { 1908 2131 case 'phrase': 1909 $ encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);2132 $pattern = '^A-Za-z0-9!*+\/ -'; 1910 2133 break; 2134 1911 2135 case 'comment': 1912 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 2136 $pattern = '\(\)"'; 2137 //note that we dont break here! 2138 //for this reason we build the $pattern withoud including delimiters and [] 2139 1913 2140 case 'text': 1914 2141 default: 1915 // Replace every high ascii, control =, ? and _ characters 1916 //TODO using /e (equivalent to eval()) is probably not a good idea 1917 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', 1918 "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded); 2142 //Replace every high ascii, control =, ? and _ characters 2143 //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode 2144 $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern; 1919 2145 break; 1920 2146 } 1921 1922 // Replace every spaces to _ (more readable than =20) 1923 $encoded = str_replace(' ', '_', $encoded); 1924 1925 return $encoded; 1926 } 2147 2148 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { 2149 foreach (array_unique($matches[0]) as $char) { 2150 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded); 2151 } 2152 } 2153 2154 //Replace every spaces to _ (more readable than =20) 2155 return str_replace(' ', '_', $encoded); 2156 } 2157 1927 2158 1928 2159 /** … … 1990 2221 } 1991 2222 1992 public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') { 2223 /** 2224 * Adds an embedded stringified attachment. This can include images, sounds, and 2225 * just about any other document. Make sure to set the $type to an 2226 * image type. For JPEG images use "image/jpeg" and for GIF images 2227 * use "image/gif". 2228 * @param string $string The attachment. 2229 * @param string $cid Content ID of the attachment. Use this to identify 2230 * the Id for accessing the image in an HTML form. 2231 * @param string $name Overrides the attachment name. 2232 * @param string $encoding File encoding (see $Encoding). 2233 * @param string $type File extension (MIME) type. 2234 * @return bool 2235 */ 2236 public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { 1993 2237 // Append to $attachment array 1994 2238 $this->attachment[] = array( 1995 2239 0 => $string, 1996 1 => $ filename,1997 2 => basename($filename),2240 1 => $name, 2241 2 => $name, 1998 2242 3 => $encoding, 1999 2243 4 => $type, … … 2018 2262 } 2019 2263 2264 /** 2265 * Returns true if an attachment (non-inline) is present. 2266 * @return bool 2267 */ 2020 2268 public function AttachmentExists() { 2021 2269 foreach($this->attachment as $attachment) { … … 2027 2275 } 2028 2276 2277 /** 2278 * Does this message have an alternative body set? 2279 * @return bool 2280 */ 2029 2281 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0;2282 return !empty($this->AltBody); 2031 2283 } 2032 2284 … … 2112 2364 * Adds the error message to the error container. 2113 2365 * @access protected 2366 * @param string $msg 2114 2367 * @return void 2115 2368 */ … … 2161 2414 * Returns a message in the appropriate language. 2162 2415 * @access protected 2416 * @param string $key 2163 2417 * @return string 2164 2418 */ … … 2185 2439 2186 2440 /** 2187 * Changes every end of line from CR or LF to CRLF. 2188 * @access public 2441 * Changes every end of line from CRLF, CR or LF to $this->LE. 2442 * @access public 2443 * @param string $str String to FixEOL 2189 2444 * @return string 2190 2445 */ 2191 2446 public function FixEOL($str) { 2192 $str = str_replace("\r\n", "\n", $str); 2193 $str = str_replace("\r", "\n", $str); 2194 $str = str_replace("\n", $this->LE, $str); 2195 return $str; 2196 } 2197 2198 /** 2199 * Adds a custom header. 2200 * @access public 2447 // condense down to \n 2448 $nstr = str_replace(array("\r\n", "\r"), "\n", $str); 2449 // Now convert LE as needed 2450 if ($this->LE !== "\n") { 2451 $nstr = str_replace("\n", $this->LE, $nstr); 2452 } 2453 return $nstr; 2454 } 2455 2456 /** 2457 * Adds a custom header. $name value can be overloaded to contain 2458 * both header name and value (name:value) 2459 * @access public 2460 * @param string $name custom header name 2461 * @param string $value header value 2201 2462 * @return void 2202 2463 */ 2203 public function AddCustomHeader($custom_header) { 2204 $this->CustomHeader[] = explode(':', $custom_header, 2); 2464 public function AddCustomHeader($name, $value=null) { 2465 if ($value === null) { 2466 // Value passed in as name:value 2467 $this->CustomHeader[] = explode(':', $name, 2); 2468 } else { 2469 $this->CustomHeader[] = array($name, $value); 2470 } 2205 2471 } 2206 2472 … … 2208 2474 * Evaluates the message and returns modifications for inline images and backgrounds 2209 2475 * @access public 2210 * @return $message 2476 * @param string $message Text to be HTML modified 2477 * @param string $basedir baseline directory for path 2478 * @return string $message 2211 2479 */ 2212 2480 public function MsgHTML($message, $basedir = '') { … … 2218 2486 $filename = basename($url); 2219 2487 $directory = dirname($url); 2220 ($directory == '.') ? $directory='': ''; 2221 $cid = 'cid:' . md5($filename); 2488 if ($directory == '.') { 2489 $directory = ''; 2490 } 2491 $cid = 'cid:' . md5($url); 2222 2492 $ext = pathinfo($filename, PATHINFO_EXTENSION); 2223 2493 $mimeType = self::_mime_types($ext); 2224 2494 if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } 2225 2495 if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } 2226 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($ filename), $filename, 'base64', $mimeType) ) {2496 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($url), $filename, 'base64', $mimeType) ) { 2227 2497 $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message); 2228 2498 } … … 2232 2502 $this->IsHTML(true); 2233 2503 $this->Body = $message; 2234 2235 2236 2237 2238 2239 2504 if (empty($this->AltBody)) { 2505 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2506 if (!empty($textMsg)) { 2507 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2508 } 2509 } 2240 2510 if (empty($this->AltBody)) { 2241 2511 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242 2512 } 2243 2513 return $message; 2244 2514 } 2245 2515 2246 2516 /** 2247 2517 * Gets the MIME type of the embedded or inline image 2248 * @param string File extension2518 * @param string $ext File extension 2249 2519 * @access public 2250 2520 * @return string MIME type of ext … … 2253 2523 public static function _mime_types($ext = '') { 2254 2524 $mimes = array( 2525 'xl' => 'application/excel', 2255 2526 'hqx' => 'application/mac-binhex40', 2256 2527 'cpt' => 'application/mac-compactpro', 2528 'bin' => 'application/macbinary', 2257 2529 'doc' => 'application/msword', 2258 'bin' => 'application/macbinary', 2530 'word' => 'application/msword', 2531 'class' => 'application/octet-stream', 2532 'dll' => 'application/octet-stream', 2259 2533 'dms' => 'application/octet-stream', 2534 'exe' => 'application/octet-stream', 2260 2535 'lha' => 'application/octet-stream', 2261 2536 'lzh' => 'application/octet-stream', 2262 'exe' => 'application/octet-stream',2263 'class' => 'application/octet-stream',2264 2537 'psd' => 'application/octet-stream', 2538 'sea' => 'application/octet-stream', 2265 2539 'so' => 'application/octet-stream', 2266 'sea' => 'application/octet-stream',2267 'dll' => 'application/octet-stream',2268 2540 'oda' => 'application/oda', 2269 2541 'pdf' => 'application/pdf', … … 2283 2555 'dvi' => 'application/x-dvi', 2284 2556 'gtar' => 'application/x-gtar', 2557 'php3' => 'application/x-httpd-php', 2558 'php4' => 'application/x-httpd-php', 2285 2559 'php' => 'application/x-httpd-php', 2286 'php4' => 'application/x-httpd-php',2287 'php3' => 'application/x-httpd-php',2288 2560 'phtml' => 'application/x-httpd-php', 2289 2561 'phps' => 'application/x-httpd-php-source', … … 2293 2565 'tar' => 'application/x-tar', 2294 2566 'tgz' => 'application/x-tar', 2567 'xht' => 'application/xhtml+xml', 2295 2568 'xhtml' => 'application/xhtml+xml', 2296 'xht' => 'application/xhtml+xml',2297 2569 'zip' => 'application/zip', 2298 2570 'mid' => 'audio/midi', 2299 2571 'midi' => 'audio/midi', 2300 'mpga' => 'audio/mpeg',2301 2572 'mp2' => 'audio/mpeg', 2302 2573 'mp3' => 'audio/mpeg', 2574 'mpga' => 'audio/mpeg', 2303 2575 'aif' => 'audio/x-aiff', 2576 'aifc' => 'audio/x-aiff', 2304 2577 'aiff' => 'audio/x-aiff', 2305 'aifc' => 'audio/x-aiff',2306 2578 'ram' => 'audio/x-pn-realaudio', 2307 2579 'rm' => 'audio/x-pn-realaudio', 2308 2580 'rpm' => 'audio/x-pn-realaudio-plugin', 2309 2581 'ra' => 'audio/x-realaudio', 2310 'rv' => 'video/vnd.rn-realvideo',2311 2582 'wav' => 'audio/x-wav', 2312 2583 'bmp' => 'image/bmp', 2313 2584 'gif' => 'image/gif', 2314 2585 'jpeg' => 'image/jpeg', 2586 'jpe' => 'image/jpeg', 2315 2587 'jpg' => 'image/jpeg', 2316 'jpe' => 'image/jpeg',2317 2588 'png' => 'image/png', 2318 2589 'tiff' => 'image/tiff', 2319 2590 'tif' => 'image/tiff', 2591 'eml' => 'message/rfc822', 2320 2592 'css' => 'text/css', 2321 2593 'html' => 'text/html', 2322 2594 'htm' => 'text/html', 2323 2595 'shtml' => 'text/html', 2596 'log' => 'text/plain', 2597 'text' => 'text/plain', 2324 2598 'txt' => 'text/plain', 2325 'text' => 'text/plain',2326 'log' => 'text/plain',2327 2599 'rtx' => 'text/richtext', 2328 2600 'rtf' => 'text/rtf', … … 2330 2602 'xsl' => 'text/xml', 2331 2603 'mpeg' => 'video/mpeg', 2604 'mpe' => 'video/mpeg', 2332 2605 'mpg' => 'video/mpeg', 2333 'm pe' => 'video/mpeg',2606 'mov' => 'video/quicktime', 2334 2607 'qt' => 'video/quicktime', 2335 ' mov' => 'video/quicktime',2608 'rv' => 'video/vnd.rn-realvideo', 2336 2609 'avi' => 'video/x-msvideo', 2337 'movie' => 'video/x-sgi-movie', 2338 'doc' => 'application/msword', 2339 'word' => 'application/msword', 2340 'xl' => 'application/excel', 2341 'eml' => 'message/rfc822' 2610 'movie' => 'video/x-sgi-movie' 2342 2611 ); 2343 2612 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; … … 2354 2623 * @param mixed $value Parameter Value 2355 2624 * NOTE: will not work with arrays, there are no arrays to set/reset 2625 * @throws phpmailerException 2626 * @return bool 2356 2627 * @todo Should this not be using __set() magic function? 2357 2628 */ … … 2379 2650 */ 2380 2651 public function SecureHeader($str) { 2381 $str = str_replace("\r", '', $str); 2382 $str = str_replace("\n", '', $str); 2383 return trim($str); 2652 return trim(str_replace(array("\r", "\n"), '', $str)); 2384 2653 } 2385 2654 … … 2388 2657 * 2389 2658 * @access public 2659 * @param $cert_filename 2390 2660 * @param string $key_filename Parameter File Name 2391 2661 * @param string $key_pass Password for private key … … 2401 2671 * 2402 2672 * @access public 2403 * @param string $ key_filename Parameter File Name2404 * @ param string $key_pass Password for private key2673 * @param string $txt 2674 * @return string 2405 2675 */ 2406 2676 public function DKIM_QP($txt) { 2407 $tmp = '';2408 2677 $line = ''; 2409 2678 for ($i = 0; $i < strlen($txt); $i++) { … … 2423 2692 * @access public 2424 2693 * @param string $s Header 2694 * @return string 2425 2695 */ 2426 2696 public function DKIM_Sign($s) { … … 2434 2704 return base64_encode($signature); 2435 2705 } 2706 return ''; 2436 2707 } 2437 2708 … … 2441 2712 * @access public 2442 2713 * @param string $s Header 2714 * @return string 2443 2715 */ 2444 2716 public function DKIM_HeaderC($s) { … … 2460 2732 * @access public 2461 2733 * @param string $body Message Body 2734 * @return string 2462 2735 */ 2463 2736 public function DKIM_BodyC($body) { … … 2480 2753 * @param string $subject Subject 2481 2754 * @param string $body Body 2755 * @return string 2482 2756 */ 2483 2757 public function DKIM_Add($headers_line, $subject, $body) { … … 2488 2762 $subject_header = "Subject: $subject"; 2489 2763 $headers = explode($this->LE, $headers_line); 2764 $from_header = ""; 2765 $to_header = ""; 2490 2766 foreach($headers as $header) { 2491 2767 if (strpos($header, 'From:') === 0) { … … 2513 2789 $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); 2514 2790 $signed = $this->DKIM_Sign($toSign); 2515 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; 2516 } 2517 2518 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { 2519 if (!empty($this->action_function) && function_exists($this->action_function)) { 2520 $params = array($isSent, $to, $cc, $bcc, $subject, $body); 2791 return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n"; 2792 } 2793 2794 /** 2795 * Perform callback 2796 * @param boolean $isSent 2797 * @param string $to 2798 * @param string $cc 2799 * @param string $bcc 2800 * @param string $subject 2801 * @param string $body 2802 * @param string $from 2803 */ 2804 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) { 2805 if (!empty($this->action_function) && is_callable($this->action_function)) { 2806 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); 2521 2807 call_user_func_array($this->action_function, $params); 2522 2808 } … … 2524 2810 } 2525 2811 2812 /** 2813 * Exception handler for PHPMailer 2814 * @package PHPMailer 2815 */ 2526 2816 class phpmailerException extends Exception { 2817 /** 2818 * Prettify error message output 2819 * @return string 2820 */ 2527 2821 public function errorMessage() { 2528 2822 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
Note: See TracChangeset
for help on using the changeset viewer.