41 if (version_compare(PHP_VERSION,
'5.0.0',
'<') ) exit(
"Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
59 public $CharSet =
'iso-8859-1';
65 public $ContentType =
'text/plain';
72 public $Encoding =
'8bit';
78 public $ErrorInfo =
'';
84 public $From =
'root@localhost';
90 public $FromName =
'Root User';
103 public $Subject =
'';
119 public $AltBody =
'';
126 public $WordWrap = 0;
132 public $Mailer =
'mail';
138 public $Sendmail =
'/usr/sbin/sendmail';
145 public $PluginDir =
'';
151 public $ConfirmReadingTo =
'';
159 public $Hostname =
'';
166 public $MessageID =
'';
180 public $Host =
'localhost';
199 public $SMTPSecure =
'';
205 public $SMTPAuth =
false;
211 public $Username =
'';
217 public $Password =
'';
224 public $Timeout = 10;
230 public $SMTPDebug =
false;
238 public $SMTPKeepAlive =
false;
245 public $SingleTo =
false;
257 private $smtp = NULL;
258 private $to = array();
259 private $cc = array();
260 private $bcc = array();
261 private $ReplyTo = array();
262 private $all_recipients = array();
263 private $attachment = array();
264 private $CustomHeader = array();
265 private $message_type =
'';
266 private $boundary = array();
267 protected $language = array();
268 private $error_count = 0;
269 private $sign_cert_file =
"";
270 private $sign_key_file =
"";
271 private $sign_key_pass =
"";
272 private $exceptions =
false;
278 const VERSION =
'5.0.0';
279 const STOP_MESSAGE = 0;
280 const STOP_CONTINUE = 1;
281 const STOP_CRITICAL = 2;
292 $this->exceptions = ($exceptions ==
true);
302 $this->ContentType =
'text/html';
304 $this->ContentType =
'text/plain';
313 $this->Mailer =
'smtp';
321 $this->Mailer =
'mail';
329 if (!stristr(ini_get(
'sendmail_path'),
'sendmail')) {
330 $this->Sendmail =
'/var/qmail/bin/sendmail';
332 $this->Mailer =
'sendmail';
340 if (stristr(ini_get(
'sendmail_path'),
'qmail')) {
341 $this->Sendmail =
'/var/qmail/bin/sendmail';
343 $this->Mailer =
'sendmail';
357 return $this->AddAnAddress(
'to', $address, $name);
367 public function AddCC($address, $name =
'') {
368 return $this->AddAnAddress(
'cc', $address, $name);
378 public function AddBCC($address, $name =
'') {
379 return $this->AddAnAddress(
'bcc', $address, $name);
389 return $this->AddAnAddress(
'ReplyTo', $address, $name);
401 private function AddAnAddress($kind, $address, $name =
'') {
402 if (!preg_match(
'/^(to|cc|bcc|ReplyTo)$/', $kind)) {
403 echo
'Invalid recipient array: ' . kind;
406 $address = trim($address);
407 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
408 if (!self::ValidateAddress($address)) {
409 $this->
SetError($this->Lang(
'invalid_address').
': '. $address);
410 if ($this->exceptions) {
413 echo $this->Lang(
'invalid_address').
': '.$address;
416 if ($kind !=
'ReplyTo') {
417 if (!isset($this->all_recipients[strtolower($address)])) {
418 array_push($this->$kind, array($address, $name));
419 $this->all_recipients[strtolower($address)] =
true;
423 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
424 $this->ReplyTo[strtolower($address)] = array($address, $name);
437 public function SetFrom($address, $name =
'') {
438 $address = trim($address);
439 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
440 if (!self::ValidateAddress($address)) {
441 $this->
SetError($this->Lang(
'invalid_address').
': '. $address);
442 if ($this->exceptions) {
445 echo $this->Lang(
'invalid_address').
': '.$address;
448 $this->From = $address;
449 $this->FromName = $name;
465 if (function_exists(
'filter_var')) {
466 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
472 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);
488 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
493 if(!empty($this->AltBody)) {
494 $this->ContentType =
'multipart/alternative';
497 $this->error_count = 0;
498 $this->SetMessageType();
502 if (empty($this->Body)) {
507 switch($this->Mailer) {
511 return $this->
SmtpSend($header, $body);
514 return $this->
MailSend($header, $body);
519 if ($this->exceptions) {
522 echo $e->getMessage().
"\n";
535 if ($this->Sender !=
'') {
536 $sendmail = sprintf(
"%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
538 $sendmail = sprintf(
"%s -oi -t", escapeshellcmd($this->Sendmail));
540 if(!@$mail = popen($sendmail,
'w')) {
541 throw new phpmailerException($this->Lang(
'execute') . $this->Sendmail, self::STOP_CRITICAL);
543 fputs($mail, $header);
545 $result = pclose($mail);
547 throw new phpmailerException($this->Lang(
'execute') . $this->Sendmail, self::STOP_CRITICAL);
561 foreach($this->to as $t) {
564 $to = implode(
', ', $toArr);
566 $params = sprintf(
"-oi -f %s", $this->Sender);
567 if ($this->Sender !=
'' && strlen(ini_get(
'safe_mode'))< 1) {
568 $old_from = ini_get(
'sendmail_from');
569 ini_set(
'sendmail_from', $this->Sender);
570 if ($this->SingleTo ===
true && count($toArr) > 1) {
571 foreach ($toArr as $key => $val) {
578 if ($this->SingleTo ===
true && count($toArr) > 1) {
579 foreach ($toArr as $key => $val) {
586 if (isset($old_from)) {
587 ini_set(
'sendmail_from', $old_from);
605 require_once $this->PluginDir .
'class.smtp.php';
609 throw new phpmailerException($this->Lang(
'smtp_connect_failed'), self::STOP_CRITICAL);
611 $smtp_from = ($this->Sender ==
'') ? $this->From : $this->Sender;
612 if(!$this->smtp->Mail($smtp_from)) {
613 throw new phpmailerException($this->Lang(
'from_failed') . $smtp_from, self::STOP_CRITICAL);
617 foreach($this->to as $to) {
618 if (!$this->smtp->Recipient($to[0])) {
619 $bad_rcpt[] = $to[0];
622 foreach($this->cc as $cc) {
623 if (!$this->smtp->Recipient($cc[0])) {
624 $bad_rcpt[] = $cc[0];
627 foreach($this->bcc as $bcc) {
628 if (!$this->smtp->Recipient($bcc[0])) {
629 $bad_rcpt[] = $bcc[0];
632 if (count($bad_rcpt) > 0 ) {
633 $badaddresses = implode(
', ', $bad_rcpt);
636 if(!$this->smtp->Data($header . $body)) {
639 if($this->SMTPKeepAlive ==
true) {
640 $this->smtp->Reset();
653 if(is_null($this->smtp)) {
654 $this->smtp =
new SMTP();
657 $this->smtp->do_debug = $this->SMTPDebug;
658 $hosts = explode(
';', $this->Host);
660 $connection = $this->smtp->Connected();
664 while($index < count($hosts) && !$connection) {
666 if (preg_match(
'/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
667 $host = $hostinfo[1];
668 $port = $hostinfo[2];
670 $host = $hosts[$index];
674 $tls = ($this->SMTPSecure ==
'tls');
675 $ssl = ($this->SMTPSecure ==
'ssl');
677 if ($this->smtp->Connect(($ssl ?
'ssl://':
'').$host, $port, $this->Timeout)) {
679 $hello = ($this->Helo !=
'' ? $this->Helo : $this->ServerHostname());
680 $this->smtp->Hello($hello);
683 if (!$this->smtp->StartTLS()) {
688 $this->smtp->Hello($hello);
692 if ($this->SMTPAuth) {
693 if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
704 $this->smtp->Reset();
715 if(!is_null($this->smtp)) {
716 if($this->smtp->Connected()) {
718 $this->smtp->Close();
730 function SetLanguage($langcode =
'en', $lang_path =
'language/') {
732 $PHPMAILER_LANG = array(
733 'provide_address' =>
'You must provide at least one recipient email address.',
734 'mailer_not_supported' =>
' mailer is not supported.',
735 'execute' =>
'Could not execute: ',
736 'instantiate' =>
'Could not instantiate mail function.',
737 'authenticate' =>
'SMTP Error: Could not authenticate.',
738 'from_failed' =>
'The following From address failed: ',
739 'recipients_failed' =>
'SMTP Error: The following recipients failed: ',
740 'data_not_accepted' =>
'SMTP Error: Data not accepted.',
741 'connect_host' =>
'SMTP Error: Could not connect to SMTP host.',
742 'file_access' =>
'Could not access file: ',
743 'file_open' =>
'File Error: Could not open file: ',
744 'encoding' =>
'Unknown encoding: ',
745 'signing' =>
'Signing Error: ',
746 'smtp_error' =>
'SMTP server error: ',
747 'empty_message' =>
'Message body empty',
748 'invalid_address' =>
'Invalid address',
749 'variable_set' =>
'Cannot set or reset variable: '
753 if ($langcode !=
'en') {
754 $l = @include $lang_path.
'phpmailer.lang-'.$langcode.
'.php';
756 $this->language = $PHPMAILER_LANG;
765 return $this->language;
778 $addr_str = $type .
': ';
779 $addresses = array();
780 foreach ($addr as $a) {
783 $addr_str .= implode(
', ', $addresses);
784 $addr_str .= $this->LE;
795 if (empty($addr[1])) {
812 public function WrapText($message, $length, $qp_mode =
false) {
813 $soft_break = ($qp_mode) ? sprintf(
" =%s", $this->LE) : $this->LE;
816 $is_utf8 = (strtolower($this->CharSet) ==
"utf-8");
818 $message = $this->FixEOL($message);
819 if (substr($message, -1) == $this->LE) {
820 $message = substr($message, 0, -1);
823 $line = explode($this->LE, $message);
825 for ($i=0 ;$i < count($line); $i++) {
826 $line_part = explode(
' ', $line[$i]);
828 for ($e = 0; $e<count($line_part); $e++) {
829 $word = $line_part[$e];
830 if ($qp_mode and (strlen($word) > $length)) {
831 $space_left = $length - strlen($buf) - 1;
833 if ($space_left > 20) {
837 } elseif (substr($word, $len - 1, 1) ==
"=") {
839 } elseif (substr($word, $len - 2, 1) ==
"=") {
842 $part = substr($word, 0, $len);
843 $word = substr($word, $len);
845 $message .= $buf . sprintf(
"=%s", $this->LE);
847 $message .= $buf . $soft_break;
851 while (strlen($word) > 0) {
855 } elseif (substr($word, $len - 1, 1) ==
"=") {
857 } elseif (substr($word, $len - 2, 1) ==
"=") {
860 $part = substr($word, 0, $len);
861 $word = substr($word, $len);
863 if (strlen($word) > 0) {
864 $message .= $part . sprintf(
"=%s", $this->LE);
871 $buf .= ($e == 0) ? $word : (
' ' . $word);
873 if (strlen($buf) > $length and $buf_o !=
'') {
874 $message .= $buf_o . $soft_break;
879 $message .= $buf . $this->LE;
895 $foundSplitPos =
false;
897 while (!$foundSplitPos) {
898 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
899 $encodedCharPos = strpos($lastChunk,
"=");
900 if ($encodedCharPos !==
false) {
903 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
908 $maxLength = ($encodedCharPos == 0) ? $maxLength :
909 $maxLength - ($lookBack - $encodedCharPos);
910 $foundSplitPos =
true;
911 } elseif ($dec >= 192) {
913 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
914 $foundSplitPos =
true;
915 } elseif ($dec < 192) {
920 $foundSplitPos =
true;
933 if($this->WordWrap < 1) {
937 switch($this->message_type) {
939 case 'alt_attachments':
940 $this->AltBody = $this->
WrapText($this->AltBody, $this->WordWrap);
943 $this->Body = $this->
WrapText($this->Body, $this->WordWrap);
957 $uniq_id = md5(uniqid(time()));
958 $this->boundary[1] =
'b1_' . $uniq_id;
959 $this->boundary[2] =
'b2_' . $uniq_id;
961 $result .= $this->
HeaderLine(
'Date', self::RFCDate());
962 if($this->Sender ==
'') {
963 $result .= $this->
HeaderLine(
'Return-Path', trim($this->From));
965 $result .= $this->
HeaderLine(
'Return-Path', trim($this->Sender));
969 if($this->Mailer !=
'mail') {
970 if(count($this->to) > 0) {
971 $result .= $this->
AddrAppend(
'To', $this->to);
972 } elseif (count($this->cc) == 0) {
973 $result .= $this->
HeaderLine(
'To',
'undisclosed-recipients:;');
978 $from[0][0] = trim($this->From);
979 $from[0][1] = $this->FromName;
983 if((($this->Mailer ==
'sendmail') || ($this->Mailer ==
'mail')) && (count($this->cc) > 0)) {
984 $result .= $this->
AddrAppend(
'Cc', $this->cc);
988 if((($this->Mailer ==
'sendmail') || ($this->Mailer ==
'mail')) && (count($this->bcc) > 0)) {
989 $result .= $this->
AddrAppend(
'Bcc', $this->bcc);
992 if(count($this->ReplyTo) > 0) {
993 $result .= $this->
AddrAppend(
'Reply-to', $this->ReplyTo);
997 if($this->Mailer !=
'mail') {
1001 if($this->MessageID !=
'') {
1002 $result .= $this->
HeaderLine(
'Message-ID',$this->MessageID);
1004 $result .= sprintf(
"Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
1006 $result .= $this->
HeaderLine(
'X-Priority', $this->Priority);
1007 $result .= $this->
HeaderLine(
'X-Mailer',
'PHPMailer ' . self::VERSION .
' (phpmailer.codeworxtech.com)');
1009 if($this->ConfirmReadingTo !=
'') {
1010 $result .= $this->
HeaderLine(
'Disposition-Notification-To',
'<' . trim($this->ConfirmReadingTo) .
'>');
1014 for($index = 0; $index < count($this->CustomHeader); $index++) {
1015 $result .= $this->
HeaderLine(trim($this->CustomHeader[$index][0]), $this->
EncodeHeader(trim($this->CustomHeader[$index][1])));
1017 if (!$this->sign_key_file) {
1018 $result .= $this->
HeaderLine(
'MIME-Version',
'1.0');
1032 switch($this->message_type) {
1034 $result .= $this->
HeaderLine(
'Content-Transfer-Encoding', $this->Encoding);
1035 $result .= sprintf(
"Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
1038 case 'alt_attachments':
1040 $result .= sprintf(
"Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
1042 $result .= $this->
HeaderLine(
'Content-Type',
'multipart/mixed;');
1043 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1047 $result .= $this->
HeaderLine(
'Content-Type',
'multipart/alternative;');
1048 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1052 if($this->Mailer !=
'mail') {
1053 $result .= $this->LE.$this->LE;
1067 if ($this->sign_key_file) {
1073 switch($this->message_type) {
1075 $body .= $this->GetBoundary($this->boundary[1],
'',
'text/plain',
'');
1076 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1077 $body .= $this->LE.$this->LE;
1078 $body .= $this->GetBoundary($this->boundary[1],
'',
'text/html',
'');
1079 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1080 $body .= $this->LE.$this->LE;
1081 $body .= $this->EndBoundary($this->boundary[1]);
1084 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1087 $body .= $this->GetBoundary($this->boundary[1],
'',
'',
'');
1088 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1090 $body .= $this->AttachAll();
1092 case 'alt_attachments':
1093 $body .= sprintf(
"--%s%s", $this->boundary[1], $this->LE);
1094 $body .= sprintf(
"Content-Type: %s;%s" .
"\tboundary=\"%s\"%s",
'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
1095 $body .= $this->GetBoundary($this->boundary[2],
'',
'text/plain',
'') . $this->LE;
1096 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1097 $body .= $this->LE.$this->LE;
1098 $body .= $this->GetBoundary($this->boundary[2],
'',
'text/html',
'') . $this->LE;
1099 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1100 $body .= $this->LE.$this->LE;
1101 $body .= $this->EndBoundary($this->boundary[2]);
1102 $body .= $this->AttachAll();
1108 } elseif ($this->sign_key_file) {
1110 $file = tempnam(
'',
'mail');
1111 file_put_contents($file, $body);
1112 $signed = tempnam(
"",
"signed");
1113 if (@openssl_pkcs7_sign($file, $signed,
"file://".$this->sign_cert_file, array(
"file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
1116 $body = file_get_contents($signed);
1124 if ($this->exceptions) {
1137 private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1139 if($charSet ==
'') {
1140 $charSet = $this->CharSet;
1142 if($contentType ==
'') {
1143 $contentType = $this->ContentType;
1145 if($encoding ==
'') {
1146 $encoding = $this->Encoding;
1148 $result .= $this->
TextLine(
'--' . $boundary);
1149 $result .= sprintf(
"Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1150 $result .= $this->LE;
1151 $result .= $this->
HeaderLine(
'Content-Transfer-Encoding', $encoding);
1152 $result .= $this->LE;
1161 private function EndBoundary($boundary) {
1162 return $this->LE .
'--' . $boundary .
'--' . $this->LE;
1170 private function SetMessageType() {
1171 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1172 $this->message_type =
'plain';
1174 if(count($this->attachment) > 0) {
1175 $this->message_type =
'attachments';
1177 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1178 $this->message_type =
'alt';
1180 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1181 $this->message_type =
'alt_attachments';
1192 return $name .
': ' . $value . $this->LE;
1201 return $value . $this->LE;
1218 public function AddAttachment($path, $name =
'', $encoding =
'base64', $type =
'application/octet-stream') {
1220 if ( !@is_file($path) ) {
1221 throw new phpmailerException($this->Lang(
'file_access') . $path, self::STOP_CONTINUE);
1223 $filename = basename($path);
1224 if ( $name ==
'' ) {
1228 $this->attachment[] = array(
1241 if ($this->exceptions) {
1244 echo $e->getMessage().
"\n";
1245 if ( $e->getCode() == self::STOP_CRITICAL ) {
1257 return $this->attachment;
1266 private function AttachAll() {
1273 foreach ($this->attachment as $attachment) {
1275 $bString = $attachment[5];
1277 $string = $attachment[0];
1279 $path = $attachment[0];
1282 if (in_array($attachment[0], $incl)) {
continue; }
1283 $filename = $attachment[1];
1284 $name = $attachment[2];
1285 $encoding = $attachment[3];
1286 $type = $attachment[4];
1287 $disposition = $attachment[6];
1288 $cid = $attachment[7];
1289 $incl[] = $attachment[0];
1290 if ( isset($cidUniq[$cid]) ) {
continue; }
1291 $cidUniq[$cid] =
true;
1293 $mime[] = sprintf(
"--%s%s", $this->boundary[1], $this->LE);
1294 $mime[] = sprintf(
"Content-Type: %s; name=\"%s\"%s", $type, $this->
EncodeHeader($this->
SecureHeader($name)), $this->LE);
1295 $mime[] = sprintf(
"Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1297 if($disposition ==
'inline') {
1298 $mime[] = sprintf(
"Content-ID: <%s>%s", $cid, $this->LE);
1301 $mime[] = sprintf(
"Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->
EncodeHeader($this->
SecureHeader($name)), $this->LE.$this->LE);
1309 $mime[] = $this->LE.$this->LE;
1311 $mime[] = $this->EncodeFile($path, $encoding);
1315 $mime[] = $this->LE.$this->LE;
1319 $mime[] = sprintf(
"--%s--%s", $this->boundary[1], $this->LE);
1321 return join(
'', $mime);
1333 private function EncodeFile($path, $encoding =
'base64') {
1335 if (!is_readable($path)) {
1338 if (function_exists(
'get_magic_quotes')) {
1339 function get_magic_quotes() {
1343 if (PHP_VERSION < 6) {
1344 $magic_quotes = get_magic_quotes_runtime();
1345 set_magic_quotes_runtime(0);
1347 $file_buffer = file_get_contents($path);
1348 $file_buffer = $this->
EncodeString($file_buffer, $encoding);
1349 if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
1350 return $file_buffer;
1351 }
catch (Exception $e) {
1367 switch(strtolower($encoding)) {
1369 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1373 $encoded = $this->FixEOL($str);
1375 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1376 $encoded .= $this->LE;
1381 case 'quoted-printable':
1385 $this->
SetError($this->Lang(
'encoding') . $encoding);
1399 switch (strtolower($position)) {
1401 if (!preg_match(
'/[\200-\377]/', $str)) {
1403 $encoded = addcslashes($str,
"\0..\37\177\\\"");
1404 if (($str == $encoded) && !preg_match(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1407 return (
"\"$encoded\"");
1410 $x = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $str, $matches);
1413 $x = preg_match_all(
'/[()"]/', $str, $matches);
1417 $x += preg_match_all(
'/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1425 $maxlen = 75 - 7 - strlen($this->CharSet);
1427 if (strlen($str)/3 < $x) {
1429 if (function_exists(
'mb_strlen') && $this->
HasMultiBytes($str)) {
1434 $encoded = base64_encode($str);
1435 $maxlen -= $maxlen % 4;
1436 $encoded = trim(chunk_split($encoded, $maxlen,
"\n"));
1440 $encoded = $this->
EncodeQ($str, $position);
1441 $encoded = $this->
WrapText($encoded, $maxlen,
true);
1442 $encoded = str_replace(
'='.$this->LE,
"\n", trim($encoded));
1445 $encoded = preg_replace(
'/^(.*)$/m',
" =?".$this->CharSet.
"?$encoding?\\1?=", $encoded);
1446 $encoded = trim(str_replace(
"\n", $this->LE, $encoded));
1458 if (function_exists(
'mb_strlen')) {
1459 return (strlen($str) > mb_strlen($str, $this->CharSet));
1474 $start =
"=?".$this->CharSet.
"?B?";
1478 $mb_length = mb_strlen($str, $this->CharSet);
1480 $length = 75 - strlen($start) - strlen($end);
1482 $ratio = $mb_length / strlen($str);
1484 $offset = $avgLength = floor($length * $ratio * .75);
1486 for ($i = 0; $i < $mb_length; $i += $offset) {
1490 $offset = $avgLength - $lookBack;
1491 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
1492 $chunk = base64_encode($chunk);
1495 while (strlen($chunk) > $length);
1497 $encoded .= $chunk . $this->LE;
1501 $encoded = substr($encoded, 0, -strlen($this->LE));
1513 public function EncodeQPphp( $input =
'', $line_max = 76, $space_conv =
false) {
1514 $hex = array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
1515 $lines = preg_split(
'/(?:\r\n|\r|\n)/', $input);
1519 while( list(, $line) = each($lines) ) {
1520 $linlen = strlen($line);
1522 for($i = 0; $i < $linlen; $i++) {
1523 $c = substr( $line, $i, 1 );
1525 if ( ( $i == 0 ) && ( $dec == 46 ) ) {
1529 if ( $i == ( $linlen - 1 ) ) {
1531 }
else if ( $space_conv ) {
1534 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
1535 $h2 = floor($dec/16);
1536 $h1 = floor($dec%16);
1537 $c = $escape.$hex[$h2].$hex[$h1];
1539 if ( (strlen($newline) + strlen($c)) >= $line_max ) {
1540 $output .= $newline.$escape.$eol;
1549 $output .= $newline.$eol;
1566 public function EncodeQP($string, $line_max = 76, $space_conv =
false) {
1567 if (function_exists(
'quoted_printable_encode')) {
1568 return quoted_printable_encode($string);
1570 $filters = stream_get_filters();
1571 if (!in_array(
'convert.*', $filters)) {
1572 return $this->
EncodeQPphp($string, $line_max, $space_conv);
1574 $fp = fopen(
'php://temp/',
'r+');
1575 $string = preg_replace(
'/\r\n?/', $this->LE, $string);
1576 $params = array(
'line-length' => $line_max,
'line-break-chars' => $this->LE);
1577 $s = stream_filter_append($fp,
'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
1578 fputs($fp, $string);
1580 $out = stream_get_contents($fp);
1581 stream_filter_remove($s);
1582 $out = preg_replace(
'/^\./m',
'=2E', $out);
1595 public function EncodeQ ($str, $position =
'text') {
1597 $encoded = preg_replace(
'/[\r\n]*/',
'', $str);
1599 switch (strtolower($position)) {
1601 $encoded = preg_replace(
"/([^A-Za-z0-9!*+\/ -])/e",
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1604 $encoded = preg_replace(
"/([\(\)\"])/e",
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1609 $encoded = preg_replace(
'/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1610 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1615 $encoded = str_replace(
' ',
'_', $encoded);
1630 public function AddStringAttachment($string, $filename, $encoding =
'base64', $type =
'application/octet-stream') {
1632 $this->attachment[] = array(
1657 public function AddEmbeddedImage($path, $cid, $name =
'', $encoding =
'base64', $type =
'application/octet-stream') {
1659 if ( !@is_file($path) ) {
1660 $this->
SetError($this->Lang(
'file_access') . $path);
1664 $filename = basename($path);
1665 if ( $name ==
'' ) {
1670 $this->attachment[] = array(
1690 foreach($this->attachment as $attachment) {
1691 if ($attachment[6] ==
'inline') {
1707 foreach($this->to as $to) {
1708 unset($this->all_recipients[strtolower($to[0])]);
1710 $this->to = array();
1718 foreach($this->cc as $cc) {
1719 unset($this->all_recipients[strtolower($cc[0])]);
1721 $this->cc = array();
1729 foreach($this->bcc as $bcc) {
1730 unset($this->all_recipients[strtolower($bcc[0])]);
1732 $this->bcc = array();
1740 $this->ReplyTo = array();
1749 $this->to = array();
1750 $this->cc = array();
1751 $this->bcc = array();
1752 $this->all_recipients = array();
1761 $this->attachment = array();
1769 $this->CustomHeader = array();
1782 $this->error_count++;
1783 if ($this->Mailer ==
'smtp' and !is_null($this->smtp)) {
1784 $lasterror = $this->smtp->getError();
1785 if (!empty($lasterror) and array_key_exists(
'smtp_msg', $lasterror)) {
1786 $msg .=
'<p>' . $this->Lang(
'smtp_error') . $lasterror[
'smtp_msg'] .
"</p>\n";
1789 $this->ErrorInfo = $msg;
1800 $tzs = ($tz < 0) ?
'-' :
'+';
1802 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1803 $result = sprintf(
"%s %s%04d", date(
'D, j M Y H:i:s'), $tzs, $tz);
1813 private function ServerHostname() {
1814 if (!empty($this->Hostname)) {
1815 $result = $this->Hostname;
1816 } elseif (isset($_SERVER[
'SERVER_NAME'])) {
1817 $result = $_SERVER[
'SERVER_NAME'];
1819 $result =
'localhost.localdomain';
1830 private function Lang($key) {
1831 if(count($this->language) < 1) {
1835 if(isset($this->language[$key])) {
1836 return $this->language[$key];
1838 return 'Language string failed to load: ' . $key;
1848 return ($this->error_count > 0);
1856 private function FixEOL($str) {
1857 $str = str_replace(
"\r\n",
"\n", $str);
1858 $str = str_replace(
"\r",
"\n", $str);
1859 $str = str_replace(
"\n", $this->LE, $str);
1869 $this->CustomHeader[] = explode(
':', $custom_header, 2);
1877 public function MsgHTML($message, $basedir =
'') {
1878 preg_match_all(
"/(src|background)=\"(.*)\"/Ui", $message, $images);
1879 if(isset($images[2])) {
1880 foreach($images[2] as $i => $url) {
1882 if (!preg_match(
'#^[A-z]+://#',$url)) {
1883 $filename = basename($url);
1884 $directory = dirname($url);
1885 ($directory ==
'.')?$directory=
'':
'';
1886 $cid =
'cid:' . md5($filename);
1887 $ext = pathinfo($filename, PATHINFO_EXTENSION);
1889 if ( strlen($basedir) > 1 && substr($basedir,-1) !=
'/') { $basedir .=
'/'; }
1890 if ( strlen($directory) > 1 && substr($directory,-1) !=
'/') { $directory .=
'/'; }
1891 if ( $this->
AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename,
'base64',$mimeType) ) {
1892 $message = preg_replace(
"/".$images[1][$i].
"=\"".preg_quote($url,
'/').
"\"/Ui", $images[1][$i].
"=\"".$cid.
"\"", $message);
1898 $this->Body = $message;
1899 $textMsg = trim(strip_tags(preg_replace(
'/<(head|title|style|script)[^>]*>.*?<\/\\1>/s',
'',$message)));
1900 if (!empty($textMsg) && empty($this->AltBody)) {
1901 $this->AltBody = html_entity_decode($textMsg);
1903 if (empty($this->AltBody)) {
1904 $this->AltBody =
'To view this email message, open it in a program that understands HTML!' .
"\n\n";
1917 'hqx' =>
'application/mac-binhex40',
1918 'cpt' =>
'application/mac-compactpro',
1919 'doc' =>
'application/msword',
1920 'bin' =>
'application/macbinary',
1921 'dms' =>
'application/octet-stream',
1922 'lha' =>
'application/octet-stream',
1923 'lzh' =>
'application/octet-stream',
1924 'exe' =>
'application/octet-stream',
1925 'class' =>
'application/octet-stream',
1926 'psd' =>
'application/octet-stream',
1927 'so' =>
'application/octet-stream',
1928 'sea' =>
'application/octet-stream',
1929 'dll' =>
'application/octet-stream',
1930 'oda' =>
'application/oda',
1931 'pdf' =>
'application/pdf',
1932 'ai' =>
'application/postscript',
1933 'eps' =>
'application/postscript',
1934 'ps' =>
'application/postscript',
1935 'smi' =>
'application/smil',
1936 'smil' =>
'application/smil',
1937 'mif' =>
'application/vnd.mif',
1938 'xls' =>
'application/vnd.ms-excel',
1939 'ppt' =>
'application/vnd.ms-powerpoint',
1940 'wbxml' =>
'application/vnd.wap.wbxml',
1941 'wmlc' =>
'application/vnd.wap.wmlc',
1942 'dcr' =>
'application/x-director',
1943 'dir' =>
'application/x-director',
1944 'dxr' =>
'application/x-director',
1945 'dvi' =>
'application/x-dvi',
1946 'gtar' =>
'application/x-gtar',
1947 'php' =>
'application/x-httpd-php',
1948 'php4' =>
'application/x-httpd-php',
1949 'php3' =>
'application/x-httpd-php',
1950 'phtml' =>
'application/x-httpd-php',
1951 'phps' =>
'application/x-httpd-php-source',
1952 'js' =>
'application/x-javascript',
1953 'swf' =>
'application/x-shockwave-flash',
1954 'sit' =>
'application/x-stuffit',
1955 'tar' =>
'application/x-tar',
1956 'tgz' =>
'application/x-tar',
1957 'xhtml' =>
'application/xhtml+xml',
1958 'xht' =>
'application/xhtml+xml',
1959 'zip' =>
'application/zip',
1960 'mid' =>
'audio/midi',
1961 'midi' =>
'audio/midi',
1962 'mpga' =>
'audio/mpeg',
1963 'mp2' =>
'audio/mpeg',
1964 'mp3' =>
'audio/mpeg',
1965 'aif' =>
'audio/x-aiff',
1966 'aiff' =>
'audio/x-aiff',
1967 'aifc' =>
'audio/x-aiff',
1968 'ram' =>
'audio/x-pn-realaudio',
1969 'rm' =>
'audio/x-pn-realaudio',
1970 'rpm' =>
'audio/x-pn-realaudio-plugin',
1971 'ra' =>
'audio/x-realaudio',
1972 'rv' =>
'video/vnd.rn-realvideo',
1973 'wav' =>
'audio/x-wav',
1974 'bmp' =>
'image/bmp',
1975 'gif' =>
'image/gif',
1976 'jpeg' =>
'image/jpeg',
1977 'jpg' =>
'image/jpeg',
1978 'jpe' =>
'image/jpeg',
1979 'png' =>
'image/png',
1980 'tiff' =>
'image/tiff',
1981 'tif' =>
'image/tiff',
1982 'css' =>
'text/css',
1983 'html' =>
'text/html',
1984 'htm' =>
'text/html',
1985 'shtml' =>
'text/html',
1986 'txt' =>
'text/plain',
1987 'text' =>
'text/plain',
1988 'log' =>
'text/plain',
1989 'rtx' =>
'text/richtext',
1990 'rtf' =>
'text/rtf',
1991 'xml' =>
'text/xml',
1992 'xsl' =>
'text/xml',
1993 'mpeg' =>
'video/mpeg',
1994 'mpg' =>
'video/mpeg',
1995 'mpe' =>
'video/mpeg',
1996 'qt' =>
'video/quicktime',
1997 'mov' =>
'video/quicktime',
1998 'avi' =>
'video/x-msvideo',
1999 'movie' =>
'video/x-sgi-movie',
2000 'doc' =>
'application/msword',
2001 'word' =>
'application/msword',
2002 'xl' =>
'application/excel',
2003 'eml' =>
'message/rfc822'
2005 return (!isset($mimes[strtolower($ext)])) ?
'application/octet-stream' : $mimes[strtolower($ext)];
2020 public function set($name, $value =
'') {
2022 if (isset($this->$name) ) {
2023 $this->$name = $value;
2025 throw new phpmailerException($this->Lang(
'variable_set') . $name, self::STOP_CRITICAL);
2027 }
catch (Exception $e) {
2029 if ($e->getCode() == self::STOP_CRITICAL) {
2043 $str = str_replace(
"\r",
'', $str);
2044 $str = str_replace(
"\n",
'', $str);
2055 public function Sign($cert_filename, $key_filename, $key_pass) {
2056 $this->sign_cert_file = $cert_filename;
2057 $this->sign_key_file = $key_filename;
2058 $this->sign_key_pass = $key_pass;
2063 public function errorMessage() {
2064 $errorMsg =
'<strong>' . $this->getMessage() .
"</strong><br />\n";