00001 <?php 00002 /*~ class.phpmailer.php 00003 .---------------------------------------------------------------------------. 00004 | Software: PHPMailer - PHP email class | 00005 | Version: 5.0.2 | 00006 | Contact: via sourceforge.net support pages (also www.codeworxtech.com) | 00007 | Info: http://phpmailer.sourceforge.net | 00008 | Support: http://sourceforge.net/projects/phpmailer/ | 00009 | ------------------------------------------------------------------------- | 00010 | Admin: Andy Prevost (project admininistrator) | 00011 | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net | 00012 | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net | 00013 | Founder: Brent R. Matzelle (original founder) | 00014 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. | 00015 | Copyright (c) 2001-2003, Brent R. Matzelle | 00016 | ------------------------------------------------------------------------- | 00017 | License: Distributed under the Lesser General Public License (LGPL) | 00018 | http://www.gnu.org/copyleft/lesser.html | 00019 | This program is distributed in the hope that it will be useful - WITHOUT | 00020 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 00021 | FITNESS FOR A PARTICULAR PURPOSE. | 00022 | ------------------------------------------------------------------------- | 00023 | We offer a number of paid services (www.codeworxtech.com): | 00024 | - Web Hosting on highly optimized fast and secure servers | 00025 | - Technology Consulting | 00026 | - Oursourcing (highly qualified programmers and graphic designers) | 00027 '---------------------------------------------------------------------------' 00028 */ 00029 00041 if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); 00042 00043 class PHPMailer { 00044 00046 // PROPERTIES, PUBLIC 00048 00053 public $Priority = 3; 00054 00059 public $CharSet = 'iso-8859-1'; 00060 00065 public $ContentType = 'text/plain'; 00066 00072 public $Encoding = '8bit'; 00073 00078 public $ErrorInfo = ''; 00079 00084 public $From = 'root@localhost'; 00085 00090 public $FromName = 'Root User'; 00091 00097 public $Sender = ''; 00098 00103 public $Subject = ''; 00104 00110 public $Body = ''; 00111 00119 public $AltBody = ''; 00120 00126 public $WordWrap = 0; 00127 00132 public $Mailer = 'mail'; 00133 00138 public $Sendmail = '/usr/sbin/sendmail'; 00139 00145 public $PluginDir = ''; 00146 00151 public $ConfirmReadingTo = ''; 00152 00159 public $Hostname = ''; 00160 00166 public $MessageID = ''; 00167 00169 // PROPERTIES FOR SMTP 00171 00180 public $Host = 'localhost'; 00181 00186 public $Port = 25; 00187 00192 public $Helo = ''; 00193 00199 public $SMTPSecure = ''; 00200 00205 public $SMTPAuth = false; 00206 00211 public $Username = ''; 00212 00217 public $Password = ''; 00218 00224 public $Timeout = 10; 00225 00230 public $SMTPDebug = false; 00231 00238 public $SMTPKeepAlive = false; 00239 00245 public $SingleTo = false; 00246 00251 public $LE = "\n"; 00252 00257 public $Version = '5.0.2'; 00258 00260 // PROPERTIES, PRIVATE AND PROTECTED 00262 00263 private $smtp = NULL; 00264 private $to = array(); 00265 private $cc = array(); 00266 private $bcc = array(); 00267 private $ReplyTo = array(); 00268 private $all_recipients = array(); 00269 private $attachment = array(); 00270 private $CustomHeader = array(); 00271 private $message_type = ''; 00272 private $boundary = array(); 00273 protected $language = array(); 00274 private $error_count = 0; 00275 private $sign_cert_file = ""; 00276 private $sign_key_file = ""; 00277 private $sign_key_pass = ""; 00278 private $exceptions = false; 00279 00281 // CONSTANTS 00283 00284 const STOP_MESSAGE = 0; // message only, continue processing 00285 const STOP_CONTINUE = 1; // message?, likely ok to continue processing 00286 const STOP_CRITICAL = 2; // message, plus full stop, critical error reached 00287 00289 // METHODS, VARIABLES 00291 00296 public function __construct($exceptions = false) { 00297 $this->exceptions = ($exceptions == true); 00298 } 00299 00305 public function IsHTML($ishtml = true) { 00306 if ($ishtml) { 00307 $this->ContentType = 'text/html'; 00308 } else { 00309 $this->ContentType = 'text/plain'; 00310 } 00311 } 00312 00317 public function IsSMTP() { 00318 $this->Mailer = 'smtp'; 00319 } 00320 00325 public function IsMail() { 00326 $this->Mailer = 'mail'; 00327 } 00328 00333 public function IsSendmail() { 00334 if (!stristr(ini_get('sendmail_path'), 'sendmail')) { 00335 $this->Sendmail = '/var/qmail/bin/sendmail'; 00336 } 00337 $this->Mailer = 'sendmail'; 00338 } 00339 00344 public function IsQmail() { 00345 if (stristr(ini_get('sendmail_path'), 'qmail')) { 00346 $this->Sendmail = '/var/qmail/bin/sendmail'; 00347 } 00348 $this->Mailer = 'sendmail'; 00349 } 00350 00352 // METHODS, RECIPIENTS 00354 00361 public function AddAddress($address, $name = '') { 00362 return $this->AddAnAddress('to', $address, $name); 00363 } 00364 00372 public function AddCC($address, $name = '') { 00373 return $this->AddAnAddress('cc', $address, $name); 00374 } 00375 00383 public function AddBCC($address, $name = '') { 00384 return $this->AddAnAddress('bcc', $address, $name); 00385 } 00386 00393 public function AddReplyTo($address, $name = '') { 00394 return $this->AddAnAddress('ReplyTo', $address, $name); 00395 } 00396 00406 private function AddAnAddress($kind, $address, $name = '') { 00407 if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { 00408 echo 'Invalid recipient array: ' . kind; 00409 return false; 00410 } 00411 $address = trim($address); 00412 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 00413 if (!self::ValidateAddress($address)) { 00414 $this->SetError($this->Lang('invalid_address').': '. $address); 00415 if ($this->exceptions) { 00416 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 00417 } 00418 echo $this->Lang('invalid_address').': '.$address; 00419 return false; 00420 } 00421 if ($kind != 'ReplyTo') { 00422 if (!isset($this->all_recipients[strtolower($address)])) { 00423 array_push($this->$kind, array($address, $name)); 00424 $this->all_recipients[strtolower($address)] = true; 00425 return true; 00426 } 00427 } else { 00428 if (!array_key_exists(strtolower($address), $this->ReplyTo)) { 00429 $this->ReplyTo[strtolower($address)] = array($address, $name); 00430 return true; 00431 } 00432 } 00433 return false; 00434 } 00435 00442 public function SetFrom($address, $name = '') { 00443 $address = trim($address); 00444 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 00445 if (!self::ValidateAddress($address)) { 00446 $this->SetError($this->Lang('invalid_address').': '. $address); 00447 if ($this->exceptions) { 00448 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 00449 } 00450 echo $this->Lang('invalid_address').': '.$address; 00451 return false; 00452 } 00453 $this->From = $address; 00454 $this->FromName = $name; 00455 return true; 00456 } 00457 00469 public static function ValidateAddress($address) { 00470 if (function_exists('filter_var')) { //Introduced in PHP 5.2 00471 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { 00472 return false; 00473 } else { 00474 return true; 00475 } 00476 } else { 00477 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); 00478 } 00479 } 00480 00482 // METHODS, MAIL SENDING 00484 00491 public function Send() { 00492 try { 00493 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 00494 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); 00495 } 00496 00497 // Set whether the message is multipart/alternative 00498 if(!empty($this->AltBody)) { 00499 $this->ContentType = 'multipart/alternative'; 00500 } 00501 00502 $this->error_count = 0; // reset errors 00503 $this->SetMessageType(); 00504 $header = $this->CreateHeader(); 00505 $body = $this->CreateBody(); 00506 00507 if (empty($this->Body)) { 00508 throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); 00509 } 00510 00511 // Choose the mailer and send through it 00512 switch($this->Mailer) { 00513 case 'sendmail': 00514 return $this->SendmailSend($header, $body); 00515 case 'smtp': 00516 return $this->SmtpSend($header, $body); 00517 case 'mail': 00518 default: 00519 return $this->MailSend($header, $body); 00520 } 00521 00522 } catch (phpmailerException $e) { 00523 $this->SetError($e->getMessage()); 00524 if ($this->exceptions) { 00525 throw $e; 00526 } 00527 echo $e->getMessage()."\n"; 00528 return false; 00529 } 00530 } 00531 00539 protected function SendmailSend($header, $body) { 00540 if ($this->Sender != '') { 00541 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); 00542 } else { 00543 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 00544 } 00545 if(!@$mail = popen($sendmail, 'w')) { 00546 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 00547 } 00548 fputs($mail, $header); 00549 fputs($mail, $body); 00550 $result = pclose($mail); 00551 if($result != 0) { 00552 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 00553 } 00554 return true; 00555 } 00556 00564 protected function MailSend($header, $body) { 00565 $toArr = array(); 00566 foreach($this->to as $t) { 00567 $toArr[] = $this->AddrFormat($t); 00568 } 00569 $to = implode(', ', $toArr); 00570 00571 $params = sprintf("-oi -f %s", $this->Sender); 00572 if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { 00573 $old_from = ini_get('sendmail_from'); 00574 ini_set('sendmail_from', $this->Sender); 00575 if ($this->SingleTo === true && count($toArr) > 1) { 00576 foreach ($toArr as $key => $val) { 00577 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 00578 } 00579 } else { 00580 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 00581 } 00582 } else { 00583 if ($this->SingleTo === true && count($toArr) > 1) { 00584 foreach ($toArr as $key => $val) { 00585 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 00586 } 00587 } else { 00588 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); 00589 } 00590 } 00591 if (isset($old_from)) { 00592 ini_set('sendmail_from', $old_from); 00593 } 00594 if(!$rt) { 00595 throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL); 00596 } 00597 return true; 00598 } 00599 00609 protected function SmtpSend($header, $body) { 00610 require_once $this->PluginDir . 'class.smtp.php'; 00611 $bad_rcpt = array(); 00612 00613 if(!$this->SmtpConnect()) { 00614 throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL); 00615 } 00616 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; 00617 if(!$this->smtp->Mail($smtp_from)) { 00618 throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); 00619 } 00620 00621 // Attempt to send attach all recipients 00622 foreach($this->to as $to) { 00623 if (!$this->smtp->Recipient($to[0])) { 00624 $bad_rcpt[] = $to[0]; 00625 } 00626 } 00627 foreach($this->cc as $cc) { 00628 if (!$this->smtp->Recipient($cc[0])) { 00629 $bad_rcpt[] = $cc[0]; 00630 } 00631 } 00632 foreach($this->bcc as $bcc) { 00633 if (!$this->smtp->Recipient($bcc[0])) { 00634 $bad_rcpt[] = $bcc[0]; 00635 } 00636 } 00637 if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses 00638 $badaddresses = implode(', ', $bad_rcpt); 00639 throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses); 00640 } 00641 if(!$this->smtp->Data($header . $body)) { 00642 throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL); 00643 } 00644 if($this->SMTPKeepAlive == true) { 00645 $this->smtp->Reset(); 00646 } 00647 return true; 00648 } 00649 00657 public function SmtpConnect() { 00658 if(is_null($this->smtp)) { 00659 $this->smtp = new SMTP(); 00660 } 00661 00662 $this->smtp->do_debug = $this->SMTPDebug; 00663 $hosts = explode(';', $this->Host); 00664 $index = 0; 00665 $connection = $this->smtp->Connected(); 00666 00667 // Retry while there is no connection 00668 try { 00669 while($index < count($hosts) && !$connection) { 00670 $hostinfo = array(); 00671 if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) { 00672 $host = $hostinfo[1]; 00673 $port = $hostinfo[2]; 00674 } else { 00675 $host = $hosts[$index]; 00676 $port = $this->Port; 00677 } 00678 00679 $tls = ($this->SMTPSecure == 'tls'); 00680 $ssl = ($this->SMTPSecure == 'ssl'); 00681 00682 if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) { 00683 00684 $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname()); 00685 $this->smtp->Hello($hello); 00686 00687 if ($tls) { 00688 if (!$this->smtp->StartTLS()) { 00689 throw new phpmailerException($this->Lang('tls')); 00690 } 00691 00692 //We must resend HELO after tls negotiation 00693 $this->smtp->Hello($hello); 00694 } 00695 00696 $connection = true; 00697 if ($this->SMTPAuth) { 00698 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 00699 throw new phpmailerException($this->Lang('authenticate')); 00700 } 00701 } 00702 } 00703 $index++; 00704 if (!$connection) { 00705 throw new phpmailerException($this->Lang('connect_host')); 00706 } 00707 } 00708 } catch (phpmailerException $e) { 00709 $this->smtp->Reset(); 00710 throw $e; 00711 } 00712 return true; 00713 } 00714 00719 public function SmtpClose() { 00720 if(!is_null($this->smtp)) { 00721 if($this->smtp->Connected()) { 00722 $this->smtp->Quit(); 00723 $this->smtp->Close(); 00724 } 00725 } 00726 } 00727 00735 function SetLanguage($langcode = 'en', $lang_path = 'language/') { 00736 //Define full set of translatable strings 00737 $PHPMAILER_LANG = array( 00738 'provide_address' => 'You must provide at least one recipient email address.', 00739 'mailer_not_supported' => ' mailer is not supported.', 00740 'execute' => 'Could not execute: ', 00741 'instantiate' => 'Could not instantiate mail function.', 00742 'authenticate' => 'SMTP Error: Could not authenticate.', 00743 'from_failed' => 'The following From address failed: ', 00744 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 00745 'data_not_accepted' => 'SMTP Error: Data not accepted.', 00746 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 00747 'file_access' => 'Could not access file: ', 00748 'file_open' => 'File Error: Could not open file: ', 00749 'encoding' => 'Unknown encoding: ', 00750 'signing' => 'Signing Error: ', 00751 'smtp_error' => 'SMTP server error: ', 00752 'empty_message' => 'Message body empty', 00753 'invalid_address' => 'Invalid address', 00754 'variable_set' => 'Cannot set or reset variable: ' 00755 ); 00756 //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! 00757 $l = true; 00758 if ($langcode != 'en') { //There is no English translation file 00759 $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php'; 00760 } 00761 $this->language = $PHPMAILER_LANG; 00762 return ($l == true); //Returns false if language not found 00763 } 00764 00769 public function GetTranslations() { 00770 return $this->language; 00771 } 00772 00774 // METHODS, MESSAGE CREATION 00776 00782 public function AddrAppend($type, $addr) { 00783 $addr_str = $type . ': '; 00784 $addresses = array(); 00785 foreach ($addr as $a) { 00786 $addresses[] = $this->AddrFormat($a); 00787 } 00788 $addr_str .= implode(', ', $addresses); 00789 $addr_str .= $this->LE; 00790 00791 return $addr_str; 00792 } 00793 00799 public function AddrFormat($addr) { 00800 if (empty($addr[1])) { 00801 return $this->SecureHeader($addr[0]); 00802 } else { 00803 return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">"; 00804 } 00805 } 00806 00817 public function WrapText($message, $length, $qp_mode = false) { 00818 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE; 00819 // If utf-8 encoding is used, we will need to make sure we don't 00820 // split multibyte characters when we wrap 00821 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 00822 00823 $message = $this->FixEOL($message); 00824 if (substr($message, -1) == $this->LE) { 00825 $message = substr($message, 0, -1); 00826 } 00827 00828 $line = explode($this->LE, $message); 00829 $message = ''; 00830 for ($i=0 ;$i < count($line); $i++) { 00831 $line_part = explode(' ', $line[$i]); 00832 $buf = ''; 00833 for ($e = 0; $e<count($line_part); $e++) { 00834 $word = $line_part[$e]; 00835 if ($qp_mode and (strlen($word) > $length)) { 00836 $space_left = $length - strlen($buf) - 1; 00837 if ($e != 0) { 00838 if ($space_left > 20) { 00839 $len = $space_left; 00840 if ($is_utf8) { 00841 $len = $this->UTF8CharBoundary($word, $len); 00842 } elseif (substr($word, $len - 1, 1) == "=") { 00843 $len--; 00844 } elseif (substr($word, $len - 2, 1) == "=") { 00845 $len -= 2; 00846 } 00847 $part = substr($word, 0, $len); 00848 $word = substr($word, $len); 00849 $buf .= ' ' . $part; 00850 $message .= $buf . sprintf("=%s", $this->LE); 00851 } else { 00852 $message .= $buf . $soft_break; 00853 } 00854 $buf = ''; 00855 } 00856 while (strlen($word) > 0) { 00857 $len = $length; 00858 if ($is_utf8) { 00859 $len = $this->UTF8CharBoundary($word, $len); 00860 } elseif (substr($word, $len - 1, 1) == "=") { 00861 $len--; 00862 } elseif (substr($word, $len - 2, 1) == "=") { 00863 $len -= 2; 00864 } 00865 $part = substr($word, 0, $len); 00866 $word = substr($word, $len); 00867 00868 if (strlen($word) > 0) { 00869 $message .= $part . sprintf("=%s", $this->LE); 00870 } else { 00871 $buf = $part; 00872 } 00873 } 00874 } else { 00875 $buf_o = $buf; 00876 $buf .= ($e == 0) ? $word : (' ' . $word); 00877 00878 if (strlen($buf) > $length and $buf_o != '') { 00879 $message .= $buf_o . $soft_break; 00880 $buf = $word; 00881 } 00882 } 00883 } 00884 $message .= $buf . $this->LE; 00885 } 00886 00887 return $message; 00888 } 00889 00899 public function UTF8CharBoundary($encodedText, $maxLength) { 00900 $foundSplitPos = false; 00901 $lookBack = 3; 00902 while (!$foundSplitPos) { 00903 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack); 00904 $encodedCharPos = strpos($lastChunk, "="); 00905 if ($encodedCharPos !== false) { 00906 // Found start of encoded character byte within $lookBack block. 00907 // Check the encoded byte value (the 2 chars after the '=') 00908 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2); 00909 $dec = hexdec($hex); 00910 if ($dec < 128) { // Single byte character. 00911 // If the encoded char was found at pos 0, it will fit 00912 // otherwise reduce maxLength to start of the encoded char 00913 $maxLength = ($encodedCharPos == 0) ? $maxLength : 00914 $maxLength - ($lookBack - $encodedCharPos); 00915 $foundSplitPos = true; 00916 } elseif ($dec >= 192) { // First byte of a multi byte character 00917 // Reduce maxLength to split at start of character 00918 $maxLength = $maxLength - ($lookBack - $encodedCharPos); 00919 $foundSplitPos = true; 00920 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back 00921 $lookBack += 3; 00922 } 00923 } else { 00924 // No encoded character found 00925 $foundSplitPos = true; 00926 } 00927 } 00928 return $maxLength; 00929 } 00930 00931 00937 public function SetWordWrap() { 00938 if($this->WordWrap < 1) { 00939 return; 00940 } 00941 00942 switch($this->message_type) { 00943 case 'alt': 00944 case 'alt_attachments': 00945 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); 00946 break; 00947 default: 00948 $this->Body = $this->WrapText($this->Body, $this->WordWrap); 00949 break; 00950 } 00951 } 00952 00958 public function CreateHeader() { 00959 $result = ''; 00960 00961 // Set the boundaries 00962 $uniq_id = md5(uniqid(time())); 00963 $this->boundary[1] = 'b1_' . $uniq_id; 00964 $this->boundary[2] = 'b2_' . $uniq_id; 00965 00966 $result .= $this->HeaderLine('Date', self::RFCDate()); 00967 if($this->Sender == '') { 00968 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 00969 } else { 00970 $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); 00971 } 00972 00973 // To be created automatically by mail() 00974 if($this->Mailer != 'mail') { 00975 if(count($this->to) > 0) { 00976 $result .= $this->AddrAppend('To', $this->to); 00977 } elseif (count($this->cc) == 0) { 00978 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); 00979 } 00980 } 00981 00982 $from = array(); 00983 $from[0][0] = trim($this->From); 00984 $from[0][1] = $this->FromName; 00985 $result .= $this->AddrAppend('From', $from); 00986 00987 // sendmail and mail() extract Cc from the header before sending 00988 if(count($this->cc) > 0) { 00989 $result .= $this->AddrAppend('Cc', $this->cc); 00990 } 00991 00992 // sendmail and mail() extract Bcc from the header before sending 00993 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) { 00994 $result .= $this->AddrAppend('Bcc', $this->bcc); 00995 } 00996 00997 if(count($this->ReplyTo) > 0) { 00998 $result .= $this->AddrAppend('Reply-to', $this->ReplyTo); 00999 } 01000 01001 // mail() sets the subject itself 01002 if($this->Mailer != 'mail') { 01003 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); 01004 } 01005 01006 if($this->MessageID != '') { 01007 $result .= $this->HeaderLine('Message-ID',$this->MessageID); 01008 } else { 01009 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 01010 } 01011 $result .= $this->HeaderLine('X-Priority', $this->Priority); 01012 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.codeworxtech.com)'); 01013 01014 if($this->ConfirmReadingTo != '') { 01015 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>'); 01016 } 01017 01018 // Add custom headers 01019 for($index = 0; $index < count($this->CustomHeader); $index++) { 01020 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1]))); 01021 } 01022 if (!$this->sign_key_file) { 01023 $result .= $this->HeaderLine('MIME-Version', '1.0'); 01024 $result .= $this->GetMailMIME(); 01025 } 01026 01027 return $result; 01028 } 01029 01035 public function GetMailMIME() { 01036 $result = ''; 01037 switch($this->message_type) { 01038 case 'plain': 01039 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 01040 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); 01041 break; 01042 case 'attachments': 01043 case 'alt_attachments': 01044 if($this->InlineImageExists()){ 01045 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); 01046 } else { 01047 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); 01048 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 01049 } 01050 break; 01051 case 'alt': 01052 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 01053 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 01054 break; 01055 } 01056 01057 if($this->Mailer != 'mail') { 01058 $result .= $this->LE.$this->LE; 01059 } 01060 01061 return $result; 01062 } 01063 01069 public function CreateBody() { 01070 $body = ''; 01071 01072 if ($this->sign_key_file) { 01073 $body .= $this->GetMailMIME(); 01074 } 01075 01076 $this->SetWordWrap(); 01077 01078 switch($this->message_type) { 01079 case 'alt': 01080 $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); 01081 $body .= $this->EncodeString($this->AltBody, $this->Encoding); 01082 $body .= $this->LE.$this->LE; 01083 $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', ''); 01084 $body .= $this->EncodeString($this->Body, $this->Encoding); 01085 $body .= $this->LE.$this->LE; 01086 $body .= $this->EndBoundary($this->boundary[1]); 01087 break; 01088 case 'plain': 01089 $body .= $this->EncodeString($this->Body, $this->Encoding); 01090 break; 01091 case 'attachments': 01092 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 01093 $body .= $this->EncodeString($this->Body, $this->Encoding); 01094 $body .= $this->LE; 01095 $body .= $this->AttachAll(); 01096 break; 01097 case 'alt_attachments': 01098 $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); 01099 $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); 01100 $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body 01101 $body .= $this->EncodeString($this->AltBody, $this->Encoding); 01102 $body .= $this->LE.$this->LE; 01103 $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body 01104 $body .= $this->EncodeString($this->Body, $this->Encoding); 01105 $body .= $this->LE.$this->LE; 01106 $body .= $this->EndBoundary($this->boundary[2]); 01107 $body .= $this->AttachAll(); 01108 break; 01109 } 01110 01111 if ($this->IsError()) { 01112 $body = ''; 01113 } elseif ($this->sign_key_file) { 01114 try { 01115 $file = tempnam('', 'mail'); 01116 file_put_contents($file, $body); //TODO check this worked 01117 $signed = tempnam("", "signed"); 01118 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { 01119 @unlink($file); 01120 @unlink($signed); 01121 $body = file_get_contents($signed); 01122 } else { 01123 @unlink($file); 01124 @unlink($signed); 01125 throw new phpmailerException($this->Lang("signing").openssl_error_string()); 01126 } 01127 } catch (phpmailerException $e) { 01128 $body = ''; 01129 if ($this->exceptions) { 01130 throw $e; 01131 } 01132 } 01133 } 01134 01135 return $body; 01136 } 01137 01142 private function GetBoundary($boundary, $charSet, $contentType, $encoding) { 01143 $result = ''; 01144 if($charSet == '') { 01145 $charSet = $this->CharSet; 01146 } 01147 if($contentType == '') { 01148 $contentType = $this->ContentType; 01149 } 01150 if($encoding == '') { 01151 $encoding = $this->Encoding; 01152 } 01153 $result .= $this->TextLine('--' . $boundary); 01154 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); 01155 $result .= $this->LE; 01156 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); 01157 $result .= $this->LE; 01158 01159 return $result; 01160 } 01161 01166 private function EndBoundary($boundary) { 01167 return $this->LE . '--' . $boundary . '--' . $this->LE; 01168 } 01169 01175 private function SetMessageType() { 01176 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { 01177 $this->message_type = 'plain'; 01178 } else { 01179 if(count($this->attachment) > 0) { 01180 $this->message_type = 'attachments'; 01181 } 01182 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { 01183 $this->message_type = 'alt'; 01184 } 01185 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { 01186 $this->message_type = 'alt_attachments'; 01187 } 01188 } 01189 } 01190 01196 public function HeaderLine($name, $value) { 01197 return $name . ': ' . $value . $this->LE; 01198 } 01199 01205 public function TextLine($value) { 01206 return $value . $this->LE; 01207 } 01208 01210 // CLASS METHODS, ATTACHMENTS 01212 01223 public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { 01224 try { 01225 if ( !@is_file($path) ) { 01226 throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE); 01227 } 01228 $filename = basename($path); 01229 if ( $name == '' ) { 01230 $name = $filename; 01231 } 01232 01233 $this->attachment[] = array( 01234 0 => $path, 01235 1 => $filename, 01236 2 => $name, 01237 3 => $encoding, 01238 4 => $type, 01239 5 => false, // isStringAttachment 01240 6 => 'attachment', 01241 7 => 0 01242 ); 01243 01244 } catch (phpmailerException $e) { 01245 $this->SetError($e->getMessage()); 01246 if ($this->exceptions) { 01247 throw $e; 01248 } 01249 echo $e->getMessage()."\n"; 01250 if ( $e->getCode() == self::STOP_CRITICAL ) { 01251 return false; 01252 } 01253 } 01254 return true; 01255 } 01256 01261 public function GetAttachments() { 01262 return $this->attachment; 01263 } 01264 01271 private function AttachAll() { 01272 // Return text of body 01273 $mime = array(); 01274 $cidUniq = array(); 01275 $incl = array(); 01276 01277 // Add all attachments 01278 foreach ($this->attachment as $attachment) { 01279 // Check for string attachment 01280 $bString = $attachment[5]; 01281 if ($bString) { 01282 $string = $attachment[0]; 01283 } else { 01284 $path = $attachment[0]; 01285 } 01286 01287 if (in_array($attachment[0], $incl)) { continue; } 01288 $filename = $attachment[1]; 01289 $name = $attachment[2]; 01290 $encoding = $attachment[3]; 01291 $type = $attachment[4]; 01292 $disposition = $attachment[6]; 01293 $cid = $attachment[7]; 01294 $incl[] = $attachment[0]; 01295 if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } 01296 $cidUniq[$cid] = true; 01297 01298 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); 01299 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); 01300 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); 01301 01302 if($disposition == 'inline') { 01303 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); 01304 } 01305 01306 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); 01307 01308 // Encode as string attachment 01309 if($bString) { 01310 $mime[] = $this->EncodeString($string, $encoding); 01311 if($this->IsError()) { 01312 return ''; 01313 } 01314 $mime[] = $this->LE.$this->LE; 01315 } else { 01316 $mime[] = $this->EncodeFile($path, $encoding); 01317 if($this->IsError()) { 01318 return ''; 01319 } 01320 $mime[] = $this->LE.$this->LE; 01321 } 01322 } 01323 01324 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); 01325 01326 return join('', $mime); 01327 } 01328 01338 private function EncodeFile($path, $encoding = 'base64') { 01339 try { 01340 if (!is_readable($path)) { 01341 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 01342 } 01343 if (function_exists('get_magic_quotes')) { 01344 function get_magic_quotes() { 01345 return false; 01346 } 01347 } 01348 if (PHP_VERSION < 6) { 01349 $magic_quotes = get_magic_quotes_runtime(); 01350 set_magic_quotes_runtime(0); 01351 } 01352 $file_buffer = file_get_contents($path); 01353 $file_buffer = $this->EncodeString($file_buffer, $encoding); 01354 if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } 01355 return $file_buffer; 01356 } catch (Exception $e) { 01357 $this->SetError($e->getMessage()); 01358 return ''; 01359 } 01360 } 01361 01370 public function EncodeString ($str, $encoding = 'base64') { 01371 $encoded = ''; 01372 switch(strtolower($encoding)) { 01373 case 'base64': 01374 $encoded = chunk_split(base64_encode($str), 76, $this->LE); 01375 break; 01376 case '7bit': 01377 case '8bit': 01378 $encoded = $this->FixEOL($str); 01379 //Make sure it ends with a line break 01380 if (substr($encoded, -(strlen($this->LE))) != $this->LE) 01381 $encoded .= $this->LE; 01382 break; 01383 case 'binary': 01384 $encoded = $str; 01385 break; 01386 case 'quoted-printable': 01387 $encoded = $this->EncodeQP($str); 01388 break; 01389 default: 01390 $this->SetError($this->Lang('encoding') . $encoding); 01391 break; 01392 } 01393 return $encoded; 01394 } 01395 01401 public function EncodeHeader($str, $position = 'text') { 01402 $x = 0; 01403 01404 switch (strtolower($position)) { 01405 case 'phrase': 01406 if (!preg_match('/[\200-\377]/', $str)) { 01407 // Can't use addslashes as we don't know what value has magic_quotes_sybase 01408 $encoded = addcslashes($str, "\0..\37\177\\\""); 01409 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) { 01410 return ($encoded); 01411 } else { 01412 return ("\"$encoded\""); 01413 } 01414 } 01415 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches); 01416 break; 01417 case 'comment': 01418 $x = preg_match_all('/[()"]/', $str, $matches); 01419 // Fall-through 01420 case 'text': 01421 default: 01422 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches); 01423 break; 01424 } 01425 01426 if ($x == 0) { 01427 return ($str); 01428 } 01429 01430 $maxlen = 75 - 7 - strlen($this->CharSet); 01431 // Try to select the encoding which should produce the shortest output 01432 if (strlen($str)/3 < $x) { 01433 $encoding = 'B'; 01434 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { 01435 // Use a custom function which correctly encodes and wraps long 01436 // multibyte strings without breaking lines within a character 01437 $encoded = $this->Base64EncodeWrapMB($str); 01438 } else { 01439 $encoded = base64_encode($str); 01440 $maxlen -= $maxlen % 4; 01441 $encoded = trim(chunk_split($encoded, $maxlen, "\n")); 01442 } 01443 } else { 01444 $encoding = 'Q'; 01445 $encoded = $this->EncodeQ($str, $position); 01446 $encoded = $this->WrapText($encoded, $maxlen, true); 01447 $encoded = str_replace('='.$this->LE, "\n", trim($encoded)); 01448 } 01449 01450 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); 01451 $encoded = trim(str_replace("\n", $this->LE, $encoded)); 01452 01453 return $encoded; 01454 } 01455 01462 public function HasMultiBytes($str) { 01463 if (function_exists('mb_strlen')) { 01464 return (strlen($str) > mb_strlen($str, $this->CharSet)); 01465 } else { // Assume no multibytes (we can't handle without mbstring functions anyway) 01466 return false; 01467 } 01468 } 01469 01478 public function Base64EncodeWrapMB($str) { 01479 $start = "=?".$this->CharSet."?B?"; 01480 $end = "?="; 01481 $encoded = ""; 01482 01483 $mb_length = mb_strlen($str, $this->CharSet); 01484 // Each line must have length <= 75, including $start and $end 01485 $length = 75 - strlen($start) - strlen($end); 01486 // Average multi-byte ratio 01487 $ratio = $mb_length / strlen($str); 01488 // Base64 has a 4:3 ratio 01489 $offset = $avgLength = floor($length * $ratio * .75); 01490 01491 for ($i = 0; $i < $mb_length; $i += $offset) { 01492 $lookBack = 0; 01493 01494 do { 01495 $offset = $avgLength - $lookBack; 01496 $chunk = mb_substr($str, $i, $offset, $this->CharSet); 01497 $chunk = base64_encode($chunk); 01498 $lookBack++; 01499 } 01500 while (strlen($chunk) > $length); 01501 01502 $encoded .= $chunk . $this->LE; 01503 } 01504 01505 // Chomp the last linefeed 01506 $encoded = substr($encoded, 0, -strlen($this->LE)); 01507 return $encoded; 01508 } 01509 01518 public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { 01519 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 01520 $lines = preg_split('/(?:\r\n|\r|\n)/', $input); 01521 $eol = "\r\n"; 01522 $escape = '='; 01523 $output = ''; 01524 while( list(, $line) = each($lines) ) { 01525 $linlen = strlen($line); 01526 $newline = ''; 01527 for($i = 0; $i < $linlen; $i++) { 01528 $c = substr( $line, $i, 1 ); 01529 $dec = ord( $c ); 01530 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E 01531 $c = '=2E'; 01532 } 01533 if ( $dec == 32 ) { 01534 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only 01535 $c = '=20'; 01536 } else if ( $space_conv ) { 01537 $c = '=20'; 01538 } 01539 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 01540 $h2 = floor($dec/16); 01541 $h1 = floor($dec%16); 01542 $c = $escape.$hex[$h2].$hex[$h1]; 01543 } 01544 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted 01545 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 01546 $newline = ''; 01547 // check if newline first character will be point or not 01548 if ( $dec == 46 ) { 01549 $c = '=2E'; 01550 } 01551 } 01552 $newline .= $c; 01553 } // end of for 01554 $output .= $newline.$eol; 01555 } // end of while 01556 return $output; 01557 } 01558 01571 public function EncodeQP($string, $line_max = 76, $space_conv = false) { 01572 if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3) 01573 return quoted_printable_encode($string); 01574 } 01575 $filters = stream_get_filters(); 01576 if (!in_array('convert.*', $filters)) { //Got convert stream filter? 01577 return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation 01578 } 01579 $fp = fopen('php://temp/', 'r+'); 01580 $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks 01581 $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE); 01582 $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params); 01583 fputs($fp, $string); 01584 rewind($fp); 01585 $out = stream_get_contents($fp); 01586 stream_filter_remove($s); 01587 $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange 01588 fclose($fp); 01589 return $out; 01590 } 01591 01600 public function EncodeQ ($str, $position = 'text') { 01601 // There should not be any EOL in the string 01602 $encoded = preg_replace('/[\r\n]*/', '', $str); 01603 01604 switch (strtolower($position)) { 01605 case 'phrase': 01606 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 01607 break; 01608 case 'comment': 01609 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 01610 case 'text': 01611 default: 01612 // Replace every high ascii, control =, ? and _ characters 01613 //TODO using /e (equivalent to eval()) is probably not a good idea 01614 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', 01615 "'='.sprintf('%02X', ord('\\1'))", $encoded); 01616 break; 01617 } 01618 01619 // Replace every spaces to _ (more readable than =20) 01620 $encoded = str_replace(' ', '_', $encoded); 01621 01622 return $encoded; 01623 } 01624 01635 public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') { 01636 // Append to $attachment array 01637 $this->attachment[] = array( 01638 0 => $string, 01639 1 => $filename, 01640 2 => $filename, 01641 3 => $encoding, 01642 4 => $type, 01643 5 => true, // isStringAttachment 01644 6 => 'attachment', 01645 7 => 0 01646 ); 01647 } 01648 01662 public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { 01663 01664 if ( !@is_file($path) ) { 01665 $this->SetError($this->Lang('file_access') . $path); 01666 return false; 01667 } 01668 01669 $filename = basename($path); 01670 if ( $name == '' ) { 01671 $name = $filename; 01672 } 01673 01674 // Append to $attachment array 01675 $this->attachment[] = array( 01676 0 => $path, 01677 1 => $filename, 01678 2 => $name, 01679 3 => $encoding, 01680 4 => $type, 01681 5 => false, // isStringAttachment 01682 6 => 'inline', 01683 7 => $cid 01684 ); 01685 01686 return true; 01687 } 01688 01694 public function InlineImageExists() { 01695 foreach($this->attachment as $attachment) { 01696 if ($attachment[6] == 'inline') { 01697 return true; 01698 } 01699 } 01700 return false; 01701 } 01702 01704 // CLASS METHODS, MESSAGE RESET 01706 01711 public function ClearAddresses() { 01712 foreach($this->to as $to) { 01713 unset($this->all_recipients[strtolower($to[0])]); 01714 } 01715 $this->to = array(); 01716 } 01717 01722 public function ClearCCs() { 01723 foreach($this->cc as $cc) { 01724 unset($this->all_recipients[strtolower($cc[0])]); 01725 } 01726 $this->cc = array(); 01727 } 01728 01733 public function ClearBCCs() { 01734 foreach($this->bcc as $bcc) { 01735 unset($this->all_recipients[strtolower($bcc[0])]); 01736 } 01737 $this->bcc = array(); 01738 } 01739 01744 public function ClearReplyTos() { 01745 $this->ReplyTo = array(); 01746 } 01747 01753 public function ClearAllRecipients() { 01754 $this->to = array(); 01755 $this->cc = array(); 01756 $this->bcc = array(); 01757 $this->all_recipients = array(); 01758 } 01759 01765 public function ClearAttachments() { 01766 $this->attachment = array(); 01767 } 01768 01773 public function ClearCustomHeaders() { 01774 $this->CustomHeader = array(); 01775 } 01776 01778 // CLASS METHODS, MISCELLANEOUS 01780 01786 protected function SetError($msg) { 01787 $this->error_count++; 01788 if ($this->Mailer == 'smtp' and !is_null($this->smtp)) { 01789 $lasterror = $this->smtp->getError(); 01790 if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { 01791 $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; 01792 } 01793 } 01794 $this->ErrorInfo = $msg; 01795 } 01796 01803 public static function RFCDate() { 01804 $tz = date('Z'); 01805 $tzs = ($tz < 0) ? '-' : '+'; 01806 $tz = abs($tz); 01807 $tz = (int)($tz/3600)*100 + ($tz%3600)/60; 01808 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz); 01809 01810 return $result; 01811 } 01812 01818 private function ServerHostname() { 01819 if (!empty($this->Hostname)) { 01820 $result = $this->Hostname; 01821 } elseif (isset($_SERVER['SERVER_NAME'])) { 01822 $result = $_SERVER['SERVER_NAME']; 01823 } else { 01824 $result = 'localhost.localdomain'; 01825 } 01826 01827 return $result; 01828 } 01829 01835 private function Lang($key) { 01836 if(count($this->language) < 1) { 01837 $this->SetLanguage('en'); // set the default language 01838 } 01839 01840 if(isset($this->language[$key])) { 01841 return $this->language[$key]; 01842 } else { 01843 return 'Language string failed to load: ' . $key; 01844 } 01845 } 01846 01852 public function IsError() { 01853 return ($this->error_count > 0); 01854 } 01855 01861 private function FixEOL($str) { 01862 $str = str_replace("\r\n", "\n", $str); 01863 $str = str_replace("\r", "\n", $str); 01864 $str = str_replace("\n", $this->LE, $str); 01865 return $str; 01866 } 01867 01873 public function AddCustomHeader($custom_header) { 01874 $this->CustomHeader[] = explode(':', $custom_header, 2); 01875 } 01876 01882 public function MsgHTML($message, $basedir = '') { 01883 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); 01884 if(isset($images[2])) { 01885 foreach($images[2] as $i => $url) { 01886 // do not change urls for absolute images (thanks to corvuscorax) 01887 if (!preg_match('#^[A-z]+://#',$url)) { 01888 $filename = basename($url); 01889 $directory = dirname($url); 01890 ($directory == '.')?$directory='':''; 01891 $cid = 'cid:' . md5($filename); 01892 $ext = pathinfo($filename, PATHINFO_EXTENSION); 01893 $mimeType = self::_mime_types($ext); 01894 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } 01895 if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } 01896 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { 01897 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); 01898 } 01899 } 01900 } 01901 } 01902 $this->IsHTML(true); 01903 $this->Body = $message; 01904 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); 01905 if (!empty($textMsg) && empty($this->AltBody)) { 01906 $this->AltBody = html_entity_decode($textMsg); 01907 } 01908 if (empty($this->AltBody)) { 01909 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 01910 } 01911 } 01912 01920 public static function _mime_types($ext = '') { 01921 $mimes = array( 01922 'hqx' => 'application/mac-binhex40', 01923 'cpt' => 'application/mac-compactpro', 01924 'doc' => 'application/msword', 01925 'bin' => 'application/macbinary', 01926 'dms' => 'application/octet-stream', 01927 'lha' => 'application/octet-stream', 01928 'lzh' => 'application/octet-stream', 01929 'exe' => 'application/octet-stream', 01930 'class' => 'application/octet-stream', 01931 'psd' => 'application/octet-stream', 01932 'so' => 'application/octet-stream', 01933 'sea' => 'application/octet-stream', 01934 'dll' => 'application/octet-stream', 01935 'oda' => 'application/oda', 01936 'pdf' => 'application/pdf', 01937 'ai' => 'application/postscript', 01938 'eps' => 'application/postscript', 01939 'ps' => 'application/postscript', 01940 'smi' => 'application/smil', 01941 'smil' => 'application/smil', 01942 'mif' => 'application/vnd.mif', 01943 'xls' => 'application/vnd.ms-excel', 01944 'ppt' => 'application/vnd.ms-powerpoint', 01945 'wbxml' => 'application/vnd.wap.wbxml', 01946 'wmlc' => 'application/vnd.wap.wmlc', 01947 'dcr' => 'application/x-director', 01948 'dir' => 'application/x-director', 01949 'dxr' => 'application/x-director', 01950 'dvi' => 'application/x-dvi', 01951 'gtar' => 'application/x-gtar', 01952 'php' => 'application/x-httpd-php', 01953 'php4' => 'application/x-httpd-php', 01954 'php3' => 'application/x-httpd-php', 01955 'phtml' => 'application/x-httpd-php', 01956 'phps' => 'application/x-httpd-php-source', 01957 'js' => 'application/x-javascript', 01958 'swf' => 'application/x-shockwave-flash', 01959 'sit' => 'application/x-stuffit', 01960 'tar' => 'application/x-tar', 01961 'tgz' => 'application/x-tar', 01962 'xhtml' => 'application/xhtml+xml', 01963 'xht' => 'application/xhtml+xml', 01964 'zip' => 'application/zip', 01965 'mid' => 'audio/midi', 01966 'midi' => 'audio/midi', 01967 'mpga' => 'audio/mpeg', 01968 'mp2' => 'audio/mpeg', 01969 'mp3' => 'audio/mpeg', 01970 'aif' => 'audio/x-aiff', 01971 'aiff' => 'audio/x-aiff', 01972 'aifc' => 'audio/x-aiff', 01973 'ram' => 'audio/x-pn-realaudio', 01974 'rm' => 'audio/x-pn-realaudio', 01975 'rpm' => 'audio/x-pn-realaudio-plugin', 01976 'ra' => 'audio/x-realaudio', 01977 'rv' => 'video/vnd.rn-realvideo', 01978 'wav' => 'audio/x-wav', 01979 'bmp' => 'image/bmp', 01980 'gif' => 'image/gif', 01981 'jpeg' => 'image/jpeg', 01982 'jpg' => 'image/jpeg', 01983 'jpe' => 'image/jpeg', 01984 'png' => 'image/png', 01985 'tiff' => 'image/tiff', 01986 'tif' => 'image/tiff', 01987 'css' => 'text/css', 01988 'html' => 'text/html', 01989 'htm' => 'text/html', 01990 'shtml' => 'text/html', 01991 'txt' => 'text/plain', 01992 'text' => 'text/plain', 01993 'log' => 'text/plain', 01994 'rtx' => 'text/richtext', 01995 'rtf' => 'text/rtf', 01996 'xml' => 'text/xml', 01997 'xsl' => 'text/xml', 01998 'mpeg' => 'video/mpeg', 01999 'mpg' => 'video/mpeg', 02000 'mpe' => 'video/mpeg', 02001 'qt' => 'video/quicktime', 02002 'mov' => 'video/quicktime', 02003 'avi' => 'video/x-msvideo', 02004 'movie' => 'video/x-sgi-movie', 02005 'doc' => 'application/msword', 02006 'word' => 'application/msword', 02007 'xl' => 'application/excel', 02008 'eml' => 'message/rfc822' 02009 ); 02010 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; 02011 } 02012 02025 public function set($name, $value = '') { 02026 try { 02027 if (isset($this->$name) ) { 02028 $this->$name = $value; 02029 } else { 02030 throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL); 02031 } 02032 } catch (Exception $e) { 02033 $this->SetError($e->getMessage()); 02034 if ($e->getCode() == self::STOP_CRITICAL) { 02035 return false; 02036 } 02037 } 02038 return true; 02039 } 02040 02047 public function SecureHeader($str) { 02048 $str = str_replace("\r", '', $str); 02049 $str = str_replace("\n", '', $str); 02050 return trim($str); 02051 } 02052 02060 public function Sign($cert_filename, $key_filename, $key_pass) { 02061 $this->sign_cert_file = $cert_filename; 02062 $this->sign_key_file = $key_filename; 02063 $this->sign_key_pass = $key_pass; 02064 } 02065 } 02066 02067 class phpmailerException extends Exception { 02068 public function errorMessage() { 02069 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; 02070 return $errorMsg; 02071 } 02072 } 02073 ?>
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
