38 if (version_compare(PHP_VERSION,
'5.0.0',
'<') )
exit(
"Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
81 public $From =
'root@localhost';
383 $this->ContentType =
'text/html';
385 $this->ContentType =
'text/plain';
394 $this->Mailer =
'smtp';
402 $this->Mailer =
'mail';
410 if (!stristr(ini_get(
'sendmail_path'),
'sendmail')) {
411 $this->Sendmail =
'/var/qmail/bin/sendmail';
413 $this->Mailer =
'sendmail';
421 if (stristr(ini_get(
'sendmail_path'),
'qmail')) {
422 $this->Sendmail =
'/var/qmail/bin/sendmail';
424 $this->Mailer =
'sendmail';
448 public function AddCC($address, $name =
'') {
459 public function AddBCC($address, $name =
'') {
470 return $this->
AddAnAddress(
'Reply-To', $address, $name);
483 if (!preg_match(
'/^(to|cc|bcc|Reply-To)$/', $kind)) {
484 $this->
SetError($this->
Lang(
'Invalid recipient array').
': '.$kind);
485 if ($this->exceptions) {
488 if ($this->SMTPDebug) {
489 echo $this->
Lang(
'Invalid recipient array').
': '.$kind;
493 $address = trim($address);
494 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
495 if (!self::ValidateAddress($address)) {
496 $this->
SetError($this->
Lang(
'invalid_address').
': '. $address);
497 if ($this->exceptions) {
500 if ($this->SMTPDebug) {
501 echo $this->
Lang(
'invalid_address').
': '.$address;
505 if ($kind !=
'Reply-To') {
506 if (!isset($this->all_recipients[strtolower($address)])) {
507 array_push($this->$kind, array($address, $name));
508 $this->all_recipients[strtolower($address)] =
true;
512 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
513 $this->ReplyTo[strtolower($address)] = array($address, $name);
526 public function SetFrom($address, $name =
'', $auto = 1) {
527 $address = trim($address);
528 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
529 if (!self::ValidateAddress($address)) {
530 $this->
SetError($this->
Lang(
'invalid_address').
': '. $address);
531 if ($this->exceptions) {
534 if ($this->SMTPDebug) {
535 echo $this->
Lang(
'invalid_address').
': '.$address;
539 $this->From = $address;
540 $this->FromName = $name;
542 if (empty($this->ReplyTo)) {
545 if (empty($this->Sender)) {
546 $this->Sender = $address;
564 if (function_exists(
'filter_var')) {
565 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
571 return preg_match(
'/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
587 if(!$this->
PreSend())
return false;
590 $this->SentMIMEMessage =
'';
592 if ($this->exceptions) {
602 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
607 if(!empty($this->AltBody)) {
608 $this->ContentType =
'multipart/alternative';
611 $this->error_count = 0;
614 if (empty($this->Body)) {
623 if ($this->Mailer ==
'mail') {
624 if (count($this->to) > 0) {
625 $mailHeader .= $this->
AddrAppend(
"To", $this->to);
627 $mailHeader .= $this->
HeaderLine(
"To",
"undisclosed-recipients:;");
636 if ($this->DKIM_domain && $this->DKIM_private) {
641 $this->SentMIMEMessage = sprintf(
"%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
646 if ($this->exceptions) {
656 switch($this->Mailer) {
658 return $this->
SendmailSend($this->MIMEHeader, $this->MIMEBody);
660 return $this->
SmtpSend($this->MIMEHeader, $this->MIMEBody);
662 return $this->
MailSend($this->MIMEHeader, $this->MIMEBody);
664 return $this->
MailSend($this->MIMEHeader, $this->MIMEBody);
669 if ($this->exceptions) {
672 if ($this->SMTPDebug) {
673 echo $e->getMessage().
"\n";
687 if ($this->Sender !=
'') {
688 $sendmail = sprintf(
"%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
690 $sendmail = sprintf(
"%s -oi -t", escapeshellcmd($this->Sendmail));
692 if ($this->SingleTo ===
true) {
693 foreach ($this->SingleToArray as $key => $val) {
694 if(!@$mail = popen($sendmail,
'w')) {
697 fputs($mail,
"To: " . $val .
"\n");
698 fputs($mail, $header);
702 $isSent = (
$result == 0) ? 1 : 0;
703 $this->
doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
709 if(!@$mail = popen($sendmail,
'w')) {
712 fputs($mail, $header);
716 $isSent = (
$result == 0) ? 1 : 0;
717 $this->
doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
734 foreach($this->to as $t) {
737 $to = implode(
', ', $toArr);
739 if (empty($this->Sender)) {
742 $params = sprintf(
"-oi -f %s", $this->Sender);
744 if ($this->Sender !=
'' and !ini_get(
'safe_mode')) {
745 $old_from = ini_get(
'sendmail_from');
746 ini_set(
'sendmail_from', $this->Sender);
747 if ($this->SingleTo ===
true && count($toArr) > 1) {
748 foreach ($toArr as $key => $val) {
751 $isSent = ($rt == 1) ? 1 : 0;
752 $this->
doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
757 $isSent = ($rt == 1) ? 1 : 0;
758 $this->
doCallback($isSent,
$to, $this->cc, $this->bcc, $this->Subject, $body);
761 if ($this->SingleTo ===
true && count($toArr) > 1) {
762 foreach ($toArr as $key => $val) {
765 $isSent = ($rt == 1) ? 1 : 0;
766 $this->
doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
771 $isSent = ($rt == 1) ? 1 : 0;
772 $this->
doCallback($isSent,
$to, $this->cc, $this->bcc, $this->Subject, $body);
775 if (isset($old_from)) {
776 ini_set(
'sendmail_from', $old_from);
794 require_once $this->PluginDir .
'class.smtp.php';
800 $smtp_from = ($this->Sender ==
'') ? $this->From : $this->Sender;
801 if(!$this->smtp->Mail($smtp_from)) {
806 foreach($this->to as
$to) {
807 if (!$this->smtp->Recipient($to[0])) {
808 $bad_rcpt[] = $to[0];
811 $this->
doCallback($isSent, $to[0],
'',
'', $this->Subject, $body);
815 $this->
doCallback($isSent, $to[0],
'',
'', $this->Subject, $body);
818 foreach($this->cc as
$cc) {
819 if (!$this->smtp->Recipient($cc[0])) {
820 $bad_rcpt[] = $cc[0];
823 $this->
doCallback($isSent,
'', $cc[0],
'', $this->Subject, $body);
827 $this->
doCallback($isSent,
'', $cc[0],
'', $this->Subject, $body);
830 foreach($this->bcc as
$bcc) {
831 if (!$this->smtp->Recipient($bcc[0])) {
832 $bad_rcpt[] = $bcc[0];
835 $this->
doCallback($isSent,
'',
'', $bcc[0], $this->Subject, $body);
839 $this->
doCallback($isSent,
'',
'', $bcc[0], $this->Subject, $body);
844 if (count($bad_rcpt) > 0 ) {
845 $badaddresses = implode(
', ', $bad_rcpt);
848 if(!$this->smtp->Data($header . $body)) {
851 if($this->SMTPKeepAlive ==
true) {
852 $this->smtp->Reset();
865 if(is_null($this->smtp)) {
866 $this->smtp =
new SMTP();
870 $hosts = explode(
';', $this->Host);
872 $connection = $this->smtp->Connected();
876 while(
$index < count($hosts) && !$connection) {
878 if (preg_match(
'/^(.+):([0-9]+)$/', $hosts[
$index], $hostinfo)) {
879 $host = $hostinfo[1];
880 $port = $hostinfo[2];
886 $tls = ($this->SMTPSecure ==
'tls');
887 $ssl = ($this->SMTPSecure ==
'ssl');
889 if ($this->smtp->Connect(($ssl ?
'ssl://':
'').$host, $port, $this->Timeout)) {
891 $hello = ($this->Helo !=
'' ? $this->Helo : $this->
ServerHostname());
892 $this->smtp->Hello($hello);
895 if (!$this->smtp->StartTLS()) {
900 $this->smtp->Hello($hello);
904 if ($this->SMTPAuth) {
905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
916 $this->smtp->Reset();
917 if ($this->exceptions) {
929 if(!is_null($this->smtp)) {
930 if($this->smtp->Connected()) {
932 $this->smtp->Close();
944 function SetLanguage($langcode =
'en', $lang_path =
'language/') {
947 'provide_address' =>
'You must provide at least one recipient email address.',
948 'mailer_not_supported' =>
' mailer is not supported.',
949 'execute' =>
'Could not execute: ',
950 'instantiate' =>
'Could not instantiate mail function.',
951 'authenticate' =>
'SMTP Error: Could not authenticate.',
952 'from_failed' =>
'The following From address failed: ',
953 'recipients_failed' =>
'SMTP Error: The following recipients failed: ',
954 'data_not_accepted' =>
'SMTP Error: Data not accepted.',
955 'connect_host' =>
'SMTP Error: Could not connect to SMTP host.',
956 'file_access' =>
'Could not access file: ',
957 'file_open' =>
'File Error: Could not open file: ',
958 'encoding' =>
'Unknown encoding: ',
959 'signing' =>
'Signing Error: ',
960 'smtp_error' =>
'SMTP server error: ',
961 'empty_message' =>
'Message body empty',
962 'invalid_address' =>
'Invalid address',
963 'variable_set' =>
'Cannot set or reset variable: '
967 if ($langcode !=
'en') {
968 $l = @include $lang_path.
'phpmailer.lang-'.$langcode.
'.php';
992 $addr_str =
$type .
': ';
993 $addresses = array();
994 foreach ($addr as $a) {
997 $addr_str .= implode(
', ', $addresses);
1009 if (empty($addr[1])) {
1026 public function WrapText($message, $length, $qp_mode =
false) {
1027 $soft_break = ($qp_mode) ? sprintf(
" =%s", $this->LE) :
$this->LE;
1030 $is_utf8 = (strtolower($this->CharSet) ==
"utf-8");
1032 $message = $this->
FixEOL($message);
1033 if (substr($message, -1) == $this->LE) {
1034 $message = substr($message, 0, -1);
1037 $line = explode($this->LE, $message);
1039 for (
$i = 0 ;
$i < count($line);
$i++) {
1040 $line_part = explode(
' ', $line[
$i]);
1042 for ($e = 0; $e<count($line_part); $e++) {
1043 $word = $line_part[$e];
1044 if ($qp_mode and (strlen($word) > $length)) {
1045 $space_left = $length - strlen($buf) - 1;
1047 if ($space_left > 20) {
1051 } elseif (substr($word, $len - 1, 1) ==
"=") {
1053 } elseif (substr($word, $len - 2, 1) ==
"=") {
1056 $part = substr($word, 0, $len);
1057 $word = substr($word, $len);
1058 $buf .=
' ' . $part;
1059 $message .= $buf . sprintf(
"=%s", $this->LE);
1061 $message .= $buf . $soft_break;
1065 while (strlen($word) > 0) {
1069 } elseif (substr($word, $len - 1, 1) ==
"=") {
1071 } elseif (substr($word, $len - 2, 1) ==
"=") {
1074 $part = substr($word, 0, $len);
1075 $word = substr($word, $len);
1077 if (strlen($word) > 0) {
1078 $message .= $part . sprintf(
"=%s", $this->LE);
1085 $buf .= ($e == 0) ? $word : (
' ' . $word);
1087 if (strlen($buf) > $length and $buf_o !=
'') {
1088 $message .= $buf_o . $soft_break;
1109 $foundSplitPos =
false;
1111 while (!$foundSplitPos) {
1112 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
1113 $encodedCharPos = strpos($lastChunk,
"=");
1114 if ($encodedCharPos !==
false) {
1117 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
1118 $dec = hexdec($hex);
1122 $maxLength = ($encodedCharPos == 0) ? $maxLength :
1123 $maxLength - ($lookBack - $encodedCharPos);
1124 $foundSplitPos =
true;
1125 } elseif ($dec >= 192) {
1127 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1128 $foundSplitPos =
true;
1129 } elseif ($dec < 192) {
1134 $foundSplitPos =
true;
1147 if($this->WordWrap < 1) {
1151 switch($this->message_type) {
1155 case 'alt_inline_attach':
1156 $this->AltBody = $this->
WrapText($this->AltBody, $this->WordWrap);
1159 $this->Body = $this->
WrapText($this->Body, $this->WordWrap);
1173 $uniq_id = md5(uniqid(time()));
1174 $this->boundary[1] =
'b1_' . $uniq_id;
1175 $this->boundary[2] =
'b2_' . $uniq_id;
1176 $this->boundary[3] =
'b3_' . $uniq_id;
1179 if($this->Sender ==
'') {
1186 if($this->Mailer !=
'mail') {
1187 if ($this->SingleTo ===
true) {
1188 foreach($this->to as $t) {
1189 $this->SingleToArray[] = $this->
AddrFormat($t);
1192 if(count($this->to) > 0) {
1194 } elseif (count($this->cc) == 0) {
1201 $from[0][0] = trim($this->From);
1206 if(count($this->cc) > 0) {
1211 if((($this->Mailer ==
'sendmail') || ($this->Mailer ==
'mail')) && (count($this->bcc) > 0)) {
1215 if(count($this->ReplyTo) > 0) {
1220 if($this->Mailer !=
'mail') {
1224 if($this->MessageID !=
'') {
1230 if($this->XMailer) {
1233 $result .= $this->
HeaderLine(
'X-Mailer',
'PHPMailer '.$this->Version.
' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
1236 if($this->ConfirmReadingTo !=
'') {
1237 $result .= $this->
HeaderLine(
'Disposition-Notification-To',
'<' . trim($this->ConfirmReadingTo) .
'>');
1244 if (!$this->sign_key_file) {
1259 switch($this->message_type) {
1262 $result .= $this->
TextLine(
'Content-Type: '.$this->ContentType.
'; charset="'.$this->CharSet.
'"');
1266 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1269 case 'inline_attach':
1271 case 'alt_inline_attach':
1273 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1278 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
1282 if($this->Mailer !=
'mail') {
1283 $result .= $this->LE.$this->LE;
1307 if ($this->sign_key_file) {
1313 switch($this->message_type) {
1315 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1318 $body .= $this->
GetBoundary($this->boundary[1],
'',
'',
'');
1319 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1320 $body .= $this->LE.$this->LE;
1321 $body .= $this->
AttachAll(
"inline", $this->boundary[1]);
1324 $body .= $this->
GetBoundary($this->boundary[1],
'',
'',
'');
1325 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1326 $body .= $this->LE.$this->LE;
1327 $body .= $this->
AttachAll(
"attachment", $this->boundary[1]);
1329 case 'inline_attach':
1330 $body .= $this->
TextLine(
"--" . $this->boundary[1]);
1331 $body .= $this->
HeaderLine(
'Content-Type',
'multipart/related;');
1332 $body .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
1334 $body .= $this->
GetBoundary($this->boundary[2],
'',
'',
'');
1335 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1336 $body .= $this->LE.$this->LE;
1337 $body .= $this->
AttachAll(
"inline", $this->boundary[2]);
1339 $body .= $this->
AttachAll(
"attachment", $this->boundary[1]);
1342 $body .= $this->
GetBoundary($this->boundary[1],
'',
'text/plain',
'');
1343 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1344 $body .= $this->LE.$this->LE;
1345 $body .= $this->
GetBoundary($this->boundary[1],
'',
'text/html',
'');
1346 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1347 $body .= $this->LE.$this->LE;
1351 $body .= $this->
GetBoundary($this->boundary[1],
'',
'text/plain',
'');
1352 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1353 $body .= $this->LE.$this->LE;
1354 $body .= $this->
TextLine(
"--" . $this->boundary[1]);
1355 $body .= $this->
HeaderLine(
'Content-Type',
'multipart/related;');
1356 $body .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
1358 $body .= $this->
GetBoundary($this->boundary[2],
'',
'text/html',
'');
1359 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1360 $body .= $this->LE.$this->LE;
1361 $body .= $this->
AttachAll(
"inline", $this->boundary[2]);
1366 $body .= $this->
TextLine(
"--" . $this->boundary[1]);
1367 $body .= $this->
HeaderLine(
'Content-Type',
'multipart/alternative;');
1368 $body .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
1370 $body .= $this->
GetBoundary($this->boundary[2],
'',
'text/plain',
'');
1371 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1372 $body .= $this->LE.$this->LE;
1373 $body .= $this->
GetBoundary($this->boundary[2],
'',
'text/html',
'');
1374 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1375 $body .= $this->LE.$this->LE;
1378 $body .= $this->
AttachAll(
"attachment", $this->boundary[1]);
1380 case 'alt_inline_attach':
1381 $body .= $this->
TextLine(
"--" . $this->boundary[1]);
1382 $body .= $this->
HeaderLine(
'Content-Type',
'multipart/alternative;');
1383 $body .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
1385 $body .= $this->
GetBoundary($this->boundary[2],
'',
'text/plain',
'');
1386 $body .= $this->
EncodeString($this->AltBody, $this->Encoding);
1387 $body .= $this->LE.$this->LE;
1388 $body .= $this->
TextLine(
"--" . $this->boundary[2]);
1389 $body .= $this->
HeaderLine(
'Content-Type',
'multipart/related;');
1390 $body .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[3] .
'"');
1392 $body .= $this->
GetBoundary($this->boundary[3],
'',
'text/html',
'');
1393 $body .= $this->
EncodeString($this->Body, $this->Encoding);
1394 $body .= $this->LE.$this->LE;
1395 $body .= $this->
AttachAll(
"inline", $this->boundary[3]);
1399 $body .= $this->
AttachAll(
"attachment", $this->boundary[1]);
1405 } elseif ($this->sign_key_file) {
1407 $file = tempnam(
'',
'mail');
1408 file_put_contents(
$file, $body);
1409 $signed = tempnam(
"",
"signed");
1410 if (@openssl_pkcs7_sign(
$file, $signed,
"file://".$this->sign_cert_file, array(
"file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
1412 $body = file_get_contents($signed);
1421 if ($this->exceptions) {
1437 if($charSet ==
'') {
1440 if($contentType ==
'') {
1443 if($encoding ==
'') {
1447 $result .= sprintf(
"Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
1470 $this->message_type = array();
1474 $this->message_type = implode(
"_", $this->message_type);
1475 if($this->message_type ==
"") $this->message_type =
"plain";
1484 return $name .
': ' . $value .
$this->LE;
1512 if ( !@is_file(
$path) ) {
1515 $filename = basename(
$path);
1516 if ( $name ==
'' ) {
1520 $this->attachment[] = array(
1533 if ($this->exceptions) {
1536 if ($this->SMTPDebug) {
1537 echo $e->getMessage().
"\n";
1539 if ( $e->getCode() == self::STOP_CRITICAL ) {
1569 if($attachment[6] == $disposition_type) {
1571 $bString = $attachment[5];
1573 $string = $attachment[0];
1575 $path = $attachment[0];
1578 $inclhash = md5(serialize($attachment));
1579 if (in_array($inclhash, $incl)) {
continue; }
1580 $incl[] = $inclhash;
1581 $filename = $attachment[1];
1582 $name = $attachment[2];
1583 $encoding = $attachment[3];
1584 $type = $attachment[4];
1585 $disposition = $attachment[6];
1586 $cid = $attachment[7];
1587 if ( $disposition ==
'inline' && isset($cidUniq[$cid]) ) {
continue; }
1588 $cidUniq[$cid] =
true;
1590 $mime[] = sprintf(
"--%s%s",
$boundary, $this->LE);
1592 $mime[] = sprintf(
"Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1594 if($disposition ==
'inline') {
1595 $mime[] = sprintf(
"Content-ID: <%s>%s", $cid, $this->LE);
1598 $mime[] = sprintf(
"Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->
EncodeHeader($this->
SecureHeader($name)), $this->LE.$this->LE);
1606 $mime[] = $this->LE.$this->LE;
1612 $mime[] = $this->LE.$this->LE;
1617 $mime[] = sprintf(
"--%s--%s",
$boundary, $this->LE);
1619 return implode(
"", $mime);
1633 if (!is_readable(
$path)) {
1636 if (function_exists(
'get_magic_quotes')) {
1637 function get_magic_quotes() {
1641 $magic_quotes = get_magic_quotes_runtime();
1642 if ($magic_quotes) {
1643 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
1644 set_magic_quotes_runtime(0);
1646 ini_set(
'magic_quotes_runtime', 0);
1649 $file_buffer = file_get_contents(
$path);
1650 $file_buffer = $this->
EncodeString($file_buffer, $encoding);
1651 if ($magic_quotes) {
1652 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
1653 set_magic_quotes_runtime($magic_quotes);
1655 ini_set(
'magic_quotes_runtime', $magic_quotes);
1658 return $file_buffer;
1659 }
catch (Exception $e) {
1675 switch(strtolower($encoding)) {
1677 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1681 $encoded = $this->
FixEOL($str);
1683 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1689 case 'quoted-printable':
1707 switch (strtolower($position)) {
1709 if (!preg_match(
'/[\200-\377]/', $str)) {
1711 $encoded = addcslashes($str,
"\0..\37\177\\\"");
1712 if (($str == $encoded) && !preg_match(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1715 return (
"\"$encoded\"");
1718 $x = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $str, $matches);
1721 $x = preg_match_all(
'/[()"]/', $str, $matches);
1725 $x += preg_match_all(
'/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1733 $maxlen = 75 - 7 - strlen($this->CharSet);
1735 if (strlen($str)/3 < $x) {
1737 if (function_exists(
'mb_strlen') && $this->
HasMultiBytes($str)) {
1742 $encoded = base64_encode($str);
1743 $maxlen -= $maxlen % 4;
1744 $encoded = trim(chunk_split($encoded, $maxlen,
"\n"));
1748 $encoded = $this->
EncodeQ($str, $position);
1749 $encoded = $this->
WrapText($encoded, $maxlen,
true);
1750 $encoded = str_replace(
'='.$this->LE,
"\n", trim($encoded));
1753 $encoded = preg_replace(
'/^(.*)$/m',
" =?".$this->CharSet.
"?$encoding?\\1?=", $encoded);
1754 $encoded = trim(str_replace(
"\n", $this->LE, $encoded));
1766 if (function_exists(
'mb_strlen')) {
1767 return (strlen($str) > mb_strlen($str, $this->CharSet));
1782 $start =
"=?".$this->CharSet.
"?B?";
1786 $mb_length = mb_strlen($str, $this->CharSet);
1788 $length = 75 - strlen(
$start) - strlen($end);
1790 $ratio = $mb_length / strlen($str);
1792 $offset = $avgLength = floor($length * $ratio * .75);
1794 for (
$i = 0;
$i < $mb_length;
$i += $offset) {
1798 $offset = $avgLength - $lookBack;
1799 $chunk = mb_substr($str,
$i, $offset, $this->CharSet);
1800 $chunk = base64_encode($chunk);
1803 while (strlen($chunk) > $length);
1809 $encoded = substr($encoded, 0, -strlen($this->LE));
1821 public function EncodeQPphp( $input =
'', $line_max = 76, $space_conv =
false) {
1822 $hex = array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
1823 $lines = preg_split(
'/(?:\r\n|\r|\n)/', $input);
1827 while( list(, $line) = each($lines) ) {
1828 $linlen = strlen($line);
1830 for(
$i = 0;
$i < $linlen;
$i++) {
1831 $c = substr( $line,
$i, 1 );
1833 if ( (
$i == 0 ) && ( $dec == 46 ) ) {
1837 if (
$i == ( $linlen - 1 ) ) {
1839 }
else if ( $space_conv ) {
1842 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
1843 $h2 = floor($dec/16);
1844 $h1 = floor($dec%16);
1845 $c = $escape.$hex[$h2].$hex[$h1];
1847 if ( (strlen($newline) + strlen($c)) >= $line_max ) {
1848 $output .= $newline.$escape.$eol;
1857 $output .= $newline.$eol;
1874 public function EncodeQP($string, $line_max = 76, $space_conv =
false) {
1875 if (function_exists(
'quoted_printable_encode')) {
1876 return quoted_printable_encode($string);
1878 $filters = stream_get_filters();
1879 if (!in_array(
'convert.*', $filters)) {
1880 return $this->
EncodeQPphp($string, $line_max, $space_conv);
1882 $fp = fopen(
'php://temp/',
'r+');
1883 $string = preg_replace(
'/\r\n?/', $this->LE, $string);
1884 $params = array(
'line-length' => $line_max,
'line-break-chars' => $this->LE);
1885 $s = stream_filter_append($fp,
'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
1886 fputs($fp, $string);
1888 $out = stream_get_contents($fp);
1889 stream_filter_remove($s);
1890 $out = preg_replace(
'/^\./m',
'=2E', $out);
1903 public function EncodeQ($str, $position =
'text') {
1905 $encoded = preg_replace(
'/[\r\n]*/',
'', $str);
1907 switch (strtolower($position)) {
1909 $encoded = preg_replace(
"/([^A-Za-z0-9!*+\/ -])/e",
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1912 $encoded = preg_replace(
"/([\(\)\"])/e",
"'='.sprintf('%02X', ord('\\1'))", $encoded);
1917 $encoded = preg_replace(
'/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1918 "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
1923 $encoded = str_replace(
' ',
'_', $encoded);
1940 $this->attachment[] = array(
1943 2 => basename($filename),
1967 if ( !@is_file(
$path) ) {
1972 $filename = basename(
$path);
1973 if ( $name ==
'' ) {
1978 $this->attachment[] = array(
1994 $this->attachment[] = array(
1997 2 => basename($filename),
2013 if ($attachment[6] ==
'inline') {
2022 if ($attachment[6] ==
'attachment') {
2030 return strlen($this->AltBody)>0;
2042 foreach($this->to as
$to) {
2043 unset($this->all_recipients[strtolower($to[0])]);
2045 $this->to = array();
2053 foreach($this->cc as
$cc) {
2054 unset($this->all_recipients[strtolower($cc[0])]);
2056 $this->cc = array();
2064 foreach($this->bcc as
$bcc) {
2065 unset($this->all_recipients[strtolower($bcc[0])]);
2067 $this->bcc = array();
2075 $this->ReplyTo = array();
2084 $this->to = array();
2085 $this->cc = array();
2086 $this->bcc = array();
2087 $this->all_recipients = array();
2096 $this->attachment = array();
2104 $this->CustomHeader = array();
2117 $this->error_count++;
2118 if ($this->Mailer ==
'smtp' and !is_null($this->smtp)) {
2119 $lasterror = $this->smtp->getError();
2120 if (!empty($lasterror) and array_key_exists(
'smtp_msg', $lasterror)) {
2121 $msg .=
'<p>' . $this->
Lang(
'smtp_error') . $lasterror[
'smtp_msg'] .
"</p>\n";
2124 $this->ErrorInfo =
$msg;
2135 $tzs = ($tz < 0) ?
'-' :
'+';
2137 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
2138 $result = sprintf(
"%s %s%04d", date(
'D, j M Y H:i:s'), $tzs, $tz);
2149 if (!empty($this->Hostname)) {
2151 } elseif (isset(
$_SERVER[
'SERVER_NAME'])) {
2154 $result =
'localhost.localdomain';
2166 if(count($this->language) < 1) {
2170 if(isset($this->language[$key])) {
2171 return $this->language[$key];
2173 return 'Language string failed to load: ' . $key;
2183 return ($this->error_count > 0);
2192 $str = str_replace(
"\r\n",
"\n", $str);
2193 $str = str_replace(
"\r",
"\n", $str);
2194 $str = str_replace(
"\n", $this->LE, $str);
2204 $this->CustomHeader[] = explode(
':', $custom_header, 2);
2212 public function MsgHTML($message, $basedir =
'') {
2213 preg_match_all(
"/(src|background)=[\"'](.*)[\"']/Ui", $message, $images);
2214 if(isset($images[2])) {
2215 foreach($images[2] as
$i =>
$url) {
2217 if (!preg_match(
'#^[A-z]+://#',
$url)) {
2218 $filename = basename(
$url);
2219 $directory = dirname(
$url);
2220 ($directory ==
'.') ? $directory=
'':
'';
2221 $cid =
'cid:' . md5($filename);
2222 $ext = pathinfo($filename, PATHINFO_EXTENSION);
2223 $mimeType = self::_mime_types(
$ext);
2224 if ( strlen($basedir) > 1 && substr($basedir, -1) !=
'/') { $basedir .=
'/'; }
2225 if ( strlen($directory) > 1 && substr($directory, -1) !=
'/') { $directory .=
'/'; }
2226 if ( $this->
AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename,
'base64', $mimeType) ) {
2227 $message = preg_replace(
"/".$images[1][
$i].
"=[\"']".preg_quote(
$url,
'/').
"[\"']/Ui", $images[1][
$i].
"=\"".$cid.
"\"", $message);
2233 $this->Body = $message;
2234 if (empty($this->AltBody)) {
2235 $textMsg = trim(strip_tags(preg_replace(
'/<(head|title|style|script)[^>]*>.*?<\/\\1>/s',
'', $message)));
2236 if (!empty($textMsg)) {
2237 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
2240 if (empty($this->AltBody)) {
2241 $this->AltBody =
'To view this email message, open it in a program that understands HTML!' .
"\n\n";
2255 'hqx' =>
'application/mac-binhex40',
2256 'cpt' =>
'application/mac-compactpro',
2257 'doc' =>
'application/msword',
2258 'bin' =>
'application/macbinary',
2259 'dms' =>
'application/octet-stream',
2260 'lha' =>
'application/octet-stream',
2261 'lzh' =>
'application/octet-stream',
2262 'exe' =>
'application/octet-stream',
2263 'class' =>
'application/octet-stream',
2264 'psd' =>
'application/octet-stream',
2265 'so' =>
'application/octet-stream',
2266 'sea' =>
'application/octet-stream',
2267 'dll' =>
'application/octet-stream',
2268 'oda' =>
'application/oda',
2269 'pdf' =>
'application/pdf',
2270 'ai' =>
'application/postscript',
2271 'eps' =>
'application/postscript',
2272 'ps' =>
'application/postscript',
2273 'smi' =>
'application/smil',
2274 'smil' =>
'application/smil',
2275 'mif' =>
'application/vnd.mif',
2276 'xls' =>
'application/vnd.ms-excel',
2277 'ppt' =>
'application/vnd.ms-powerpoint',
2278 'wbxml' =>
'application/vnd.wap.wbxml',
2279 'wmlc' =>
'application/vnd.wap.wmlc',
2280 'dcr' =>
'application/x-director',
2281 'dir' =>
'application/x-director',
2282 'dxr' =>
'application/x-director',
2283 'dvi' =>
'application/x-dvi',
2284 'gtar' =>
'application/x-gtar',
2285 'php' =>
'application/x-httpd-php',
2286 'php4' =>
'application/x-httpd-php',
2287 'php3' =>
'application/x-httpd-php',
2288 'phtml' =>
'application/x-httpd-php',
2289 'phps' =>
'application/x-httpd-php-source',
2290 'js' =>
'application/x-javascript',
2291 'swf' =>
'application/x-shockwave-flash',
2292 'sit' =>
'application/x-stuffit',
2293 'tar' =>
'application/x-tar',
2294 'tgz' =>
'application/x-tar',
2295 'xhtml' =>
'application/xhtml+xml',
2296 'xht' =>
'application/xhtml+xml',
2297 'zip' =>
'application/zip',
2298 'mid' =>
'audio/midi',
2299 'midi' =>
'audio/midi',
2300 'mpga' =>
'audio/mpeg',
2301 'mp2' =>
'audio/mpeg',
2302 'mp3' =>
'audio/mpeg',
2303 'aif' =>
'audio/x-aiff',
2304 'aiff' =>
'audio/x-aiff',
2305 'aifc' =>
'audio/x-aiff',
2306 'ram' =>
'audio/x-pn-realaudio',
2307 'rm' =>
'audio/x-pn-realaudio',
2308 'rpm' =>
'audio/x-pn-realaudio-plugin',
2309 'ra' =>
'audio/x-realaudio',
2310 'rv' =>
'video/vnd.rn-realvideo',
2311 'wav' =>
'audio/x-wav',
2312 'bmp' =>
'image/bmp',
2313 'gif' =>
'image/gif',
2314 'jpeg' =>
'image/jpeg',
2315 'jpg' =>
'image/jpeg',
2316 'jpe' =>
'image/jpeg',
2317 'png' =>
'image/png',
2318 'tiff' =>
'image/tiff',
2319 'tif' =>
'image/tiff',
2320 'css' =>
'text/css',
2321 'html' =>
'text/html',
2322 'htm' =>
'text/html',
2323 'shtml' =>
'text/html',
2324 'txt' =>
'text/plain',
2325 'text' =>
'text/plain',
2326 'log' =>
'text/plain',
2327 'rtx' =>
'text/richtext',
2328 'rtf' =>
'text/rtf',
2329 'xml' =>
'text/xml',
2330 'xsl' =>
'text/xml',
2331 'mpeg' =>
'video/mpeg',
2332 'mpg' =>
'video/mpeg',
2333 'mpe' =>
'video/mpeg',
2334 'qt' =>
'video/quicktime',
2335 'mov' =>
'video/quicktime',
2336 'avi' =>
'video/x-msvideo',
2337 'movie' =>
'video/x-sgi-movie',
2338 'doc' =>
'application/msword',
2339 'word' =>
'application/msword',
2340 'xl' =>
'application/excel',
2341 'eml' =>
'message/rfc822'
2343 return (!isset($mimes[strtolower(
$ext)])) ?
'application/octet-stream' : $mimes[strtolower(
$ext)];
2358 public function set($name, $value =
'') {
2360 if (isset($this->$name) ) {
2361 $this->$name = $value;
2365 }
catch (Exception $e) {
2367 if ($e->getCode() == self::STOP_CRITICAL) {
2381 $str = str_replace(
"\r",
'', $str);
2382 $str = str_replace(
"\n",
'', $str);
2393 public function Sign($cert_filename, $key_filename, $key_pass) {
2394 $this->sign_cert_file = $cert_filename;
2395 $this->sign_key_file = $key_filename;
2396 $this->sign_key_pass = $key_pass;
2409 for (
$i = 0;
$i < strlen($txt);
$i++) {
2410 $ord = ord($txt[
$i]);
2411 if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
2414 $line .=
"=".sprintf(
"%02X", $ord);
2427 $privKeyStr = file_get_contents($this->DKIM_private);
2428 if ($this->DKIM_passphrase !=
'') {
2429 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
2431 $privKey = $privKeyStr;
2433 if (openssl_sign($s, $signature, $privKey)) {
2434 return base64_encode($signature);
2445 $s = preg_replace(
"/\r\n\s+/",
" ", $s);
2446 $lines = explode(
"\r\n", $s);
2447 foreach ($lines as $key => $line) {
2448 list($heading, $value) = explode(
":", $line, 2);
2449 $heading = strtolower($heading);
2450 $value = preg_replace(
"/\s+/",
" ", $value) ;
2451 $lines[$key] = $heading.
":".trim($value) ;
2453 $s = implode(
"\r\n", $lines);
2464 if ($body ==
'')
return "\r\n";
2466 $body = str_replace(
"\r\n",
"\n", $body);
2467 $body = str_replace(
"\n",
"\r\n", $body);
2469 while (substr($body, strlen($body) - 4, 4) ==
"\r\n\r\n") {
2470 $body = substr($body, 0, strlen($body) - 2);
2483 public function DKIM_Add($headers_line, $subject, $body) {
2484 $DKIMsignatureType =
'rsa-sha1';
2485 $DKIMcanonicalization =
'relaxed/simple';
2486 $DKIMquery =
'dns/txt';
2487 $DKIMtime = time() ;
2488 $subject_header =
"Subject: $subject";
2489 $headers = explode($this->LE, $headers_line);
2490 foreach($headers as $header) {
2491 if (strpos($header,
'From:') === 0) {
2492 $from_header = $header;
2493 } elseif (strpos($header,
'To:') === 0) {
2494 $to_header = $header;
2497 $from = str_replace(
'|',
'=7C', $this->
DKIM_QP($from_header));
2498 $to = str_replace(
'|',
'=7C', $this->
DKIM_QP($to_header));
2499 $subject = str_replace(
'|',
'=7C', $this->
DKIM_QP($subject_header)) ;
2501 $DKIMlen = strlen($body) ;
2502 $DKIMb64 = base64_encode(pack(
"H*", sha1($body))) ;
2503 $ident = ($this->DKIM_identity ==
'')?
'' :
" i=" . $this->DKIM_identity .
";";
2504 $dkimhdrs =
"DKIM-Signature: v=1; a=" . $DKIMsignatureType .
"; q=" . $DKIMquery .
"; l=" . $DKIMlen .
"; s=" . $this->DKIM_selector .
";\r\n".
2505 "\tt=" . $DKIMtime .
"; c=" . $DKIMcanonicalization .
";\r\n".
2506 "\th=From:To:Subject;\r\n".
2507 "\td=" . $this->DKIM_domain .
";" . $ident .
"\r\n".
2511 "\tbh=" . $DKIMb64 .
";\r\n".
2513 $toSign = $this->
DKIM_HeaderC($from_header .
"\r\n" . $to_header .
"\r\n" . $subject_header .
"\r\n" . $dkimhdrs);
2515 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed.
"\r\n";
2519 if (!empty($this->action_function) && function_exists($this->action_function)) {
2520 $params = array($isSent,
$to,
$cc,
$bcc, $subject, $body);
2521 call_user_func_array($this->action_function, $params);
2528 $errorMsg =
'<strong>' . $this->getMessage() .
"</strong><br />\n";