Revision 1550
Added by Luisehahne almost 14 years ago
| class.phpmailer.php | ||
|---|---|---|
| 2 | 2 |
/*~ class.phpmailer.php |
| 3 | 3 |
.---------------------------------------------------------------------------. |
| 4 | 4 |
| Software: PHPMailer - PHP email class | |
| 5 |
| Version: 5.1 | |
|
| 6 |
| Contact: via sourceforge.net support pages (also www.worxware.com) | |
|
| 7 |
| Info: http://phpmailer.sourceforge.net | |
|
| 8 |
| Support: http://sourceforge.net/projects/phpmailer/ | |
|
| 5 |
| Version: 5.2 | |
|
| 6 |
| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | |
|
| 9 | 7 |
| ------------------------------------------------------------------------- | |
| 10 |
| Admin: Andy Prevost (project admininistrator) |
|
|
| 8 |
| Admin: Jim Jagielski (project admininistrator) |
|
|
| 11 | 9 |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net | |
| 12 | 10 |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net | |
| 11 |
| : Jim Jagielski (jimjag) jimjag@gmail.com | |
|
| 13 | 12 |
| Founder: Brent R. Matzelle (original founder) | |
| 13 |
| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved. | |
|
| 14 | 14 |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. | |
| 15 | 15 |
| Copyright (c) 2001-2003, Brent R. Matzelle | |
| 16 | 16 |
| ------------------------------------------------------------------------- | |
| ... | ... | |
| 19 | 19 |
| This program is distributed in the hope that it will be useful - WITHOUT | |
| 20 | 20 |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 21 | 21 |
| FITNESS FOR A PARTICULAR PURPOSE. | |
| 22 |
| ------------------------------------------------------------------------- | |
|
| 23 |
| We offer a number of paid services (www.worxware.com): | |
|
| 24 |
| - Web Hosting on highly optimized fast and secure servers | |
|
| 25 |
| - Technology Consulting | |
|
| 26 |
| - Oursourcing (highly qualified programmers and graphic designers) | |
|
| 27 | 22 |
'---------------------------------------------------------------------------' |
| 28 | 23 |
*/ |
| 29 | 24 |
|
| ... | ... | |
| 33 | 28 |
* @package PHPMailer |
| 34 | 29 |
* @author Andy Prevost |
| 35 | 30 |
* @author Marcus Bointon |
| 31 |
* @author Jim Jagielski |
|
| 32 |
* @copyright 2010 - 2011 Jim Jagielski |
|
| 36 | 33 |
* @copyright 2004 - 2009 Andy Prevost |
| 37 |
* @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $
|
|
| 34 |
* @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
|
|
| 38 | 35 |
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
| 39 | 36 |
*/ |
| 40 | 37 |
|
| ... | ... | |
| 119 | 116 |
public $AltBody = ''; |
| 120 | 117 |
|
| 121 | 118 |
/** |
| 119 |
* Stores the complete compiled MIME message body. |
|
| 120 |
* @var string |
|
| 121 |
* @access protected |
|
| 122 |
*/ |
|
| 123 |
protected $MIMEBody = ''; |
|
| 124 |
|
|
| 125 |
/** |
|
| 126 |
* Stores the complete compiled MIME message headers. |
|
| 127 |
* @var string |
|
| 128 |
* @access protected |
|
| 129 |
*/ |
|
| 130 |
protected $MIMEHeader = ''; |
|
| 131 |
|
|
| 132 |
/** |
|
| 122 | 133 |
* Sets word wrapping on the body of the message to a given number of |
| 123 | 134 |
* characters. |
| 124 | 135 |
* @var int |
| ... | ... | |
| 271 | 282 |
|
| 272 | 283 |
/** |
| 273 | 284 |
* Used with DKIM DNS Resource Record |
| 285 |
* @var string |
|
| 286 |
*/ |
|
| 287 |
public $DKIM_passphrase = ''; |
|
| 288 |
|
|
| 289 |
/** |
|
| 290 |
* Used with DKIM DNS Resource Record |
|
| 274 | 291 |
* optional, in format of email address 'you@yourdomain.com' |
| 275 | 292 |
* @var string |
| 276 | 293 |
*/ |
| ... | ... | |
| 300 | 317 |
* Sets the PHPMailer Version number |
| 301 | 318 |
* @var string |
| 302 | 319 |
*/ |
| 303 |
public $Version = '5.1';
|
|
| 320 |
public $Version = '5.2';
|
|
| 304 | 321 |
|
| 322 |
/** |
|
| 323 |
* What to use in the X-Mailer header |
|
| 324 |
* @var string |
|
| 325 |
*/ |
|
| 326 |
public $XMailer = ''; |
|
| 327 |
|
|
| 305 | 328 |
///////////////////////////////////////////////// |
| 306 | 329 |
// PROPERTIES, PRIVATE AND PROTECTED |
| 307 | 330 |
///////////////////////////////////////////////// |
| 308 | 331 |
|
| 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;
|
|
| 332 |
protected $smtp = NULL;
|
|
| 333 |
protected $to = array();
|
|
| 334 |
protected $cc = array();
|
|
| 335 |
protected $bcc = array();
|
|
| 336 |
protected $ReplyTo = array();
|
|
| 337 |
protected $all_recipients = array();
|
|
| 338 |
protected $attachment = array();
|
|
| 339 |
protected $CustomHeader = array();
|
|
| 340 |
protected $message_type = '';
|
|
| 341 |
protected $boundary = array();
|
|
| 342 |
protected $language = array();
|
|
| 343 |
protected $error_count = 0;
|
|
| 344 |
protected $sign_cert_file = '';
|
|
| 345 |
protected $sign_key_file = '';
|
|
| 346 |
protected $sign_key_pass = '';
|
|
| 347 |
protected $exceptions = false;
|
|
| 325 | 348 |
|
| 326 | 349 |
///////////////////////////////////////////////// |
| 327 | 350 |
// CONSTANTS |
| ... | ... | |
| 447 | 470 |
* @param string $address The email address to send to |
| 448 | 471 |
* @param string $name |
| 449 | 472 |
* @return boolean true on success, false if address already used or invalid in some way |
| 450 |
* @access private
|
|
| 473 |
* @access protected
|
|
| 451 | 474 |
*/ |
| 452 |
private function AddAnAddress($kind, $address, $name = '') {
|
|
| 475 |
protected function AddAnAddress($kind, $address, $name = '') {
|
|
| 453 | 476 |
if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
|
| 454 |
echo 'Invalid recipient array: ' . kind; |
|
| 477 |
$this->SetError($this->Lang('Invalid recipient array').': '.$kind);
|
|
| 478 |
if ($this->exceptions) {
|
|
| 479 |
throw new phpmailerException('Invalid recipient array: ' . $kind);
|
|
| 480 |
} |
|
| 481 |
echo $this->Lang('Invalid recipient array').': '.$kind;
|
|
| 455 | 482 |
return false; |
| 456 | 483 |
} |
| 457 | 484 |
$address = trim($address); |
| ... | ... | |
| 485 | 512 |
* @param string $name |
| 486 | 513 |
* @return boolean |
| 487 | 514 |
*/ |
| 488 |
public function SetFrom($address, $name = '',$auto=1) {
|
|
| 515 |
public function SetFrom($address, $name = '', $auto = 1) {
|
|
| 489 | 516 |
$address = trim($address); |
| 490 | 517 |
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
|
| 491 | 518 |
if (!self::ValidateAddress($address)) {
|
| ... | ... | |
| 544 | 571 |
*/ |
| 545 | 572 |
public function Send() {
|
| 546 | 573 |
try {
|
| 574 |
if(!$this->PreSend()) return false; |
|
| 575 |
return $this->PostSend(); |
|
| 576 |
} catch (phpmailerException $e) {
|
|
| 577 |
$this->SetError($e->getMessage()); |
|
| 578 |
if ($this->exceptions) {
|
|
| 579 |
throw $e; |
|
| 580 |
} |
|
| 581 |
return false; |
|
| 582 |
} |
|
| 583 |
} |
|
| 584 |
|
|
| 585 |
protected function PreSend() {
|
|
| 586 |
try {
|
|
| 547 | 587 |
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
|
| 548 | 588 |
throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
|
| 549 | 589 |
} |
| ... | ... | |
| 555 | 595 |
|
| 556 | 596 |
$this->error_count = 0; // reset errors |
| 557 | 597 |
$this->SetMessageType(); |
| 558 |
$header = $this->CreateHeader(); |
|
| 559 |
$body = $this->CreateBody(); |
|
| 560 |
|
|
| 598 |
//Refuse to send an empty message |
|
| 561 | 599 |
if (empty($this->Body)) {
|
| 562 | 600 |
throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
|
| 563 | 601 |
} |
| 564 | 602 |
|
| 603 |
$this->MIMEHeader = $this->CreateHeader(); |
|
| 604 |
$this->MIMEBody = $this->CreateBody(); |
|
| 605 |
|
|
| 606 |
|
|
| 565 | 607 |
// digitally sign with DKIM if enabled |
| 566 | 608 |
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;
|
|
| 609 |
$header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
|
|
| 610 |
$this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
|
|
| 569 | 611 |
} |
| 570 | 612 |
|
| 613 |
return true; |
|
| 614 |
} catch (phpmailerException $e) {
|
|
| 615 |
$this->SetError($e->getMessage()); |
|
| 616 |
if ($this->exceptions) {
|
|
| 617 |
throw $e; |
|
| 618 |
} |
|
| 619 |
return false; |
|
| 620 |
} |
|
| 621 |
} |
|
| 622 |
|
|
| 623 |
protected function PostSend() {
|
|
| 624 |
try {
|
|
| 571 | 625 |
// Choose the mailer and send through it |
| 572 | 626 |
switch($this->Mailer) {
|
| 573 | 627 |
case 'sendmail': |
| 574 |
return $this->SendmailSend($header, $body);
|
|
| 628 |
return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
|
|
| 575 | 629 |
case 'smtp': |
| 576 |
return $this->SmtpSend($header, $body);
|
|
| 630 |
return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
|
|
| 577 | 631 |
default: |
| 578 |
return $this->MailSend($header, $body);
|
|
| 632 |
return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
|
|
| 579 | 633 |
} |
| 580 | 634 |
|
| 581 | 635 |
} catch (phpmailerException $e) {
|
| ... | ... | |
| 612 | 666 |
$result = pclose($mail); |
| 613 | 667 |
// implement call back function if it exists |
| 614 | 668 |
$isSent = ($result == 0) ? 1 : 0; |
| 615 |
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
|
|
| 669 |
$this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
|
|
| 616 | 670 |
if($result != 0) {
|
| 617 | 671 |
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
|
| 618 | 672 |
} |
| ... | ... | |
| 626 | 680 |
$result = pclose($mail); |
| 627 | 681 |
// implement call back function if it exists |
| 628 | 682 |
$isSent = ($result == 0) ? 1 : 0; |
| 629 |
$this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
|
|
| 683 |
$this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
|
|
| 630 | 684 |
if($result != 0) {
|
| 631 | 685 |
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
|
| 632 | 686 |
} |
| ... | ... | |
| 648 | 702 |
} |
| 649 | 703 |
$to = implode(', ', $toArr);
|
| 650 | 704 |
|
| 651 |
$params = sprintf("-oi -f %s", $this->Sender);
|
|
| 652 |
if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
|
|
| 705 |
if (empty($this->Sender)) {
|
|
| 706 |
$params = "-oi -f %s"; |
|
| 707 |
} else {
|
|
| 708 |
$params = sprintf("-oi -f %s", $this->Sender);
|
|
| 709 |
} |
|
| 710 |
if ($this->Sender != '' and !ini_get('safe_mode')) {
|
|
| 653 | 711 |
$old_from = ini_get('sendmail_from');
|
| 654 | 712 |
ini_set('sendmail_from', $this->Sender);
|
| 655 | 713 |
if ($this->SingleTo === true && count($toArr) > 1) {
|
| ... | ... | |
| 657 | 715 |
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 658 | 716 |
// implement call back function if it exists |
| 659 | 717 |
$isSent = ($rt == 1) ? 1 : 0; |
| 660 |
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
|
|
| 718 |
$this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
|
|
| 661 | 719 |
} |
| 662 | 720 |
} else {
|
| 663 | 721 |
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 664 | 722 |
// implement call back function if it exists |
| 665 | 723 |
$isSent = ($rt == 1) ? 1 : 0; |
| 666 |
$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
|
|
| 724 |
$this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
|
|
| 667 | 725 |
} |
| 668 | 726 |
} else {
|
| 669 | 727 |
if ($this->SingleTo === true && count($toArr) > 1) {
|
| ... | ... | |
| 671 | 729 |
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); |
| 672 | 730 |
// implement call back function if it exists |
| 673 | 731 |
$isSent = ($rt == 1) ? 1 : 0; |
| 674 |
$this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
|
|
| 732 |
$this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
|
|
| 675 | 733 |
} |
| 676 | 734 |
} else {
|
| 677 | 735 |
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); |
| 678 | 736 |
// implement call back function if it exists |
| 679 | 737 |
$isSent = ($rt == 1) ? 1 : 0; |
| 680 |
$this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
|
|
| 738 |
$this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
|
|
| 681 | 739 |
} |
| 682 | 740 |
} |
| 683 | 741 |
if (isset($old_from)) {
|
| ... | ... | |
| 716 | 774 |
$bad_rcpt[] = $to[0]; |
| 717 | 775 |
// implement call back function if it exists |
| 718 | 776 |
$isSent = 0; |
| 719 |
$this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
|
|
| 777 |
$this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
|
|
| 720 | 778 |
} else {
|
| 721 | 779 |
// implement call back function if it exists |
| 722 | 780 |
$isSent = 1; |
| 723 |
$this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
|
|
| 781 |
$this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
|
|
| 724 | 782 |
} |
| 725 | 783 |
} |
| 726 | 784 |
foreach($this->cc as $cc) {
|
| ... | ... | |
| 728 | 786 |
$bad_rcpt[] = $cc[0]; |
| 729 | 787 |
// implement call back function if it exists |
| 730 | 788 |
$isSent = 0; |
| 731 |
$this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
|
|
| 789 |
$this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
|
|
| 732 | 790 |
} else {
|
| 733 | 791 |
// implement call back function if it exists |
| 734 | 792 |
$isSent = 1; |
| 735 |
$this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
|
|
| 793 |
$this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
|
|
| 736 | 794 |
} |
| 737 | 795 |
} |
| 738 | 796 |
foreach($this->bcc as $bcc) {
|
| ... | ... | |
| 740 | 798 |
$bad_rcpt[] = $bcc[0]; |
| 741 | 799 |
// implement call back function if it exists |
| 742 | 800 |
$isSent = 0; |
| 743 |
$this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
|
|
| 801 |
$this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
|
|
| 744 | 802 |
} else {
|
| 745 | 803 |
// implement call back function if it exists |
| 746 | 804 |
$isSent = 1; |
| 747 |
$this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
|
|
| 805 |
$this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
|
|
| 748 | 806 |
} |
| 749 | 807 |
} |
| 750 | 808 |
|
| ... | ... | |
| 942 | 1000 |
|
| 943 | 1001 |
$line = explode($this->LE, $message); |
| 944 | 1002 |
$message = ''; |
| 945 |
for ($i=0 ;$i < count($line); $i++) {
|
|
| 1003 |
for ($i = 0 ;$i < count($line); $i++) {
|
|
| 946 | 1004 |
$line_part = explode(' ', $line[$i]);
|
| 947 | 1005 |
$buf = ''; |
| 948 | 1006 |
for ($e = 0; $e<count($line_part); $e++) {
|
| ... | ... | |
| 1056 | 1114 |
|
| 1057 | 1115 |
switch($this->message_type) {
|
| 1058 | 1116 |
case 'alt': |
| 1059 |
case 'alt_attachments': |
|
| 1117 |
case 'alt_inline': |
|
| 1118 |
case 'alt_attach': |
|
| 1119 |
case 'alt_inline_attach': |
|
| 1060 | 1120 |
$this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); |
| 1061 | 1121 |
break; |
| 1062 | 1122 |
default: |
| ... | ... | |
| 1077 | 1137 |
$uniq_id = md5(uniqid(time())); |
| 1078 | 1138 |
$this->boundary[1] = 'b1_' . $uniq_id; |
| 1079 | 1139 |
$this->boundary[2] = 'b2_' . $uniq_id; |
| 1140 |
$this->boundary[3] = 'b3_' . $uniq_id; |
|
| 1080 | 1141 |
|
| 1081 | 1142 |
$result .= $this->HeaderLine('Date', self::RFCDate());
|
| 1082 | 1143 |
if($this->Sender == '') {
|
| ... | ... | |
| 1125 | 1186 |
} |
| 1126 | 1187 |
|
| 1127 | 1188 |
if($this->MessageID != '') {
|
| 1128 |
$result .= $this->HeaderLine('Message-ID',$this->MessageID);
|
|
| 1189 |
$result .= $this->HeaderLine('Message-ID', $this->MessageID);
|
|
| 1129 | 1190 |
} else {
|
| 1130 | 1191 |
$result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
|
| 1131 | 1192 |
} |
| 1132 | 1193 |
$result .= $this->HeaderLine('X-Priority', $this->Priority);
|
| 1133 |
$result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
|
|
| 1194 |
if($this->XMailer) {
|
|
| 1195 |
$result .= $this->HeaderLine('X-Mailer', $this->XMailer);
|
|
| 1196 |
} else {
|
|
| 1197 |
$result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
|
|
| 1198 |
} |
|
| 1134 | 1199 |
|
| 1135 | 1200 |
if($this->ConfirmReadingTo != '') {
|
| 1136 | 1201 |
$result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
|
| ... | ... | |
| 1158 | 1223 |
switch($this->message_type) {
|
| 1159 | 1224 |
case 'plain': |
| 1160 | 1225 |
$result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
|
| 1161 |
$result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
|
|
| 1226 |
$result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
|
|
| 1162 | 1227 |
break; |
| 1163 |
case 'attachments': |
|
| 1164 |
case 'alt_attachments': |
|
| 1165 |
if($this->InlineImageExists()){
|
|
| 1166 |
$result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
|
|
| 1167 |
} else {
|
|
| 1168 |
$result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
|
|
| 1169 |
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
|
|
| 1170 |
} |
|
| 1228 |
case 'inline': |
|
| 1229 |
$result .= $this->HeaderLine('Content-Type', 'multipart/related;');
|
|
| 1230 |
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
|
|
| 1171 | 1231 |
break; |
| 1232 |
case 'attach': |
|
| 1233 |
case 'inline_attach': |
|
| 1234 |
case 'alt_attach': |
|
| 1235 |
case 'alt_inline_attach': |
|
| 1236 |
$result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
|
|
| 1237 |
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
|
|
| 1238 |
break; |
|
| 1172 | 1239 |
case 'alt': |
| 1240 |
case 'alt_inline': |
|
| 1173 | 1241 |
$result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
|
| 1174 | 1242 |
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
|
| 1175 | 1243 |
break; |
| ... | ... | |
| 1197 | 1265 |
$this->SetWordWrap(); |
| 1198 | 1266 |
|
| 1199 | 1267 |
switch($this->message_type) {
|
| 1268 |
case 'plain': |
|
| 1269 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1270 |
break; |
|
| 1271 |
case 'inline': |
|
| 1272 |
$body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1273 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1274 |
$body .= $this->LE.$this->LE; |
|
| 1275 |
$body .= $this->AttachAll("inline", $this->boundary[1]);
|
|
| 1276 |
break; |
|
| 1277 |
case 'attach': |
|
| 1278 |
$body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1279 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1280 |
$body .= $this->LE.$this->LE; |
|
| 1281 |
$body .= $this->AttachAll("attachment", $this->boundary[1]);
|
|
| 1282 |
break; |
|
| 1283 |
case 'inline_attach': |
|
| 1284 |
$body .= $this->TextLine("--" . $this->boundary[1]);
|
|
| 1285 |
$body .= $this->HeaderLine('Content-Type', 'multipart/related;');
|
|
| 1286 |
$body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
|
|
| 1287 |
$body .= $this->LE; |
|
| 1288 |
$body .= $this->GetBoundary($this->boundary[2], '', '', ''); |
|
| 1289 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
|
| 1290 |
$body .= $this->LE.$this->LE; |
|
| 1291 |
$body .= $this->AttachAll("inline", $this->boundary[2]);
|
|
| 1292 |
$body .= $this->LE; |
|
| 1293 |
$body .= $this->AttachAll("attachment", $this->boundary[1]);
|
|
| 1294 |
break; |
|
| 1200 | 1295 |
case 'alt': |
| 1201 | 1296 |
$body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
| 1202 | 1297 |
$body .= $this->EncodeString($this->AltBody, $this->Encoding); |
| ... | ... | |
| 1206 | 1301 |
$body .= $this->LE.$this->LE; |
| 1207 | 1302 |
$body .= $this->EndBoundary($this->boundary[1]); |
| 1208 | 1303 |
break; |
| 1209 |
case 'plain': |
|
| 1304 |
case 'alt_inline': |
|
| 1305 |
$body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); |
|
| 1306 |
$body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1307 |
$body .= $this->LE.$this->LE; |
|
| 1308 |
$body .= $this->TextLine("--" . $this->boundary[1]);
|
|
| 1309 |
$body .= $this->HeaderLine('Content-Type', 'multipart/related;');
|
|
| 1310 |
$body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
|
|
| 1311 |
$body .= $this->LE; |
|
| 1312 |
$body .= $this->GetBoundary($this->boundary[2], '', 'text/html', ''); |
|
| 1210 | 1313 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
| 1314 |
$body .= $this->LE.$this->LE; |
|
| 1315 |
$body .= $this->AttachAll("inline", $this->boundary[2]);
|
|
| 1316 |
$body .= $this->LE; |
|
| 1317 |
$body .= $this->EndBoundary($this->boundary[1]); |
|
| 1211 | 1318 |
break; |
| 1212 |
case 'attachments': |
|
| 1213 |
$body .= $this->GetBoundary($this->boundary[1], '', '', ''); |
|
| 1319 |
case 'alt_attach': |
|
| 1320 |
$body .= $this->TextLine("--" . $this->boundary[1]);
|
|
| 1321 |
$body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
|
|
| 1322 |
$body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
|
|
| 1323 |
$body .= $this->LE; |
|
| 1324 |
$body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', ''); |
|
| 1325 |
$body .= $this->EncodeString($this->AltBody, $this->Encoding); |
|
| 1326 |
$body .= $this->LE.$this->LE; |
|
| 1327 |
$body .= $this->GetBoundary($this->boundary[2], '', 'text/html', ''); |
|
| 1214 | 1328 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
| 1329 |
$body .= $this->LE.$this->LE; |
|
| 1330 |
$body .= $this->EndBoundary($this->boundary[2]); |
|
| 1215 | 1331 |
$body .= $this->LE; |
| 1216 |
$body .= $this->AttachAll(); |
|
| 1332 |
$body .= $this->AttachAll("attachment", $this->boundary[1]);
|
|
| 1217 | 1333 |
break; |
| 1218 |
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 |
|
| 1334 |
case 'alt_inline_attach': |
|
| 1335 |
$body .= $this->TextLine("--" . $this->boundary[1]);
|
|
| 1336 |
$body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
|
|
| 1337 |
$body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
|
|
| 1338 |
$body .= $this->LE; |
|
| 1339 |
$body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', ''); |
|
| 1222 | 1340 |
$body .= $this->EncodeString($this->AltBody, $this->Encoding); |
| 1223 | 1341 |
$body .= $this->LE.$this->LE; |
| 1224 |
$body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body |
|
| 1342 |
$body .= $this->TextLine("--" . $this->boundary[2]);
|
|
| 1343 |
$body .= $this->HeaderLine('Content-Type', 'multipart/related;');
|
|
| 1344 |
$body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
|
|
| 1345 |
$body .= $this->LE; |
|
| 1346 |
$body .= $this->GetBoundary($this->boundary[3], '', 'text/html', ''); |
|
| 1225 | 1347 |
$body .= $this->EncodeString($this->Body, $this->Encoding); |
| 1226 | 1348 |
$body .= $this->LE.$this->LE; |
| 1349 |
$body .= $this->AttachAll("inline", $this->boundary[3]);
|
|
| 1350 |
$body .= $this->LE; |
|
| 1227 | 1351 |
$body .= $this->EndBoundary($this->boundary[2]); |
| 1228 |
$body .= $this->AttachAll(); |
|
| 1352 |
$body .= $this->LE; |
|
| 1353 |
$body .= $this->AttachAll("attachment", $this->boundary[1]);
|
|
| 1229 | 1354 |
break; |
| 1230 | 1355 |
} |
| 1231 | 1356 |
|
| ... | ... | |
| 1258 | 1383 |
|
| 1259 | 1384 |
/** |
| 1260 | 1385 |
* Returns the start of a message boundary. |
| 1261 |
* @access private |
|
| 1386 |
* @access protected |
|
| 1387 |
* @return string |
|
| 1262 | 1388 |
*/ |
| 1263 |
private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
|
|
| 1389 |
protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
|
|
| 1264 | 1390 |
$result = ''; |
| 1265 | 1391 |
if($charSet == '') {
|
| 1266 | 1392 |
$charSet = $this->CharSet; |
| ... | ... | |
| 1272 | 1398 |
$encoding = $this->Encoding; |
| 1273 | 1399 |
} |
| 1274 | 1400 |
$result .= $this->TextLine('--' . $boundary);
|
| 1275 |
$result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
|
|
| 1401 |
$result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
|
|
| 1276 | 1402 |
$result .= $this->LE; |
| 1277 | 1403 |
$result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
|
| 1278 | 1404 |
$result .= $this->LE; |
| ... | ... | |
| 1282 | 1408 |
|
| 1283 | 1409 |
/** |
| 1284 | 1410 |
* Returns the end of a message boundary. |
| 1285 |
* @access private |
|
| 1411 |
* @access protected |
|
| 1412 |
* @return string |
|
| 1286 | 1413 |
*/ |
| 1287 |
private function EndBoundary($boundary) {
|
|
| 1414 |
protected function EndBoundary($boundary) {
|
|
| 1288 | 1415 |
return $this->LE . '--' . $boundary . '--' . $this->LE; |
| 1289 | 1416 |
} |
| 1290 | 1417 |
|
| 1291 | 1418 |
/** |
| 1292 | 1419 |
* Sets the message type. |
| 1293 |
* @access private
|
|
| 1420 |
* @access protected
|
|
| 1294 | 1421 |
* @return void |
| 1295 | 1422 |
*/ |
| 1296 |
private function SetMessageType() {
|
|
| 1297 |
if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
|
|
| 1298 |
$this->message_type = 'plain'; |
|
| 1299 |
} else {
|
|
| 1300 |
if(count($this->attachment) > 0) {
|
|
| 1301 |
$this->message_type = 'attachments'; |
|
| 1302 |
} |
|
| 1303 |
if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
|
|
| 1304 |
$this->message_type = 'alt'; |
|
| 1305 |
} |
|
| 1306 |
if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
|
|
| 1307 |
$this->message_type = 'alt_attachments'; |
|
| 1308 |
} |
|
| 1309 |
} |
|
| 1423 |
protected function SetMessageType() {
|
|
| 1424 |
$this->message_type = array(); |
|
| 1425 |
if($this->AlternativeExists()) $this->message_type[] = "alt"; |
|
| 1426 |
if($this->InlineImageExists()) $this->message_type[] = "inline"; |
|
| 1427 |
if($this->AttachmentExists()) $this->message_type[] = "attach"; |
|
| 1428 |
$this->message_type = implode("_", $this->message_type);
|
|
| 1429 |
if($this->message_type == "") $this->message_type = "plain"; |
|
| 1310 | 1430 |
} |
| 1311 | 1431 |
|
| 1312 | 1432 |
/** |
| ... | ... | |
| 1386 | 1506 |
/** |
| 1387 | 1507 |
* Attaches all fs, string, and binary attachments to the message. |
| 1388 | 1508 |
* Returns an empty string on failure. |
| 1389 |
* @access private
|
|
| 1509 |
* @access protected
|
|
| 1390 | 1510 |
* @return string |
| 1391 | 1511 |
*/ |
| 1392 |
private function AttachAll() {
|
|
| 1512 |
protected function AttachAll($disposition_type, $boundary) {
|
|
| 1393 | 1513 |
// Return text of body |
| 1394 | 1514 |
$mime = array(); |
| 1395 | 1515 |
$cidUniq = array(); |
| ... | ... | |
| 1397 | 1517 |
|
| 1398 | 1518 |
// Add all attachments |
| 1399 | 1519 |
foreach ($this->attachment as $attachment) {
|
| 1400 |
// Check for string attachment |
|
| 1401 |
$bString = $attachment[5]; |
|
| 1402 |
if ($bString) {
|
|
| 1403 |
$string = $attachment[0]; |
|
| 1404 |
} else {
|
|
| 1405 |
$path = $attachment[0]; |
|
| 1406 |
} |
|
| 1520 |
// CHECK IF IT IS A VALID DISPOSITION_FILTER |
|
| 1521 |
if($attachment[6] == $disposition_type) {
|
|
| 1522 |
// Check for string attachment |
|
| 1523 |
$bString = $attachment[5]; |
|
| 1524 |
if ($bString) {
|
|
| 1525 |
$string = $attachment[0]; |
|
| 1526 |
} else {
|
|
| 1527 |
$path = $attachment[0]; |
|
| 1528 |
} |
|
| 1407 | 1529 |
|
| 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; |
|
| 1530 |
$inclhash = md5(serialize($attachment)); |
|
| 1531 |
if (in_array($inclhash, $incl)) { continue; }
|
|
| 1532 |
$incl[] = $inclhash; |
|
| 1533 |
$filename = $attachment[1]; |
|
| 1534 |
$name = $attachment[2]; |
|
| 1535 |
$encoding = $attachment[3]; |
|
| 1536 |
$type = $attachment[4]; |
|
| 1537 |
$disposition = $attachment[6]; |
|
| 1538 |
$cid = $attachment[7]; |
|
| 1539 |
if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
|
|
| 1540 |
$cidUniq[$cid] = true; |
|
| 1418 | 1541 |
|
| 1419 |
$mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
|
|
| 1420 |
$mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
|
|
| 1421 |
$mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
|
|
| 1542 |
$mime[] = sprintf("--%s%s", $boundary, $this->LE);
|
|
| 1543 |
$mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
|
|
| 1544 |
$mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
|
|
| 1422 | 1545 |
|
| 1423 |
if($disposition == 'inline') {
|
|
| 1424 |
$mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
|
|
| 1425 |
} |
|
| 1546 |
if($disposition == 'inline') {
|
|
| 1547 |
$mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
|
|
| 1548 |
}
|
|
| 1426 | 1549 |
|
| 1427 |
$mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
|
|
| 1550 |
$mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
|
|
| 1428 | 1551 |
|
| 1429 |
// Encode as string attachment |
|
| 1430 |
if($bString) {
|
|
| 1431 |
$mime[] = $this->EncodeString($string, $encoding); |
|
| 1432 |
if($this->IsError()) {
|
|
| 1433 |
return ''; |
|
| 1552 |
// Encode as string attachment |
|
| 1553 |
if($bString) {
|
|
| 1554 |
$mime[] = $this->EncodeString($string, $encoding); |
|
| 1555 |
if($this->IsError()) {
|
|
| 1556 |
return ''; |
|
| 1557 |
} |
|
| 1558 |
$mime[] = $this->LE.$this->LE; |
|
| 1559 |
} else {
|
|
| 1560 |
$mime[] = $this->EncodeFile($path, $encoding); |
|
| 1561 |
if($this->IsError()) {
|
|
| 1562 |
return ''; |
|
| 1563 |
} |
|
| 1564 |
$mime[] = $this->LE.$this->LE; |
|
| 1434 | 1565 |
} |
| 1435 |
$mime[] = $this->LE.$this->LE; |
|
| 1436 |
} else {
|
|
| 1437 |
$mime[] = $this->EncodeFile($path, $encoding); |
|
| 1438 |
if($this->IsError()) {
|
|
| 1439 |
return ''; |
|
| 1440 |
} |
|
| 1441 |
$mime[] = $this->LE.$this->LE; |
|
| 1442 | 1566 |
} |
| 1443 | 1567 |
} |
| 1444 | 1568 |
|
| 1445 |
$mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
|
|
| 1569 |
$mime[] = sprintf("--%s--%s", $boundary, $this->LE);
|
|
| 1446 | 1570 |
|
| 1447 |
return join('', $mime);
|
|
| 1571 |
return implode("", $mime);
|
|
| 1448 | 1572 |
} |
| 1449 | 1573 |
|
| 1450 | 1574 |
/** |
| ... | ... | |
| 1453 | 1577 |
* @param string $path The full path to the file |
| 1454 | 1578 |
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' |
| 1455 | 1579 |
* @see EncodeFile() |
| 1456 |
* @access private
|
|
| 1580 |
* @access protected
|
|
| 1457 | 1581 |
* @return string |
| 1458 | 1582 |
*/ |
| 1459 |
private function EncodeFile($path, $encoding = 'base64') {
|
|
| 1583 |
protected function EncodeFile($path, $encoding = 'base64') {
|
|
| 1460 | 1584 |
try {
|
| 1461 | 1585 |
if (!is_readable($path)) {
|
| 1462 | 1586 |
throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
|
| ... | ... | |
| 1466 | 1590 |
return false; |
| 1467 | 1591 |
} |
| 1468 | 1592 |
} |
| 1469 |
if (PHP_VERSION < 6) {
|
|
| 1593 |
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
|
| 1470 | 1594 |
$magic_quotes = get_magic_quotes_runtime(); |
| 1471 | 1595 |
set_magic_quotes_runtime(0); |
| 1472 | 1596 |
} |
| 1473 | 1597 |
$file_buffer = file_get_contents($path); |
| 1474 | 1598 |
$file_buffer = $this->EncodeString($file_buffer, $encoding); |
| 1475 |
if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
|
|
| 1599 |
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
|
| 1600 |
set_magic_quotes_runtime($magic_quotes); |
|
| 1601 |
} |
|
| 1476 | 1602 |
return $file_buffer; |
| 1477 | 1603 |
} catch (Exception $e) {
|
| 1478 | 1604 |
$this->SetError($e->getMessage()); |
| ... | ... | |
| 1488 | 1614 |
* @access public |
| 1489 | 1615 |
* @return string |
| 1490 | 1616 |
*/ |
| 1491 |
public function EncodeString ($str, $encoding = 'base64') {
|
|
| 1617 |
public function EncodeString($str, $encoding = 'base64') {
|
|
| 1492 | 1618 |
$encoded = ''; |
| 1493 | 1619 |
switch(strtolower($encoding)) {
|
| 1494 | 1620 |
case 'base64': |
| ... | ... | |
| 1637 | 1763 |
* @return string |
| 1638 | 1764 |
*/ |
| 1639 | 1765 |
public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
|
| 1640 |
$hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
|
|
| 1766 |
$hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
|
|
| 1641 | 1767 |
$lines = preg_split('/(?:\r\n|\r|\n)/', $input);
|
| 1642 | 1768 |
$eol = "\r\n"; |
| 1643 | 1769 |
$escape = '='; |
| ... | ... | |
| 1718 | 1844 |
* @access public |
| 1719 | 1845 |
* @return string |
| 1720 | 1846 |
*/ |
| 1721 |
public function EncodeQ ($str, $position = 'text') {
|
|
| 1847 |
public function EncodeQ($str, $position = 'text') {
|
|
| 1722 | 1848 |
// There should not be any EOL in the string |
| 1723 | 1849 |
$encoded = preg_replace('/[\r\n]*/', '', $str);
|
| 1724 | 1850 |
|
| ... | ... | |
| 1733 | 1859 |
// Replace every high ascii, control =, ? and _ characters |
| 1734 | 1860 |
//TODO using /e (equivalent to eval()) is probably not a good idea |
| 1735 | 1861 |
$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
|
| 1736 |
"'='.sprintf('%02X', ord('\\1'))", $encoded);
|
|
| 1862 |
"'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
|
|
| 1737 | 1863 |
break; |
| 1738 | 1864 |
} |
| 1739 | 1865 |
|
| ... | ... | |
| 1807 | 1933 |
return true; |
| 1808 | 1934 |
} |
| 1809 | 1935 |
|
| 1936 |
public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
|
|
| 1937 |
// Append to $attachment array |
|
| 1938 |
$this->attachment[] = array( |
|
| 1939 |
0 => $string, |
|
| 1940 |
1 => $filename, |
|
| 1941 |
2 => basename($filename), |
|
| 1942 |
3 => $encoding, |
|
| 1943 |
4 => $type, |
|
| 1944 |
5 => true, // isStringAttachment |
|
| 1945 |
6 => 'inline', |
|
| 1946 |
7 => $cid |
|
| 1947 |
); |
|
| 1948 |
} |
|
| 1949 |
|
|
| 1810 | 1950 |
/** |
| 1811 | 1951 |
* Returns true if an inline attachment is present. |
| 1812 | 1952 |
* @access public |
| ... | ... | |
| 1821 | 1961 |
return false; |
| 1822 | 1962 |
} |
| 1823 | 1963 |
|
| 1964 |
public function AttachmentExists() {
|
|
| 1965 |
foreach($this->attachment as $attachment) {
|
|
| 1966 |
if ($attachment[6] == 'attachment') {
|
|
| 1967 |
return true; |
|
| 1968 |
} |
|
| 1969 |
} |
|
| 1970 |
return false; |
|
| 1971 |
} |
|
| 1972 |
|
|
| 1973 |
public function AlternativeExists() {
|
|
| 1974 |
return strlen($this->AltBody)>0; |
|
| 1975 |
} |
|
| 1976 |
|
|
| 1824 | 1977 |
///////////////////////////////////////////////// |
| 1825 | 1978 |
// CLASS METHODS, MESSAGE RESET |
| 1826 | 1979 |
///////////////////////////////////////////////// |
| ... | ... | |
| 1933 | 2086 |
|
| 1934 | 2087 |
/** |
| 1935 | 2088 |
* Returns the server hostname or 'localhost.localdomain' if unknown. |
| 1936 |
* @access private
|
|
| 2089 |
* @access protected
|
|
| 1937 | 2090 |
* @return string |
| 1938 | 2091 |
*/ |
| 1939 |
private function ServerHostname() {
|
|
| 2092 |
protected function ServerHostname() {
|
|
| 1940 | 2093 |
if (!empty($this->Hostname)) {
|
| 1941 | 2094 |
$result = $this->Hostname; |
| 1942 | 2095 |
} elseif (isset($_SERVER['SERVER_NAME'])) {
|
| ... | ... | |
| 1950 | 2103 |
|
| 1951 | 2104 |
/** |
| 1952 | 2105 |
* Returns a message in the appropriate language. |
| 1953 |
* @access private
|
|
| 2106 |
* @access protected
|
|
| 1954 | 2107 |
* @return string |
| 1955 | 2108 |
*/ |
| 1956 |
private function Lang($key) {
|
|
| 2109 |
protected function Lang($key) {
|
|
| 1957 | 2110 |
if(count($this->language) < 1) {
|
| 1958 | 2111 |
$this->SetLanguage('en'); // set the default language
|
| 1959 | 2112 |
} |
| ... | ... | |
| 1976 | 2129 |
|
| 1977 | 2130 |
/** |
| 1978 | 2131 |
* Changes every end of line from CR or LF to CRLF. |
| 1979 |
* @access private
|
|
| 2132 |
* @access public
|
|
| 1980 | 2133 |
* @return string |
| 1981 | 2134 |
*/ |
| 1982 |
private function FixEOL($str) {
|
|
| 2135 |
public function FixEOL($str) {
|
|
| 1983 | 2136 |
$str = str_replace("\r\n", "\n", $str);
|
| 1984 | 2137 |
$str = str_replace("\r", "\n", $str);
|
| 1985 | 2138 |
$str = str_replace("\n", $this->LE, $str);
|
| ... | ... | |
| 2005 | 2158 |
if(isset($images[2])) {
|
| 2006 | 2159 |
foreach($images[2] as $i => $url) {
|
| 2007 | 2160 |
// do not change urls for absolute images (thanks to corvuscorax) |
| 2008 |
if (!preg_match('#^[A-z]+://#',$url)) {
|
|
| 2161 |
if (!preg_match('#^[A-z]+://#', $url)) {
|
|
| 2009 | 2162 |
$filename = basename($url); |
| 2010 | 2163 |
$directory = dirname($url); |
| 2011 |
($directory == '.')?$directory='':'';
|
|
| 2164 |
($directory == '.') ? $directory='': '';
|
|
| 2012 | 2165 |
$cid = 'cid:' . md5($filename); |
| 2013 | 2166 |
$ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 2014 | 2167 |
$mimeType = self::_mime_types($ext); |
| 2015 |
if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
|
|
| 2016 |
if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
|
|
| 2017 |
if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
|
|
| 2168 |
if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
|
|
| 2169 |
if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
|
|
| 2170 |
if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
|
|
| 2018 | 2171 |
$message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
|
| 2019 | 2172 |
} |
| 2020 | 2173 |
} |
| ... | ... | |
| 2022 | 2175 |
} |
| 2023 | 2176 |
$this->IsHTML(true); |
| 2024 | 2177 |
$this->Body = $message; |
| 2025 |
$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
|
|
| 2178 |
$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
|
|
| 2026 | 2179 |
if (!empty($textMsg) && empty($this->AltBody)) {
|
| 2027 | 2180 |
$this->AltBody = html_entity_decode($textMsg); |
| 2028 | 2181 |
} |
| ... | ... | |
| 2192 | 2345 |
* @param string $key_pass Password for private key |
| 2193 | 2346 |
*/ |
| 2194 | 2347 |
public function DKIM_QP($txt) {
|
| 2195 |
$tmp="";
|
|
| 2196 |
$line="";
|
|
| 2197 |
for ($i=0;$i<strlen($txt);$i++) {
|
|
| 2198 |
$ord=ord($txt[$i]);
|
|
| 2348 |
$tmp = '';
|
|
| 2349 |
$line = '';
|
|
| 2350 |
for ($i = 0; $i < strlen($txt); $i++) {
|
|
| 2351 |
$ord = ord($txt[$i]);
|
|
| 2199 | 2352 |
if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
|
| 2200 |
$line.=$txt[$i];
|
|
| 2353 |
$line .= $txt[$i];
|
|
| 2201 | 2354 |
} else {
|
| 2202 |
$line.="=".sprintf("%02X",$ord);
|
|
| 2355 |
$line .= "=".sprintf("%02X", $ord);
|
|
| 2203 | 2356 |
} |
| 2204 | 2357 |
} |
| 2205 | 2358 |
return $line; |
| ... | ... | |
| 2213 | 2366 |
*/ |
| 2214 | 2367 |
public function DKIM_Sign($s) {
|
| 2215 | 2368 |
$privKeyStr = file_get_contents($this->DKIM_private); |
| 2216 |
if ($this->DKIM_passphrase!='') {
|
|
| 2217 |
$privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); |
|
| 2369 |
if ($this->DKIM_passphrase != '') {
|
|
| 2370 |
$privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
|
|
| 2218 | 2371 |
} else {
|
| 2219 | 2372 |
$privKey = $privKeyStr; |
| 2220 | 2373 |
} |
| ... | ... | |
| 2230 | 2383 |
* @param string $s Header |
| 2231 | 2384 |
*/ |
| 2232 | 2385 |
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
|
|
| 2386 |
$s = preg_replace("/\r\n\s+/", " ", $s);
|
|
| 2387 |
$lines = explode("\r\n", $s);
|
|
| 2388 |
foreach ($lines as $key => $line) {
|
|
| 2389 |
list($heading, $value) = explode(":", $line, 2);
|
|
| 2390 |
$heading = strtolower($heading);
|
|
| 2391 |
$value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces
|
|
| 2392 |
$lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value
|
|
| 2240 | 2393 |
} |
| 2241 |
$s=implode("\r\n",$lines);
|
|
| 2394 |
$s = implode("\r\n", $lines);
|
|
| 2242 | 2395 |
return $s; |
| 2243 | 2396 |
} |
| 2244 | 2397 |
|
| ... | ... | |
| 2251 | 2404 |
public function DKIM_BodyC($body) {
|
| 2252 | 2405 |
if ($body == '') return "\r\n"; |
| 2253 | 2406 |
// stabilize line endings |
| 2254 |
$body=str_replace("\r\n","\n",$body);
|
|
| 2255 |
$body=str_replace("\n","\r\n",$body);
|
|
| 2407 |
$body = str_replace("\r\n", "\n", $body);
|
|
| 2408 |
$body = str_replace("\n", "\r\n", $body);
|
|
| 2256 | 2409 |
// END stabilize line endings |
| 2257 |
while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
|
|
| 2258 |
$body=substr($body,0,strlen($body)-2);
|
|
| 2410 |
while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
|
|
| 2411 |
$body = substr($body, 0, strlen($body) - 2);
|
|
| 2259 | 2412 |
} |
| 2260 | 2413 |
return $body; |
| 2261 | 2414 |
} |
| ... | ... | |
| 2268 | 2421 |
* @param string $subject Subject |
| 2269 | 2422 |
* @param string $body Body |
| 2270 | 2423 |
*/ |
| 2271 |
public function DKIM_Add($headers_line,$subject,$body) {
|
|
| 2424 |
public function DKIM_Add($headers_line, $subject, $body) {
|
|
| 2272 | 2425 |
$DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms |
| 2273 | 2426 |
$DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body |
| 2274 | 2427 |
$DKIMquery = 'dns/txt'; // Query method |
| 2275 | 2428 |
$DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) |
| 2276 | 2429 |
$subject_header = "Subject: $subject"; |
| 2277 |
$headers = explode("\r\n",$headers_line);
|
|
| 2430 |
$headers = explode($this->LE, $headers_line);
|
|
| 2278 | 2431 |
foreach($headers as $header) {
|
| 2279 |
if (strpos($header,'From:') === 0) {
|
|
| 2280 |
$from_header=$header;
|
|
| 2281 |
} elseif (strpos($header,'To:') === 0) {
|
|
| 2282 |
$to_header=$header;
|
|
| 2432 |
if (strpos($header, 'From:') === 0) {
|
|
| 2433 |
$from_header = $header;
|
|
| 2434 |
} elseif (strpos($header, 'To:') === 0) {
|
|
| 2435 |
$to_header = $header;
|
|
| 2283 | 2436 |
} |
| 2284 | 2437 |
} |
| 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
|
|
| 2438 |
$from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
|
|
| 2439 |
$to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
|
|
| 2440 |
$subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
|
|
| 2288 | 2441 |
$body = $this->DKIM_BodyC($body); |
| 2289 | 2442 |
$DKIMlen = strlen($body) ; // Length of body |
| 2290 | 2443 |
$DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
|
| ... | ... | |
| 2303 | 2456 |
return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; |
| 2304 | 2457 |
} |
| 2305 | 2458 |
|
| 2306 |
protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
|
|
| 2459 |
protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
|
|
| 2307 | 2460 |
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); |
|
| 2461 |
$params = array($isSent, $to, $cc, $bcc, $subject, $body);
|
|
| 2462 |
call_user_func_array($this->action_function, $params);
|
|
| 2310 | 2463 |
} |
| 2311 | 2464 |
} |
| 2312 | 2465 |
} |
| ... | ... | |
| 2317 | 2470 |
return $errorMsg; |
| 2318 | 2471 |
} |
| 2319 | 2472 |
} |
| 2320 |
?> |
|
| 2473 |
?> |
|
Also available in: Unified diff
update php mailer to version 5.2