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");
84 public $From =
'root@localhost';
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();
320 private $error_count = 0;
321 private $sign_cert_file =
"";
322 private $sign_key_file =
"";
323 private $sign_key_pass =
"";
324 private $exceptions =
false;
343 $this->exceptions = ($exceptions ==
true);
353 $this->ContentType =
'text/html';
355 $this->ContentType =
'text/plain';
364 $this->Mailer =
'smtp';
372 $this->Mailer =
'mail';
380 if (!stristr(ini_get(
'sendmail_path'),
'sendmail')) {
381 $this->Sendmail =
'/var/qmail/bin/sendmail';
383 $this->Mailer =
'sendmail';
391 if (stristr(ini_get(
'sendmail_path'),
'qmail')) {
392 $this->Sendmail =
'/var/qmail/bin/sendmail';
394 $this->Mailer =
'sendmail';
453 if (!preg_match(
'/^(to|cc|bcc|ReplyTo)$/', $kind)) {
454 echo
'Invalid recipient array: ' . kind;
458 $name = trim(preg_replace(
'/[\r\n]+/',
'',
$name));
459 if (!self::ValidateAddress(
$address)) {
461 if ($this->exceptions) {
464 echo $this->Lang(
'invalid_address').
': '.
$address;
467 if ($kind !=
'ReplyTo') {
468 if (!isset($this->all_recipients[strtolower(
$address)])) {
470 $this->all_recipients[strtolower(
$address)] =
true;
474 if (!array_key_exists(strtolower(
$address), $this->ReplyTo)) {
490 $name = trim(preg_replace(
'/[\r\n]+/',
'',
$name));
491 if (!self::ValidateAddress(
$address)) {
493 if ($this->exceptions) {
496 echo $this->Lang(
'invalid_address').
': '.
$address;
500 $this->FromName =
$name;
502 if (empty($this->ReplyTo)) {
505 if (empty($this->Sender)) {
524 if (function_exists(
'filter_var')) {
525 if(filter_var(
$address, FILTER_VALIDATE_EMAIL) === FALSE) {
531 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);
547 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
552 if(!empty($this->AltBody)) {
553 $this->ContentType =
'multipart/alternative';
556 $this->error_count = 0;
557 $this->SetMessageType();
561 if (empty($this->Body)) {
566 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;
572 switch($this->Mailer) {
576 return $this->
SmtpSend($header, $body);
578 return $this->
MailSend($header, $body);
583 if ($this->exceptions) {
586 echo $e->getMessage().
"\n";
599 if ($this->Sender !=
'') {
600 $sendmail = sprintf(
"%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
602 $sendmail = sprintf(
"%s -oi -t", escapeshellcmd($this->Sendmail));
604 if ($this->SingleTo ===
true) {
605 foreach ($this->SingleToArray as $key => $val) {
606 if(!@
$mail = popen($sendmail,
'w')) {
607 throw new phpmailerException($this->Lang(
'execute') . $this->Sendmail, self::STOP_CRITICAL);
609 fputs(
$mail,
"To: " . $val .
"\n");
610 fputs(
$mail, $header);
614 $isSent = (
$result == 0) ? 1 : 0;
615 $this->
doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
617 throw new phpmailerException($this->Lang(
'execute') . $this->Sendmail, self::STOP_CRITICAL);
621 if(!@
$mail = popen($sendmail,
'w')) {
622 throw new phpmailerException($this->Lang(
'execute') . $this->Sendmail, self::STOP_CRITICAL);
624 fputs(
$mail, $header);
628 $isSent = (
$result == 0) ? 1 : 0;
629 $this->
doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
631 throw new phpmailerException($this->Lang(
'execute') . $this->Sendmail, self::STOP_CRITICAL);
646 foreach($this->to as $t) {
649 $to = implode(
', ', $toArr);
651 $params = sprintf(
"-oi -f %s", $this->Sender);
652 if ($this->Sender !=
'' && strlen(ini_get(
'safe_mode'))< 1) {
653 $old_from = ini_get(
'sendmail_from');
654 ini_set(
'sendmail_from', $this->Sender);
655 if ($this->SingleTo ===
true && count($toArr) > 1) {
656 foreach ($toArr as $key => $val) {
659 $isSent = ($rt == 1) ? 1 : 0;
660 $this->
doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
665 $isSent = ($rt == 1) ? 1 : 0;
666 $this->
doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
669 if ($this->SingleTo ===
true && count($toArr) > 1) {
670 foreach ($toArr as $key => $val) {
673 $isSent = ($rt == 1) ? 1 : 0;
674 $this->
doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
679 $isSent = ($rt == 1) ? 1 : 0;
680 $this->
doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
683 if (isset($old_from)) {
684 ini_set(
'sendmail_from', $old_from);
702 require_once $this->PluginDir .
'class.smtp.php';
706 throw new phpmailerException($this->Lang(
'smtp_connect_failed'), self::STOP_CRITICAL);
708 $smtp_from = ($this->Sender ==
'') ? $this->From : $this->Sender;
709 if(!$this->smtp->Mail($smtp_from)) {
710 throw new phpmailerException($this->Lang(
'from_failed') . $smtp_from, self::STOP_CRITICAL);
714 foreach($this->to as $to) {
715 if (!$this->smtp->Recipient($to[0])) {
716 $bad_rcpt[] = $to[0];
719 $this->
doCallback($isSent,$to[0],
'',
'',$this->Subject,$body);
723 $this->
doCallback($isSent,$to[0],
'',
'',$this->Subject,$body);
726 foreach($this->cc as $cc) {
727 if (!$this->smtp->Recipient($cc[0])) {
728 $bad_rcpt[] = $cc[0];
731 $this->
doCallback($isSent,
'',$cc[0],
'',$this->Subject,$body);
735 $this->
doCallback($isSent,
'',$cc[0],
'',$this->Subject,$body);
738 foreach($this->bcc as $bcc) {
739 if (!$this->smtp->Recipient($bcc[0])) {
740 $bad_rcpt[] = $bcc[0];
743 $this->
doCallback($isSent,
'',
'',$bcc[0],$this->Subject,$body);
747 $this->
doCallback($isSent,
'',
'',$bcc[0],$this->Subject,$body);
752 if (count($bad_rcpt) > 0 ) {
753 $badaddresses = implode(
', ', $bad_rcpt);
756 if(!$this->smtp->Data($header . $body)) {
759 if($this->SMTPKeepAlive ==
true) {
760 $this->smtp->Reset();
773 if(is_null($this->smtp)) {
774 $this->smtp =
new SMTP();
778 $hosts = explode(
';', $this->Host);
780 $connection = $this->smtp->Connected();
784 while($index < count($hosts) && !$connection) {
786 if (preg_match(
'/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
787 $host = $hostinfo[1];
788 $port = $hostinfo[2];
790 $host = $hosts[$index];
794 $tls = ($this->SMTPSecure ==
'tls');
795 $ssl = ($this->SMTPSecure ==
'ssl');
797 if ($this->smtp->Connect(($ssl ?
'ssl://':
'').$host, $port, $this->Timeout)) {
799 $hello = ($this->Helo !=
'' ? $this->Helo : $this->ServerHostname());
800 $this->smtp->Hello($hello);
803 if (!$this->smtp->StartTLS()) {
808 $this->smtp->Hello($hello);
812 if ($this->SMTPAuth) {
813 if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
824 $this->smtp->Reset();
835 if(!is_null($this->smtp)) {
836 if($this->smtp->Connected()) {
838 $this->smtp->Close();
850 function SetLanguage($langcode =
'en', $lang_path =
'language/') {
853 'provide_address' =>
'You must provide at least one recipient email address.',
854 'mailer_not_supported' =>
' mailer is not supported.',
855 'execute' =>
'Could not execute: ',
856 'instantiate' =>
'Could not instantiate mail function.',
857 'authenticate' =>
'SMTP Error: Could not authenticate.',
858 'from_failed' =>
'The following From address failed: ',
859 'recipients_failed' =>
'SMTP Error: The following recipients failed: ',
860 'data_not_accepted' =>
'SMTP Error: Data not accepted.',
861 'connect_host' =>
'SMTP Error: Could not connect to SMTP host.',
862 'file_access' =>
'Could not access file: ',
863 'file_open' =>
'File Error: Could not open file: ',
864 'encoding' =>
'Unknown encoding: ',
865 'signing' =>
'Signing Error: ',
866 'smtp_error' =>
'SMTP server error: ',
867 'empty_message' =>
'Message body empty',
868 'invalid_address' =>
'Invalid address',
869 'variable_set' =>
'Cannot set or reset variable: '
873 if ($langcode !=
'en') {
874 $l = @include $lang_path.
'phpmailer.lang-'.$langcode.
'.php';
898 $addr_str =
$type .
': ';
899 $addresses = array();
900 foreach ($addr as $a) {
903 $addr_str .= implode(
', ', $addresses);
915 if (empty($addr[1])) {
932 public function WrapText($message, $length, $qp_mode =
false) {
933 $soft_break = ($qp_mode) ? sprintf(
" =%s", $this->LE) :
$this->LE;
936 $is_utf8 = (strtolower($this->CharSet) ==
"utf-8");
938 $message = $this->FixEOL($message);
939 if (substr($message, -1) == $this->LE) {
940 $message = substr($message, 0, -1);
943 $line = explode($this->LE, $message);
945 for (
$i=0 ;
$i < count($line);
$i++) {
946 $line_part = explode(
' ', $line[
$i]);
948 for ($e = 0; $e<count($line_part); $e++) {
949 $word = $line_part[$e];
950 if ($qp_mode and (strlen($word) > $length)) {
951 $space_left = $length - strlen($buf) - 1;
953 if ($space_left > 20) {
957 } elseif (substr($word, $len - 1, 1) ==
"=") {
959 } elseif (substr($word, $len - 2, 1) ==
"=") {
962 $part = substr($word, 0, $len);
963 $word = substr($word, $len);
965 $message .= $buf . sprintf(
"=%s", $this->LE);
967 $message .= $buf . $soft_break;
971 while (strlen($word) > 0) {
975 } elseif (substr($word, $len - 1, 1) ==
"=") {
977 } elseif (substr($word, $len - 2, 1) ==
"=") {
980 $part = substr($word, 0, $len);
981 $word = substr($word, $len);
983 if (strlen($word) > 0) {
984 $message .= $part . sprintf(
"=%s", $this->LE);
991 $buf .= ($e == 0) ? $word : (
' ' . $word);
993 if (strlen($buf) > $length and $buf_o !=
'') {
994 $message .= $buf_o . $soft_break;
1015 $foundSplitPos =
false;
1017 while (!$foundSplitPos) {
1018 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
1019 $encodedCharPos = strpos($lastChunk,
"=");
1020 if ($encodedCharPos !==
false) {
1023 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
1024 $dec = hexdec($hex);
1028 $maxLength = ($encodedCharPos == 0) ? $maxLength :
1029 $maxLength - ($lookBack - $encodedCharPos);
1030 $foundSplitPos =
true;
1031 } elseif ($dec >= 192) {
1033 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1034 $foundSplitPos =
true;
1035 } elseif ($dec < 192) {
1040 $foundSplitPos =
true;
1053 if($this->WordWrap < 1) {
1057 switch($this->message_type) {
1059 case 'alt_attachments':
1060 $this->AltBody = $this->
WrapText($this->AltBody, $this->WordWrap);
1063 $this->Body = $this->
WrapText($this->Body, $this->WordWrap);
1077 $uniq_id = md5(uniqid(time()));
1078 $this->boundary[1] =
'b1_' . $uniq_id;
1079 $this->boundary[2] =
'b2_' . $uniq_id;
1082 if($this->Sender ==
'') {
1089 if($this->Mailer !=
'mail') {
1090 if ($this->SingleTo ===
true) {
1091 foreach($this->to as $t) {
1092 $this->SingleToArray[] = $this->
AddrFormat($t);
1095 if(count($this->to) > 0) {
1097 } elseif (count($this->cc) == 0) {
1104 $from[0][0] = trim($this->From);
1109 if(count($this->cc) > 0) {
1114 if((($this->Mailer ==
'sendmail') || ($this->Mailer ==
'mail')) && (count($this->bcc) > 0)) {
1118 if(count($this->ReplyTo) > 0) {
1123 if($this->Mailer !=
'mail') {
1127 if($this->MessageID !=
'') {
1130 $result .= sprintf(
"Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
1133 $result .= $this->
HeaderLine(
'X-Mailer',
'PHPMailer '.$this->Version.
' (phpmailer.sourceforge.net)');
1135 if($this->ConfirmReadingTo !=
'') {
1136 $result .= $this->
HeaderLine(
'Disposition-Notification-To',
'<' . trim($this->ConfirmReadingTo) .
'>');
1140 for($index = 0; $index < count($this->CustomHeader); $index++) {
1143 if (!$this->sign_key_file) {
1158 switch($this->message_type) {
1161 $result .= sprintf(
"Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
1164 case 'alt_attachments':
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);
1169 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1174 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1178 if($this->Mailer !=
'mail') {
1179 $result .= $this->LE.$this->LE;
1193 if ($this->sign_key_file) {
1199 switch($this->message_type) {
1201 $body .= $this->GetBoundary($this->boundary[1],
'',
'text/plain',
'');
1202 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1203 $body .= $this->LE.$this->LE;
1204 $body .= $this->GetBoundary($this->boundary[1],
'',
'text/html',
'');
1205 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1206 $body .= $this->LE.$this->LE;
1207 $body .= $this->EndBoundary($this->boundary[1]);
1210 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1213 $body .= $this->GetBoundary($this->boundary[1],
'',
'',
'');
1214 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1216 $body .= $this->AttachAll();
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;
1222 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1223 $body .= $this->LE.$this->LE;
1224 $body .= $this->GetBoundary($this->boundary[2],
'',
'text/html',
'') .
$this->LE;
1225 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1226 $body .= $this->LE.$this->LE;
1227 $body .= $this->EndBoundary($this->boundary[2]);
1228 $body .= $this->AttachAll();
1234 } elseif ($this->sign_key_file) {
1236 $file = tempnam(
'',
'mail');
1237 file_put_contents($file, $body);
1238 $signed = tempnam(
"",
"signed");
1239 if (@openssl_pkcs7_sign($file, $signed,
"file://".$this->sign_cert_file, array(
"file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
1242 $body = file_get_contents($signed);
1250 if ($this->exceptions) {
1263 private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1265 if($charSet ==
'') {
1268 if($contentType ==
'') {
1271 if($encoding ==
'') {
1275 $result .= sprintf(
"Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1287 private function EndBoundary($boundary) {
1288 return $this->LE .
'--' . $boundary .
'--' .
$this->LE;
1296 private function SetMessageType() {
1297 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1298 $this->message_type =
'plain';
1300 if(count($this->attachment) > 0) {
1301 $this->message_type =
'attachments';
1303 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1304 $this->message_type =
'alt';
1306 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1307 $this->message_type =
'alt_attachments';
1346 if ( !@is_file($path) ) {
1347 throw new phpmailerException($this->Lang(
'file_access') . $path, self::STOP_CONTINUE);
1349 $filename = basename($path);
1350 if (
$name ==
'' ) {
1354 $this->attachment[] = array(
1367 if ($this->exceptions) {
1370 echo $e->getMessage().
"\n";
1371 if ( $e->getCode() == self::STOP_CRITICAL ) {
1383 return $this->attachment;
1392 private function AttachAll() {
1399 foreach ($this->attachment as $attachment) {
1401 $bString = $attachment[5];
1403 $string = $attachment[0];
1405 $path = $attachment[0];
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;
1419 $mime[] = sprintf(
"--%s%s", $this->boundary[1], $this->LE);
1421 $mime[] = sprintf(
"Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1423 if($disposition ==
'inline') {
1424 $mime[] = sprintf(
"Content-ID: <%s>%s", $cid, $this->LE);
1427 $mime[] = sprintf(
"Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->
EncodeHeader($this->
SecureHeader(
$name)), $this->LE.$this->LE);
1435 $mime[] = $this->LE.$this->LE;
1437 $mime[] = $this->EncodeFile($path, $encoding);
1441 $mime[] = $this->LE.$this->LE;
1445 $mime[] = sprintf(
"--%s--%s", $this->boundary[1], $this->LE);
1447 return join(
'', $mime);
1459 private function EncodeFile($path, $encoding =
'base64') {
1461 if (!is_readable($path)) {
1464 if (function_exists(
'get_magic_quotes')) {
1465 function get_magic_quotes() {
1469 if (PHP_VERSION < 6) {
1470 $magic_quotes = get_magic_quotes_runtime();
1471 set_magic_quotes_runtime(0);
1473 $file_buffer = file_get_contents($path);
1474 $file_buffer = $this->
EncodeString($file_buffer, $encoding);
1475 if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
1476 return $file_buffer;
1477 }
catch (Exception $e) {
1493 switch(strtolower($encoding)) {
1495 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1499 $encoded = $this->FixEOL($str);
1501 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1507 case 'quoted-printable':
1511 $this->
SetError($this->Lang(
'encoding') . $encoding);
1525 switch (strtolower($position)) {
1527 if (!preg_match(
'/[\200-\377]/', $str)) {
1529 $encoded = addcslashes($str,
"\0..\37\177\\\"");
1530 if (($str == $encoded) && !preg_match(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1533 return (
"\"$encoded\"");
1536 $x = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $str, $matches);
1539 $x = preg_match_all(
'/[()"]/', $str, $matches);
1543 $x += preg_match_all(
'/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1551 $maxlen = 75 - 7 - strlen($this->CharSet);
1553 if (strlen($str)/3 < $x) {
1555 if (function_exists(
'mb_strlen') && $this->
HasMultiBytes($str)) {
1560 $encoded = base64_encode($str);
1561 $maxlen -= $maxlen % 4;
1562 $encoded = trim(chunk_split($encoded, $maxlen,
"\n"));
1566 $encoded = $this->
EncodeQ($str, $position);
1567 $encoded = $this->
WrapText($encoded, $maxlen,
true);
1568 $encoded = str_replace(
'='.$this->LE,
"\n", trim($encoded));
1571 $encoded = preg_replace(
'/^(.*)$/m',
" =?".$this->CharSet.
"?$encoding?\\1?=", $encoded);
1572 $encoded = trim(str_replace(
"\n", $this->LE, $encoded));
1584 if (function_exists(
'mb_strlen')) {
1585 return (strlen($str) > mb_strlen($str, $this->CharSet));
1600 $start =
"=?".$this->CharSet.
"?B?";
1604 $mb_length = mb_strlen($str, $this->CharSet);
1606 $length = 75 - strlen($start) - strlen($end);
1608 $ratio = $mb_length / strlen($str);
1610 $offset = $avgLength = floor($length * $ratio * .75);
1612 for (
$i = 0;
$i < $mb_length;
$i += $offset) {
1616 $offset = $avgLength - $lookBack;
1617 $chunk = mb_substr($str,
$i, $offset, $this->CharSet);
1618 $chunk = base64_encode($chunk);
1621 while (strlen($chunk) > $length);
1627 $encoded = substr($encoded, 0, -strlen($this->LE));
1639 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');
1641 $lines = preg_split(
'/(?:\r\n|\r|\n)/', $input);
1645 while( list(, $line) = each($lines) ) {
1646 $linlen = strlen($line);
1648 for(
$i = 0;
$i < $linlen;
$i++) {
1649 $c = substr( $line,
$i, 1 );
1651 if ( (
$i == 0 ) && ( $dec == 46 ) ) {
1655 if (
$i == ( $linlen - 1 ) ) {
1657 }
else if ( $space_conv ) {
1660 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
1661 $h2 = floor($dec/16);
1662 $h1 = floor($dec%16);
1663 $c = $escape.$hex[$h2].$hex[$h1];
1665 if ( (strlen($newline) + strlen($c)) >= $line_max ) {
1666 $output .= $newline.$escape.$eol;
1675 $output .= $newline.$eol;
1692 public function EncodeQP($string, $line_max = 76, $space_conv =
false) {
1693 if (function_exists(
'quoted_printable_encode')) {
1694 return quoted_printable_encode($string);
1696 $filters = stream_get_filters();
1697 if (!in_array(
'convert.*', $filters)) {
1698 return $this->
EncodeQPphp($string, $line_max, $space_conv);
1700 $fp = fopen(
'php://temp/',
'r+');
1701 $string = preg_replace(
'/\r\n?/', $this->LE, $string);
1702 $params = array(
'line-length' => $line_max,
'line-break-chars' => $this->LE);
1703 $s = stream_filter_append($fp,
'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
1704 fputs($fp, $string);
1706 $out = stream_get_contents($fp);
1707 stream_filter_remove($s);
1708 $out = preg_replace(
'/^\./m',
'=2E', $out);
1721 public function EncodeQ ($str, $position =
'text') {
1723 $encoded = preg_replace(
'/[\r\n]*/',
'', $str);
1725 switch (strtolower($position)) {
1727 $encoded = preg_replace(
"/([^A-Za-z0-9!*+\/ -])/e",
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1730 $encoded = preg_replace(
"/([\(\)\"])/e",
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1735 $encoded = preg_replace(
'/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1736 "'='.sprintf('%02X', ord('\\1'))", $encoded);
1741 $encoded = str_replace(
' ',
'_', $encoded);
1758 $this->attachment[] = array(
1761 2 => basename($filename),
1785 if ( !@is_file($path) ) {
1786 $this->
SetError($this->Lang(
'file_access') . $path);
1790 $filename = basename($path);
1791 if (
$name ==
'' ) {
1796 $this->attachment[] = array(
1816 foreach($this->attachment as $attachment) {
1817 if ($attachment[6] ==
'inline') {
1833 foreach($this->to as $to) {
1834 unset($this->all_recipients[strtolower($to[0])]);
1836 $this->to = array();
1844 foreach($this->cc as $cc) {
1845 unset($this->all_recipients[strtolower($cc[0])]);
1847 $this->cc = array();
1855 foreach($this->bcc as $bcc) {
1856 unset($this->all_recipients[strtolower($bcc[0])]);
1858 $this->bcc = array();
1866 $this->ReplyTo = array();
1875 $this->to = array();
1876 $this->cc = array();
1877 $this->bcc = array();
1878 $this->all_recipients = array();
1887 $this->attachment = array();
1895 $this->CustomHeader = array();
1908 $this->error_count++;
1909 if ($this->Mailer ==
'smtp' and !is_null($this->smtp)) {
1910 $lasterror = $this->smtp->getError();
1911 if (!empty($lasterror) and array_key_exists(
'smtp_msg', $lasterror)) {
1912 $msg .=
'<p>' . $this->Lang(
'smtp_error') . $lasterror[
'smtp_msg'] .
"</p>\n";
1915 $this->ErrorInfo = $msg;
1926 $tzs = ($tz < 0) ?
'-' :
'+';
1928 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1929 $result = sprintf(
"%s %s%04d", date(
'D, j M Y H:i:s'), $tzs, $tz);
1939 private function ServerHostname() {
1940 if (!empty($this->Hostname)) {
1942 } elseif (isset($_SERVER[
'SERVER_NAME'])) {
1943 $result = $_SERVER[
'SERVER_NAME'];
1945 $result =
'localhost.localdomain';
1956 private function Lang($key) {
1957 if(count($this->language) < 1) {
1961 if(isset($this->language[$key])) {
1962 return $this->language[$key];
1964 return 'Language string failed to load: ' . $key;
1974 return ($this->error_count > 0);
1982 private function FixEOL($str) {
1983 $str = str_replace(
"\r\n",
"\n", $str);
1984 $str = str_replace(
"\r",
"\n", $str);
1985 $str = str_replace(
"\n", $this->LE, $str);
1995 $this->CustomHeader[] = explode(
':', $custom_header, 2);
2003 public function MsgHTML($message, $basedir =
'') {
2004 preg_match_all(
"/(src|background)=\"(.*)\"/Ui", $message, $images);
2005 if(isset($images[2])) {
2006 foreach($images[2] as
$i => $url) {
2008 if (!preg_match(
'#^[A-z]+://#',$url)) {
2009 $filename = basename($url);
2010 $directory = dirname($url);
2011 ($directory ==
'.')?$directory=
'':
'';
2012 $cid =
'cid:' . md5($filename);
2013 $ext = pathinfo($filename, PATHINFO_EXTENSION);
2014 $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) ) {
2018 $message = preg_replace(
"/".$images[1][
$i].
"=\"".preg_quote($url,
'/').
"\"/Ui", $images[1][
$i].
"=\"".$cid.
"\"", $message);
2024 $this->Body = $message;
2025 $textMsg = trim(strip_tags(preg_replace(
'/<(head|title|style|script)[^>]*>.*?<\/\\1>/s',
'',$message)));
2026 if (!empty($textMsg) && empty($this->AltBody)) {
2027 $this->AltBody = html_entity_decode($textMsg);
2029 if (empty($this->AltBody)) {
2030 $this->AltBody =
'To view this email message, open it in a program that understands HTML!' .
"\n\n";
2043 'hqx' =>
'application/mac-binhex40',
2044 'cpt' =>
'application/mac-compactpro',
2045 'doc' =>
'application/msword',
2046 'bin' =>
'application/macbinary',
2047 'dms' =>
'application/octet-stream',
2048 'lha' =>
'application/octet-stream',
2049 'lzh' =>
'application/octet-stream',
2050 'exe' =>
'application/octet-stream',
2051 'class' =>
'application/octet-stream',
2052 'psd' =>
'application/octet-stream',
2053 'so' =>
'application/octet-stream',
2054 'sea' =>
'application/octet-stream',
2055 'dll' =>
'application/octet-stream',
2056 'oda' =>
'application/oda',
2057 'pdf' =>
'application/pdf',
2058 'ai' =>
'application/postscript',
2059 'eps' =>
'application/postscript',
2060 'ps' =>
'application/postscript',
2061 'smi' =>
'application/smil',
2062 'smil' =>
'application/smil',
2063 'mif' =>
'application/vnd.mif',
2064 'xls' =>
'application/vnd.ms-excel',
2065 'ppt' =>
'application/vnd.ms-powerpoint',
2066 'wbxml' =>
'application/vnd.wap.wbxml',
2067 'wmlc' =>
'application/vnd.wap.wmlc',
2068 'dcr' =>
'application/x-director',
2069 'dir' =>
'application/x-director',
2070 'dxr' =>
'application/x-director',
2071 'dvi' =>
'application/x-dvi',
2072 'gtar' =>
'application/x-gtar',
2073 'php' =>
'application/x-httpd-php',
2074 'php4' =>
'application/x-httpd-php',
2075 'php3' =>
'application/x-httpd-php',
2076 'phtml' =>
'application/x-httpd-php',
2077 'phps' =>
'application/x-httpd-php-source',
2078 'js' =>
'application/x-javascript',
2079 'swf' =>
'application/x-shockwave-flash',
2080 'sit' =>
'application/x-stuffit',
2081 'tar' =>
'application/x-tar',
2082 'tgz' =>
'application/x-tar',
2083 'xhtml' =>
'application/xhtml+xml',
2084 'xht' =>
'application/xhtml+xml',
2085 'zip' =>
'application/zip',
2086 'mid' =>
'audio/midi',
2087 'midi' =>
'audio/midi',
2088 'mpga' =>
'audio/mpeg',
2089 'mp2' =>
'audio/mpeg',
2090 'mp3' =>
'audio/mpeg',
2091 'aif' =>
'audio/x-aiff',
2092 'aiff' =>
'audio/x-aiff',
2093 'aifc' =>
'audio/x-aiff',
2094 'ram' =>
'audio/x-pn-realaudio',
2095 'rm' =>
'audio/x-pn-realaudio',
2096 'rpm' =>
'audio/x-pn-realaudio-plugin',
2097 'ra' =>
'audio/x-realaudio',
2098 'rv' =>
'video/vnd.rn-realvideo',
2099 'wav' =>
'audio/x-wav',
2100 'bmp' =>
'image/bmp',
2101 'gif' =>
'image/gif',
2102 'jpeg' =>
'image/jpeg',
2103 'jpg' =>
'image/jpeg',
2104 'jpe' =>
'image/jpeg',
2105 'png' =>
'image/png',
2106 'tiff' =>
'image/tiff',
2107 'tif' =>
'image/tiff',
2108 'css' =>
'text/css',
2109 'html' =>
'text/html',
2110 'htm' =>
'text/html',
2111 'shtml' =>
'text/html',
2112 'txt' =>
'text/plain',
2113 'text' =>
'text/plain',
2114 'log' =>
'text/plain',
2115 'rtx' =>
'text/richtext',
2116 'rtf' =>
'text/rtf',
2117 'xml' =>
'text/xml',
2118 'xsl' =>
'text/xml',
2119 'mpeg' =>
'video/mpeg',
2120 'mpg' =>
'video/mpeg',
2121 'mpe' =>
'video/mpeg',
2122 'qt' =>
'video/quicktime',
2123 'mov' =>
'video/quicktime',
2124 'avi' =>
'video/x-msvideo',
2125 'movie' =>
'video/x-sgi-movie',
2126 'doc' =>
'application/msword',
2127 'word' =>
'application/msword',
2128 'xl' =>
'application/excel',
2129 'eml' =>
'message/rfc822'
2131 return (!isset($mimes[strtolower($ext)])) ?
'application/octet-stream' : $mimes[strtolower($ext)];
2148 if (isset($this->
$name) ) {
2149 $this->
$name = $value;
2153 }
catch (Exception $e) {
2155 if ($e->getCode() == self::STOP_CRITICAL) {
2169 $str = str_replace(
"\r",
'', $str);
2170 $str = str_replace(
"\n",
'', $str);
2181 public function Sign($cert_filename, $key_filename, $key_pass) {
2182 $this->sign_cert_file = $cert_filename;
2183 $this->sign_key_file = $key_filename;
2184 $this->sign_key_pass = $key_pass;
2197 for (
$i=0;
$i<strlen($txt);
$i++) {
2199 if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
2202 $line.=
"=".sprintf(
"%02X",$ord);
2215 $privKeyStr = file_get_contents($this->DKIM_private);
2216 if ($this->DKIM_passphrase!=
'') {
2217 $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
2219 $privKey = $privKeyStr;
2221 if (openssl_sign($s, $signature, $privKey)) {
2222 return base64_encode($signature);
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) ;
2239 $lines[$key]=$heading.
":".trim($value) ;
2241 $s=implode(
"\r\n",$lines);
2252 if ($body ==
'')
return "\r\n";
2254 $body=str_replace(
"\r\n",
"\n",$body);
2255 $body=str_replace(
"\n",
"\r\n",$body);
2257 while (substr($body,strlen($body)-4,4) ==
"\r\n\r\n") {
2258 $body=substr($body,0,strlen($body)-2);
2271 public function DKIM_Add($headers_line,$subject,$body) {
2272 $DKIMsignatureType =
'rsa-sha1';
2273 $DKIMcanonicalization =
'relaxed/simple';
2274 $DKIMquery =
'dns/txt';
2275 $DKIMtime = time() ;
2276 $subject_header =
"Subject: $subject";
2277 $headers = explode(
"\r\n",$headers_line);
2278 foreach($headers as $header) {
2279 if (strpos($header,
'From:') === 0) {
2280 $from_header=$header;
2281 } elseif (strpos($header,
'To:') === 0) {
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)) ;
2289 $DKIMlen = strlen($body) ;
2290 $DKIMb64 = base64_encode(pack(
"H*", sha1($body))) ;
2291 $ident = ($this->DKIM_identity ==
'')?
'' :
" i=" . $this->DKIM_identity .
";";
2292 $dkimhdrs =
"DKIM-Signature: v=1; a=" . $DKIMsignatureType .
"; q=" . $DKIMquery .
"; l=" . $DKIMlen .
"; s=" . $this->DKIM_selector .
";\r\n".
2293 "\tt=" . $DKIMtime .
"; c=" . $DKIMcanonicalization .
";\r\n".
2294 "\th=From:To:Subject;\r\n".
2295 "\td=" . $this->DKIM_domain .
";" . $ident .
"\r\n".
2299 "\tbh=" . $DKIMb64 .
";\r\n".
2301 $toSign = $this->
DKIM_HeaderC($from_header .
"\r\n" . $to_header .
"\r\n" . $subject_header .
"\r\n" . $dkimhdrs);
2303 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed.
"\r\n";
2306 protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
2307 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);
2316 $errorMsg =
'<strong>' . $this->getMessage() .
"</strong><br />\n";