73 public $From =
'root@localhost';
689 if (ini_get(
'mbstring.func_overload') & 1) {
695 if(0 == strlen(
$to) && strpos(
$header,
'To: undisclosed-recipients:;') !==
false)
697 $to =
'undisclosed-recipients:;';
698 $header = preg_replace(
'/To: undisclosed-recipients:;(\s*)/',
'',
$header);
703 if (ini_get(
'safe_mode') or !$this->UseSendmailOptions or is_null(
$params)) {
719 if ($this->SMTPDebug <= 0) {
723 if (!in_array($this->Debugoutput, array(
'error_log',
'html',
'echo')) and is_callable($this->Debugoutput)) {
724 call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
727 switch ($this->Debugoutput) {
735 preg_replace(
'/[\r\n]+/',
'', $str),
744 $str = preg_replace(
'/\r\n?/ms',
"\n", $str);
745 echo gmdate(
'Y-m-d H:i:s') .
"\t" . str_replace(
761 $this->ContentType =
'text/html';
763 $this->ContentType =
'text/plain';
773 $this->Mailer =
'smtp';
782 $this->Mailer =
'mail';
791 $ini_sendmail_path = ini_get(
'sendmail_path');
793 if (!stristr($ini_sendmail_path,
'sendmail')) {
794 $this->Sendmail =
'/usr/sbin/sendmail';
796 $this->Sendmail = $ini_sendmail_path;
798 $this->Mailer =
'sendmail';
807 $ini_sendmail_path = ini_get(
'sendmail_path');
809 if (!stristr($ini_sendmail_path,
'qmail')) {
810 $this->Sendmail =
'/var/qmail/bin/qmail-inject';
812 $this->Sendmail = $ini_sendmail_path;
814 $this->Mailer =
'qmail';
835 public function addCC($address, $name =
'')
847 public function addBCC($address, $name =
'')
877 $address = trim($address);
878 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
879 if (($pos = strrpos($address,
'@')) ===
false) {
881 $error_message = $this->
lang(
'invalid_address') .
" (addAnAddress $kind): $address";
883 $this->
edebug($error_message);
884 if ($this->exceptions) {
889 $params = array($kind, $address, $name);
892 if ($kind !=
'Reply-To') {
893 if (!array_key_exists($address, $this->RecipientsQueue)) {
894 $this->RecipientsQueue[$address] =
$params;
898 if (!array_key_exists($address, $this->ReplyToQueue)) {
899 $this->ReplyToQueue[$address] =
$params;
906 return call_user_func_array(array($this,
'addAnAddress'),
$params);
921 if (!in_array($kind, array(
'to',
'cc',
'bcc',
'Reply-To'))) {
922 $error_message = $this->
lang(
'Invalid recipient kind: ') . $kind;
924 $this->
edebug($error_message);
925 if ($this->exceptions) {
931 $error_message = $this->
lang(
'invalid_address') .
" (addAnAddress $kind): $address";
933 $this->
edebug($error_message);
934 if ($this->exceptions) {
939 if ($kind !=
'Reply-To') {
940 if (!array_key_exists(strtolower($address), $this->all_recipients)) {
941 array_push($this->$kind, array($address, $name));
942 $this->all_recipients[strtolower($address)] =
true;
946 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
947 $this->ReplyTo[strtolower($address)] = array($address, $name);
966 $addresses = array();
967 if ($useimap and function_exists(
'imap_rfc822_parse_adrlist')) {
969 $list = imap_rfc822_parse_adrlist($addrstr,
'');
970 foreach ($list as $address) {
971 if ($address->host !=
'.SYNTAX-ERROR.') {
972 if ($this->
validateAddress($address->mailbox .
'@' . $address->host)) {
973 $addresses[] = array(
974 'name' => (property_exists($address,
'personal') ? $address->personal :
''),
975 'address' => $address->mailbox .
'@' . $address->host
982 $list = explode(
',', $addrstr);
983 foreach ($list as $address) {
984 $address = trim($address);
986 if (strpos($address,
'<') ===
false) {
989 $addresses[] = array(
991 'address' => $address
995 list($name, $email) = explode(
'<', $address);
996 $email = trim(str_replace(
'>',
'', $email));
998 $addresses[] = array(
999 'name' => trim(str_replace(array(
'"',
"'"),
'', $name)),
1017 public function setFrom($address, $name =
'', $auto =
true)
1019 $address = trim($address);
1020 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
1022 if (($pos = strrpos($address,
'@')) ===
false or
1025 $error_message = $this->
lang(
'invalid_address') .
" (setFrom) $address";
1027 $this->
edebug($error_message);
1028 if ($this->exceptions) {
1033 $this->From = $address;
1034 $this->FromName = $name;
1036 if (empty($this->Sender)) {
1037 $this->Sender = $address;
1076 if (is_null($patternselect)) {
1079 if (is_callable($patternselect)) {
1080 return call_user_func($patternselect, $address);
1083 if (strpos($address,
"\n") !==
false or strpos($address,
"\r") !==
false) {
1086 if (!$patternselect or $patternselect ==
'auto') {
1089 if (defined(
'PCRE_VERSION')) {
1091 if (version_compare(PCRE_VERSION,
'8.0.3') >= 0) {
1092 $patternselect =
'pcre8';
1094 $patternselect =
'pcre';
1096 } elseif (function_exists(
'extension_loaded') and extension_loaded(
'pcre')) {
1098 $patternselect =
'pcre';
1101 if (version_compare(PHP_VERSION,
'5.2.0') >= 0) {
1102 $patternselect =
'php';
1104 $patternselect =
'noregex';
1108 switch ($patternselect) {
1116 return (
boolean)preg_match(
1117 '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
1118 '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
1119 '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
1120 '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
1121 '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
1122 '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
1123 '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
1124 '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
1125 '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
1130 return (
boolean)preg_match(
1131 '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
1132 '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
1133 '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
1134 '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
1135 '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
1136 '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
1137 '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
1138 '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
1139 '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
1140 '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
1148 return (
boolean)preg_match(
1149 '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
1150 '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
1156 return (strlen($address) >= 3
1157 and strpos($address,
'@') >= 1
1158 and strpos($address,
'@') != strlen($address) - 1);
1161 return (
boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
1173 return function_exists(
'idn_to_ascii') and function_exists(
'mb_convert_encoding');
1191 !empty($this->CharSet) and
1192 ($pos = strrpos($address,
'@')) !==
false) {
1193 $domain = substr($address, ++$pos);
1195 if ($this->
has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
1196 $domain = mb_convert_encoding($domain,
'UTF-8', $this->CharSet);
1197 if (($punycode = defined(
'INTL_IDNA_VARIANT_UTS46') ?
1198 idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
1199 idn_to_ascii($domain)) !==
false) {
1200 return substr($address, 0, $pos) . $punycode;
1221 $this->mailHeader =
'';
1222 $this->
setError($exc->getMessage());
1223 if ($this->exceptions) {
1238 $this->error_count = 0;
1239 $this->mailHeader =
'';
1242 foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as
$params) {
1244 call_user_func_array(array($this,
'addAnAddress'),
$params);
1246 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
1251 foreach (array(
'From',
'Sender',
'ConfirmReadingTo') as $address_kind) {
1252 $this->$address_kind = trim($this->$address_kind);
1253 if (empty($this->$address_kind)) {
1258 $error_message = $this->
lang(
'invalid_address') .
' (punyEncode) ' . $this->$address_kind;
1260 $this->
edebug($error_message);
1261 if ($this->exceptions) {
1270 $this->ContentType =
'multipart/alternative';
1275 if (!$this->AllowEmpty and empty($this->Body)) {
1280 $this->MIMEHeader =
'';
1285 $this->MIMEHeader .= $tempheaders;
1289 if ($this->Mailer ==
'mail') {
1290 if (count($this->to) > 0) {
1291 $this->mailHeader .= $this->
addrAppend(
'To', $this->to);
1293 $this->mailHeader .= $this->
headerLine(
'To',
'undisclosed-recipients:;');
1302 if (!empty($this->DKIM_domain)
1303 && !empty($this->DKIM_selector)
1304 && (!empty($this->DKIM_private_string)
1305 || (!empty($this->DKIM_private) && file_exists($this->DKIM_private))
1309 $this->MIMEHeader . $this->mailHeader,
1313 $this->MIMEHeader = rtrim($this->MIMEHeader,
"\r\n ") . self::CRLF .
1314 str_replace(
"\r\n",
"\n", $header_dkim) .
self::CRLF;
1318 $this->
setError($exc->getMessage());
1319 if ($this->exceptions) {
1336 switch ($this->Mailer) {
1339 return $this->
sendmailSend($this->MIMEHeader, $this->MIMEBody);
1341 return $this->
smtpSend($this->MIMEHeader, $this->MIMEBody);
1343 return $this->
mailSend($this->MIMEHeader, $this->MIMEBody);
1345 $sendMethod = $this->Mailer.
'Send';
1346 if (method_exists($this, $sendMethod)) {
1347 return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
1350 return $this->
mailSend($this->MIMEHeader, $this->MIMEBody);
1353 $this->
setError($exc->getMessage());
1354 $this->
edebug($exc->getMessage());
1355 if ($this->exceptions) {
1374 if (!empty($this->Sender) and self::isShellSafe($this->Sender)) {
1375 if ($this->Mailer ==
'qmail') {
1376 $sendmailFmt =
'%s -f%s';
1378 $sendmailFmt =
'%s -oi -f%s -t';
1381 if ($this->Mailer ==
'qmail') {
1382 $sendmailFmt =
'%s';
1384 $sendmailFmt =
'%s -oi -t';
1389 $sendmail = sprintf($sendmailFmt, escapeshellcmd($this->Sendmail), $this->Sender);
1391 if ($this->SingleTo) {
1392 foreach ($this->SingleToArray as $toAddr) {
1393 if (!@$mail = popen($sendmail,
'w')) {
1396 fputs($mail,
'To: ' . $toAddr .
"\n");
1398 fputs($mail, $body);
1414 if (!@$mail = popen($sendmail,
'w')) {
1418 fputs($mail, $body);
1448 if (escapeshellcmd($string) !== $string
1449 or !in_array(escapeshellarg($string), array(
"'$string'",
"\"$string\""))
1454 $length = strlen($string);
1456 for ($i = 0; $i < $length; $i++) {
1462 if (!ctype_alnum($c) && strpos(
'@_-.', $c) ===
false) {
1482 foreach ($this->to as $toaddr) {
1485 $to = implode(
', ', $toArr);
1489 if (!empty($this->Sender) and $this->
validateAddress($this->Sender)) {
1491 if (self::isShellSafe($this->Sender)) {
1492 $params = sprintf(
'-f%s', $this->Sender);
1495 if (!empty($this->Sender) and !ini_get(
'safe_mode') and $this->
validateAddress($this->Sender)) {
1496 $old_from = ini_get(
'sendmail_from');
1497 ini_set(
'sendmail_from', $this->Sender);
1500 if ($this->SingleTo and count($toArr) > 1) {
1501 foreach ($toArr as $toAddr) {
1503 $this->
doCallback(
$result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1507 $this->
doCallback(
$result, $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1509 if (isset($old_from)) {
1510 ini_set(
'sendmail_from', $old_from);
1525 if (!is_object($this->smtp)) {
1526 $this->smtp =
new SMTP;
1545 $bad_rcpt = array();
1549 if (!empty($this->Sender) and $this->
validateAddress($this->Sender)) {
1554 if (!$this->smtp->mail($smtp_from)) {
1555 $this->
setError($this->
lang(
'from_failed') . $smtp_from .
' : ' . implode(
',', $this->smtp->getError()));
1560 foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
1561 foreach ($togroup as
$to) {
1562 if (!$this->smtp->recipient(
$to[0])) {
1563 $error = $this->smtp->getError();
1564 $bad_rcpt[] = array(
'to' =>
$to[0],
'error' => $error[
'detail']);
1569 $this->
doCallback($isSent, array(
$to[0]), array(), array(), $this->Subject, $body, $this->From);
1574 if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data(
$header . $body)) {
1577 if ($this->SMTPKeepAlive) {
1578 $this->smtp->reset();
1580 $this->smtp->quit();
1581 $this->smtp->close();
1584 if (count($bad_rcpt) > 0) {
1586 foreach ($bad_rcpt as $bad) {
1587 $errstr .= $bad[
'to'] .
': ' . $bad[
'error'];
1590 $this->
lang(
'recipients_failed') . $errstr,
1608 if (is_null($this->smtp)) {
1618 if ($this->smtp->connected()) {
1622 $this->smtp->setTimeout($this->Timeout);
1623 $this->smtp->setDebugLevel($this->SMTPDebug);
1624 $this->smtp->setDebugOutput($this->Debugoutput);
1625 $this->smtp->setVerp($this->do_verp);
1626 $hosts = explode(
';', $this->Host);
1627 $lastexception =
null;
1629 foreach ($hosts as $hostentry) {
1630 $hostinfo = array();
1631 if (!preg_match(
'/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
1642 $tls = ($this->SMTPSecure ==
'tls');
1643 if (
'ssl' == $hostinfo[2] or (
'' == $hostinfo[2] and
'ssl' == $this->SMTPSecure)) {
1647 } elseif ($hostinfo[2] ==
'tls') {
1653 $sslext = defined(
'OPENSSL_ALGO_SHA1');
1654 if (
'tls' === $secure or
'ssl' === $secure) {
1660 $host = $hostinfo[3];
1662 $tport = (integer)$hostinfo[4];
1663 if ($tport > 0 and $tport < 65536) {
1666 if ($this->smtp->connect($prefix . $host, $port, $this->Timeout,
$options)) {
1673 $this->smtp->hello($hello);
1679 if ($this->SMTPAutoTLS and $sslext and $secure !=
'ssl' and $this->smtp->getServerExt(
'STARTTLS')) {
1683 if (!$this->smtp->startTLS()) {
1687 $this->smtp->hello($hello);
1689 if ($this->SMTPAuth) {
1690 if (!$this->smtp->authenticate(
1703 $lastexception = $exc;
1704 $this->
edebug($exc->getMessage());
1706 $this->smtp->quit();
1711 $this->smtp->close();
1713 if ($this->exceptions and !is_null($lastexception)) {
1714 throw $lastexception;
1725 if (is_a($this->smtp,
'SMTP')) {
1726 if ($this->smtp->connected()) {
1727 $this->smtp->quit();
1728 $this->smtp->close();
1745 $renamed_langcodes = array(
1753 if (isset($renamed_langcodes[$langcode])) {
1754 $langcode = $renamed_langcodes[$langcode];
1759 'authenticate' =>
'SMTP Error: Could not authenticate.',
1760 'connect_host' =>
'SMTP Error: Could not connect to SMTP host.',
1761 'data_not_accepted' =>
'SMTP Error: data not accepted.',
1762 'empty_message' =>
'Message body empty',
1763 'encoding' =>
'Unknown encoding: ',
1764 'execute' =>
'Could not execute: ',
1765 'file_access' =>
'Could not access file: ',
1766 'file_open' =>
'File Error: Could not open file: ',
1767 'from_failed' =>
'The following From address failed: ',
1768 'instantiate' =>
'Could not instantiate mail function.',
1769 'invalid_address' =>
'Invalid address: ',
1770 'mailer_not_supported' =>
' mailer is not supported.',
1771 'provide_address' =>
'You must provide at least one recipient email address.',
1772 'recipients_failed' =>
'SMTP Error: The following recipients failed: ',
1773 'signing' =>
'Signing Error: ',
1774 'smtp_connect_failed' =>
'SMTP connect() failed.',
1775 'smtp_error' =>
'SMTP server error: ',
1776 'variable_set' =>
'Cannot set or reset variable: ',
1777 'extension_missing' =>
'Extension missing: '
1779 if (empty($lang_path)) {
1781 $lang_path = dirname(__FILE__). DIRECTORY_SEPARATOR .
'language'. DIRECTORY_SEPARATOR;
1784 if (!preg_match(
'/^[a-z]{2}(?:_[a-zA-Z]{2})?$/', $langcode)) {
1788 $lang_file = $lang_path .
'phpmailer.lang-' . $langcode .
'.php';
1790 if ($langcode !=
'en') {
1792 if (!is_readable($lang_file)) {
1797 $foundlang = include $lang_file;
1801 return (
boolean)$foundlang;
1825 $addresses = array();
1826 foreach ($addr as $address) {
1829 return $type .
': ' . implode(
', ', $addresses) .
$this->LE;
1841 if (empty($addr[1])) {
1861 public function wrapText($message, $length, $qp_mode =
false)
1864 $soft_break = sprintf(
' =%s', $this->LE);
1870 $is_utf8 = (strtolower($this->CharSet) ==
'utf-8');
1871 $lelen = strlen($this->LE);
1872 $crlflen = strlen(self::CRLF);
1874 $message = $this->
fixEOL($message);
1876 if (substr($message, -$lelen) == $this->LE) {
1877 $message = substr($message, 0, -$lelen);
1881 $lines = explode($this->LE, $message);
1884 foreach ($lines as $line) {
1885 $words = explode(
' ', $line);
1888 foreach ($words as $word) {
1889 if ($qp_mode and (strlen($word) > $length)) {
1890 $space_left = $length - strlen($buf) - $crlflen;
1892 if ($space_left > 20) {
1896 } elseif (substr($word, $len - 1, 1) ==
'=') {
1898 } elseif (substr($word, $len - 2, 1) ==
'=') {
1901 $part = substr($word, 0, $len);
1902 $word = substr($word, $len);
1903 $buf .=
' ' . $part;
1904 $message .= $buf . sprintf(
'=%s', self::CRLF);
1906 $message .= $buf . $soft_break;
1910 while (strlen($word) > 0) {
1917 } elseif (substr($word, $len - 1, 1) ==
'=') {
1919 } elseif (substr($word, $len - 2, 1) ==
'=') {
1922 $part = substr($word, 0, $len);
1923 $word = substr($word, $len);
1925 if (strlen($word) > 0) {
1926 $message .= $part . sprintf(
'=%s', self::CRLF);
1938 if (strlen($buf) > $length and $buf_o !=
'') {
1939 $message .= $buf_o . $soft_break;
1962 $foundSplitPos =
false;
1964 while (!$foundSplitPos) {
1965 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
1966 $encodedCharPos = strpos($lastChunk,
'=');
1967 if (
false !== $encodedCharPos) {
1970 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
1971 $dec = hexdec($hex);
1976 if ($encodedCharPos > 0) {
1977 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1979 $foundSplitPos =
true;
1980 } elseif ($dec >= 192) {
1983 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
1984 $foundSplitPos =
true;
1985 } elseif ($dec < 192) {
1991 $foundSplitPos =
true;
2007 if ($this->WordWrap < 1) {
2011 switch ($this->message_type) {
2015 case 'alt_inline_attach':
2016 $this->AltBody = $this->
wrapText($this->AltBody, $this->WordWrap);
2019 $this->Body = $this->
wrapText($this->Body, $this->WordWrap);
2033 if ($this->MessageDate ==
'') {
2039 if ($this->SingleTo) {
2040 if ($this->Mailer !=
'mail') {
2041 foreach ($this->to as $toaddr) {
2042 $this->SingleToArray[] = $this->
addrFormat($toaddr);
2046 if (count($this->to) > 0) {
2047 if ($this->Mailer !=
'mail') {
2050 } elseif (count($this->cc) == 0) {
2055 $result .= $this->
addrAppend(
'From', array(array(trim($this->From), $this->FromName)));
2058 if (count($this->cc) > 0) {
2064 $this->Mailer ==
'sendmail' or $this->Mailer ==
'qmail' or $this->Mailer ==
'mail'
2066 and count($this->bcc) > 0
2071 if (count($this->ReplyTo) > 0) {
2076 if ($this->Mailer !=
'mail') {
2082 if (
'' != $this->MessageID and preg_match(
'/^<.*@.*>$/', $this->MessageID)) {
2085 $this->lastMessageID = sprintf(
'<%s@%s>', $this->uniqueid, $this->
serverHostname());
2088 if (!is_null($this->Priority)) {
2091 if ($this->XMailer ==
'') {
2094 'PHPMailer ' . $this->Version .
' (https://github.com/PHPMailer/PHPMailer)'
2097 $myXmailer = trim($this->XMailer);
2103 if ($this->ConfirmReadingTo !=
'') {
2104 $result .= $this->
headerLine(
'Disposition-Notification-To',
'<' . $this->ConfirmReadingTo .
'>');
2108 foreach ($this->CustomHeader as
$header) {
2114 if (!$this->sign_key_file) {
2130 $ismultipart =
true;
2131 switch ($this->message_type) {
2134 $result .= $this->
textLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
2137 case 'inline_attach':
2139 case 'alt_inline_attach':
2141 $result .= $this->
textLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
2146 $result .= $this->
textLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
2150 $result .= $this->
textLine(
'Content-Type: ' . $this->ContentType .
'; charset=' . $this->CharSet);
2151 $ismultipart =
false;
2155 if ($this->Encoding !=
'7bit') {
2158 if ($this->Encoding ==
'8bit') {
2167 if ($this->Mailer !=
'mail') {
2184 return rtrim($this->MIMEHeader . $this->mailHeader,
"\n\r") . self::CRLF . self::CRLF .
$this->MIMEBody;
2192 return md5(uniqid(time()));
2211 if ($this->sign_key_file) {
2220 if ($bodyEncoding ==
'8bit' and !$this->
has8bitChars($this->Body)) {
2221 $bodyEncoding =
'7bit';
2223 $bodyCharSet =
'us-ascii';
2227 if (
'base64' != $this->Encoding and self::hasLineLongerThanMax($this->Body)) {
2228 $bodyEncoding =
'quoted-printable';
2234 if ($altBodyEncoding ==
'8bit' and !$this->
has8bitChars($this->AltBody)) {
2235 $altBodyEncoding =
'7bit';
2237 $altBodyCharSet =
'us-ascii';
2241 if (
'base64' != $altBodyEncoding and self::hasLineLongerThanMax($this->AltBody)) {
2242 $altBodyEncoding =
'quoted-printable';
2245 $mimepre =
"This is a multi-part message in MIME format." . $this->LE .
$this->LE;
2246 switch ($this->message_type) {
2249 $body .= $this->
getBoundary($this->boundary[1], $bodyCharSet,
'', $bodyEncoding);
2250 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2252 $body .= $this->
attachAll(
'inline', $this->boundary[1]);
2256 $body .= $this->
getBoundary($this->boundary[1], $bodyCharSet,
'', $bodyEncoding);
2257 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2259 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2261 case 'inline_attach':
2263 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2264 $body .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2265 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2267 $body .= $this->
getBoundary($this->boundary[2], $bodyCharSet,
'', $bodyEncoding);
2268 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2270 $body .= $this->
attachAll(
'inline', $this->boundary[2]);
2272 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2276 $body .= $this->
getBoundary($this->boundary[1], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2277 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2279 $body .= $this->
getBoundary($this->boundary[1], $bodyCharSet,
'text/html', $bodyEncoding);
2280 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2282 if (!empty($this->Ical)) {
2283 $body .= $this->
getBoundary($this->boundary[1],
'',
'text/calendar; method=REQUEST',
'');
2284 $body .= $this->
encodeString($this->Ical, $this->Encoding);
2291 $body .= $this->
getBoundary($this->boundary[1], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2292 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2294 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2295 $body .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2296 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2298 $body .= $this->
getBoundary($this->boundary[2], $bodyCharSet,
'text/html', $bodyEncoding);
2299 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2301 $body .= $this->
attachAll(
'inline', $this->boundary[2]);
2307 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2308 $body .= $this->
headerLine(
'Content-Type',
'multipart/alternative;');
2309 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2311 $body .= $this->
getBoundary($this->boundary[2], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2312 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2314 $body .= $this->
getBoundary($this->boundary[2], $bodyCharSet,
'text/html', $bodyEncoding);
2315 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2319 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2321 case 'alt_inline_attach':
2323 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2324 $body .= $this->
headerLine(
'Content-Type',
'multipart/alternative;');
2325 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2327 $body .= $this->
getBoundary($this->boundary[2], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2328 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2330 $body .= $this->
textLine(
'--' . $this->boundary[2]);
2331 $body .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2332 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[3] .
'"');
2334 $body .= $this->
getBoundary($this->boundary[3], $bodyCharSet,
'text/html', $bodyEncoding);
2335 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2337 $body .= $this->
attachAll(
'inline', $this->boundary[3]);
2341 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2346 $this->Encoding = $bodyEncoding;
2347 $body .= $this->
encodeString($this->Body, $this->Encoding);
2353 } elseif ($this->sign_key_file) {
2355 if (!defined(
'PKCS7_TEXT')) {
2359 $file = tempnam(sys_get_temp_dir(),
'mail');
2360 if (
false === file_put_contents(
$file, $body)) {
2363 $signed = tempnam(sys_get_temp_dir(),
'signed');
2365 if (empty($this->sign_extracerts_file)) {
2366 $sign = @openssl_pkcs7_sign(
2369 'file://' . realpath($this->sign_cert_file),
2370 array(
'file://' . realpath($this->sign_key_file), $this->sign_key_pass),
2374 $sign = @openssl_pkcs7_sign(
2377 'file://' . realpath($this->sign_cert_file),
2378 array(
'file://' . realpath($this->sign_key_file), $this->sign_key_pass),
2381 $this->sign_extracerts_file
2386 $body = file_get_contents($signed);
2389 $parts = explode(
"\n\n", $body, 2);
2390 $this->MIMEHeader .= $parts[0] . $this->LE .
$this->LE;
2399 if ($this->exceptions) {
2419 if ($charSet ==
'') {
2422 if ($contentType ==
'') {
2425 if ($encoding ==
'') {
2429 $result .= sprintf(
'Content-Type: %s; charset=%s', $contentType, $charSet);
2432 if ($encoding !=
'7bit') {
2469 $this->message_type = implode(
'_', $type);
2470 if ($this->message_type ==
'') {
2472 $this->message_type =
'plain';
2485 return $name .
': ' . $value .
$this->LE;
2511 public function addAttachment(
$path, $name =
'', $encoding =
'base64', $type =
'', $disposition =
'attachment')
2514 if (!@is_file(
$path)) {
2528 $this->attachment[] = array(
2540 $this->
setError($exc->getMessage());
2541 $this->
edebug($exc->getMessage());
2542 if ($this->exceptions) {
2589 if (in_array($inclhash, $incl)) {
2592 $incl[] = $inclhash;
2598 if ($disposition ==
'inline' && array_key_exists($cid, $cidUniq)) {
2601 $cidUniq[$cid] =
true;
2603 $mime[] = sprintf(
'--%s%s',
$boundary, $this->LE);
2605 if (!empty($name)) {
2607 'Content-Type: %s; name="%s"%s',
2614 'Content-Type: %s%s',
2620 if ($encoding !=
'7bit') {
2621 $mime[] = sprintf(
'Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
2624 if ($disposition ==
'inline') {
2625 $mime[] = sprintf(
'Content-ID: <%s>%s', $cid, $this->LE);
2632 if (!(empty($disposition))) {
2634 if (preg_match(
'/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
2636 'Content-Disposition: %s; filename="%s"%s',
2639 $this->LE . $this->LE
2642 if (!empty($encoded_name)) {
2644 'Content-Disposition: %s; filename=%s%s',
2647 $this->LE . $this->LE
2651 'Content-Disposition: %s%s',
2653 $this->LE . $this->LE
2678 $mime[] = sprintf(
'--%s--%s',
$boundary, $this->LE);
2680 return implode(
'', $mime);
2695 if (!is_readable(
$path)) {
2698 $magic_quotes = get_magic_quotes_runtime();
2699 if ($magic_quotes) {
2700 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
2701 set_magic_quotes_runtime(
false);
2706 ini_set(
'magic_quotes_runtime',
false);
2709 $file_buffer = file_get_contents(
$path);
2710 $file_buffer = $this->
encodeString($file_buffer, $encoding);
2711 if ($magic_quotes) {
2712 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
2713 set_magic_quotes_runtime($magic_quotes);
2715 ini_set(
'magic_quotes_runtime', $magic_quotes);
2718 return $file_buffer;
2719 }
catch (Exception $exc) {
2720 $this->
setError($exc->getMessage());
2736 switch (strtolower($encoding)) {
2738 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2742 $encoded = $this->
fixEOL($str);
2744 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
2751 case 'quoted-printable':
2772 switch (strtolower($position)) {
2774 if (!preg_match(
'/[\200-\377]/', $str)) {
2776 $encoded = addcslashes($str,
"\0..\37\177\\\"");
2777 if (($str == $encoded) && !preg_match(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2780 return (
"\"$encoded\"");
2783 $matchcount = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $str, $matches);
2787 $matchcount = preg_match_all(
'/[()"]/', $str, $matches);
2791 $matchcount += preg_match_all(
'/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2796 if ($matchcount == 0) {
2800 $maxlen = 75 - 7 - strlen($this->CharSet);
2802 if ($matchcount > strlen($str) / 3) {
2805 if (function_exists(
'mb_strlen') && $this->
hasMultiBytes($str)) {
2810 $encoded = base64_encode($str);
2811 $maxlen -= $maxlen % 4;
2812 $encoded = trim(chunk_split($encoded, $maxlen,
"\n"));
2816 $encoded = $this->
encodeQ($str, $position);
2817 $encoded = $this->
wrapText($encoded, $maxlen,
true);
2818 $encoded = str_replace(
'=' . self::CRLF,
"\n", trim($encoded));
2821 $encoded = preg_replace(
'/^(.*)$/m',
' =?' . $this->CharSet .
"?$encoding?\\1?=", $encoded);
2822 $encoded = trim(str_replace(
"\n", $this->LE, $encoded));
2835 if (function_exists(
'mb_strlen')) {
2836 return (strlen($str) > mb_strlen($str, $this->CharSet));
2849 return (
boolean)preg_match(
'/[\x80-\xFF]/',
$text);
2864 $start =
'=?' . $this->CharSet .
'?B?';
2867 if ($linebreak ===
null) {
2871 $mb_length = mb_strlen($str, $this->CharSet);
2873 $length = 75 - strlen($start) - strlen($end);
2875 $ratio = $mb_length / strlen($str);
2877 $avgLength = floor($length * $ratio * .75);
2879 for ($i = 0; $i < $mb_length; $i += $offset) {
2882 $offset = $avgLength - $lookBack;
2883 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2884 $chunk = base64_encode($chunk);
2886 }
while (strlen($chunk) > $length);
2887 $encoded .= $chunk . $linebreak;
2891 $encoded = substr($encoded, 0, -strlen($linebreak));
2907 if (function_exists(
'quoted_printable_encode')) {
2908 return quoted_printable_encode($string);
2911 $string = str_replace(
2912 array(
'%20',
'%0D%0A.',
'%0D%0A',
'%'),
2913 array(
' ',
"\r\n=2E",
"\r\n",
'='),
2914 rawurlencode($string)
2916 return preg_replace(
'/[^\r\n]{' . ($line_max - 3) .
'}[^=\r\n]{2}/',
"$0=\r\n", $string);
2931 $line_max = 76, $space_conv =
false
2934 return $this->
encodeQP($string, $line_max);
2949 $encoded = str_replace(array(
"\r",
"\n"),
'', $str);
2950 switch (strtolower($position)) {
2953 $pattern =
'^A-Za-z0-9!*+\/ -';
2958 $pattern =
'\(\)"';
2965 $pattern =
'\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
2969 if (preg_match_all(
"/[{$pattern}]/", $encoded, $matches)) {
2972 $eqkey = array_search(
'=', $matches[0]);
2973 if (
false !== $eqkey) {
2974 unset($matches[0][$eqkey]);
2975 array_unshift($matches[0],
'=');
2977 foreach (array_unique($matches[0]) as $char) {
2978 $encoded = str_replace($char,
'=' . sprintf(
'%02X', ord($char)), $encoded);
2982 return str_replace(
' ',
'_', $encoded);
2999 $encoding =
'base64',
3001 $disposition =
'attachment'
3008 $this->attachment[] = array(
3039 if (!@is_file(
$path)) {
3055 $this->attachment[] = array(
3086 $encoding =
'base64',
3088 $disposition =
'inline'
3091 if ($type ==
'' and !empty($name)) {
3096 $this->attachment[] = array(
3144 return !empty($this->AltBody);
3158 unset($this->RecipientsQueue[$address]);
3169 foreach ($this->to as
$to) {
3170 unset($this->all_recipients[strtolower(
$to[0])]);
3172 $this->to = array();
3182 foreach ($this->cc as
$cc) {
3183 unset($this->all_recipients[strtolower(
$cc[0])]);
3185 $this->cc = array();
3195 foreach ($this->bcc as
$bcc) {
3196 unset($this->all_recipients[strtolower(
$bcc[0])]);
3198 $this->bcc = array();
3208 $this->ReplyTo = array();
3209 $this->ReplyToQueue = array();
3218 $this->to = array();
3219 $this->cc = array();
3220 $this->bcc = array();
3221 $this->all_recipients = array();
3222 $this->RecipientsQueue = array();
3231 $this->attachment = array();
3240 $this->CustomHeader = array();
3251 $this->error_count++;
3252 if ($this->Mailer ==
'smtp' and !is_null($this->smtp)) {
3253 $lasterror = $this->smtp->getError();
3254 if (!empty($lasterror[
'error'])) {
3255 $msg .= $this->
lang(
'smtp_error') . $lasterror[
'error'];
3256 if (!empty($lasterror[
'detail'])) {
3257 $msg .=
' Detail: '. $lasterror[
'detail'];
3259 if (!empty($lasterror[
'smtp_code'])) {
3260 $msg .=
' SMTP code: ' . $lasterror[
'smtp_code'];
3262 if (!empty($lasterror[
'smtp_code_ex'])) {
3263 $msg .=
' Additional SMTP info: ' . $lasterror[
'smtp_code_ex'];
3267 $this->ErrorInfo = $msg;
3280 date_default_timezone_set(@date_default_timezone_get());
3281 return date(
'D, j M Y H:i:s O');
3292 $result =
'localhost.localdomain';
3293 if (!empty($this->Hostname)) {
3297 } elseif (function_exists(
'gethostname') && gethostname() !==
false) {
3299 } elseif (php_uname(
'n') !==
false) {
3313 if (count($this->language) < 1) {
3317 if (array_key_exists($key, $this->language)) {
3318 if ($key ==
'smtp_connect_failed') {
3322 return $this->language[$key] .
' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
3324 return $this->language[$key];
3338 return ($this->error_count > 0);
3351 $nstr = str_replace(array(
"\r\n",
"\r"),
"\n", $str);
3353 if ($this->LE !==
"\n") {
3354 $nstr = str_replace(
"\n", $this->LE, $nstr);
3370 if ($value ===
null) {
3372 $this->CustomHeader[] = explode(
':', $name, 2);
3374 $this->CustomHeader[] = array($name, $value);
3403 public function msgHTML($message, $basedir =
'', $advanced =
false)
3405 preg_match_all(
'/(src|background)=["\'](.*)["\']/Ui', $message, $images);
3406 if (array_key_exists(2, $images)) {
3407 if (strlen($basedir) > 1 && substr($basedir, -1) !=
'/') {
3411 foreach ($images[2] as $imgindex =>
$url) {
3413 if (preg_match(
'#^data:(image[^;,]*)(;base64)?,#',
$url, $match)) {
3420 $cid = md5(
$url) .
'@phpmailer.0';
3422 $message = str_replace(
3423 $images[0][$imgindex],
3424 $images[1][$imgindex] .
'="cid:' . $cid .
'"',
3434 && (strpos(
$url,
'..') ===
false)
3436 && substr(
$url, 0, 4) !==
'cid:'
3438 && !preg_match(
'#^[a-z][a-z0-9+.-]*:?//#i',
$url)
3441 $directory = dirname(
$url);
3442 if ($directory ==
'.') {
3445 $cid = md5(
$url) .
'@phpmailer.0';
3446 if (strlen($directory) > 1 && substr($directory, -1) !=
'/') {
3454 self::_mime_types((
string)self::mb_pathinfo(
$filename, PATHINFO_EXTENSION))
3457 $message = preg_replace(
3458 '/' . $images[1][$imgindex] .
'=["\']' . preg_quote(
$url,
'/') .
'["\']/Ui',
3459 $images[1][$imgindex] .
'="cid:' . $cid .
'"',
3471 $this->AltBody =
'To view this email message, open it in a program that understands HTML!' .
3499 if (is_callable($advanced)) {
3500 return call_user_func($advanced,
$html);
3502 return html_entity_decode(
3503 trim(strip_tags(preg_replace(
'/<(head|title|style|script)[^>]*>.*?<\/\\1>/si',
'',
$html))),
3519 'xl' =>
'application/excel',
3520 'js' =>
'application/javascript',
3521 'hqx' =>
'application/mac-binhex40',
3522 'cpt' =>
'application/mac-compactpro',
3523 'bin' =>
'application/macbinary',
3524 'doc' =>
'application/msword',
3525 'word' =>
'application/msword',
3526 'xlsx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3527 'xltx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
3528 'potx' =>
'application/vnd.openxmlformats-officedocument.presentationml.template',
3529 'ppsx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
3530 'pptx' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
3531 'sldx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slide',
3532 'docx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
3533 'dotx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
3534 'xlam' =>
'application/vnd.ms-excel.addin.macroEnabled.12',
3535 'xlsb' =>
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
3536 'class' =>
'application/octet-stream',
3537 'dll' =>
'application/octet-stream',
3538 'dms' =>
'application/octet-stream',
3539 'exe' =>
'application/octet-stream',
3540 'lha' =>
'application/octet-stream',
3541 'lzh' =>
'application/octet-stream',
3542 'psd' =>
'application/octet-stream',
3543 'sea' =>
'application/octet-stream',
3544 'so' =>
'application/octet-stream',
3545 'oda' =>
'application/oda',
3546 'pdf' =>
'application/pdf',
3547 'ai' =>
'application/postscript',
3548 'eps' =>
'application/postscript',
3549 'ps' =>
'application/postscript',
3550 'smi' =>
'application/smil',
3551 'smil' =>
'application/smil',
3552 'mif' =>
'application/vnd.mif',
3553 'xls' =>
'application/vnd.ms-excel',
3554 'ppt' =>
'application/vnd.ms-powerpoint',
3555 'wbxml' =>
'application/vnd.wap.wbxml',
3556 'wmlc' =>
'application/vnd.wap.wmlc',
3557 'dcr' =>
'application/x-director',
3558 'dir' =>
'application/x-director',
3559 'dxr' =>
'application/x-director',
3560 'dvi' =>
'application/x-dvi',
3561 'gtar' =>
'application/x-gtar',
3562 'php3' =>
'application/x-httpd-php',
3563 'php4' =>
'application/x-httpd-php',
3564 'php' =>
'application/x-httpd-php',
3565 'phtml' =>
'application/x-httpd-php',
3566 'phps' =>
'application/x-httpd-php-source',
3567 'swf' =>
'application/x-shockwave-flash',
3568 'sit' =>
'application/x-stuffit',
3569 'tar' =>
'application/x-tar',
3570 'tgz' =>
'application/x-tar',
3571 'xht' =>
'application/xhtml+xml',
3572 'xhtml' =>
'application/xhtml+xml',
3573 'zip' =>
'application/zip',
3574 'mid' =>
'audio/midi',
3575 'midi' =>
'audio/midi',
3576 'mp2' =>
'audio/mpeg',
3577 'mp3' =>
'audio/mpeg',
3578 'mpga' =>
'audio/mpeg',
3579 'aif' =>
'audio/x-aiff',
3580 'aifc' =>
'audio/x-aiff',
3581 'aiff' =>
'audio/x-aiff',
3582 'ram' =>
'audio/x-pn-realaudio',
3583 'rm' =>
'audio/x-pn-realaudio',
3584 'rpm' =>
'audio/x-pn-realaudio-plugin',
3585 'ra' =>
'audio/x-realaudio',
3586 'wav' =>
'audio/x-wav',
3587 'bmp' =>
'image/bmp',
3588 'gif' =>
'image/gif',
3589 'jpeg' =>
'image/jpeg',
3590 'jpe' =>
'image/jpeg',
3591 'jpg' =>
'image/jpeg',
3592 'png' =>
'image/png',
3593 'tiff' =>
'image/tiff',
3594 'tif' =>
'image/tiff',
3595 'eml' =>
'message/rfc822',
3596 'css' =>
'text/css',
3597 'html' =>
'text/html',
3598 'htm' =>
'text/html',
3599 'shtml' =>
'text/html',
3600 'log' =>
'text/plain',
3601 'text' =>
'text/plain',
3602 'txt' =>
'text/plain',
3603 'rtx' =>
'text/richtext',
3604 'rtf' =>
'text/rtf',
3605 'vcf' =>
'text/vcard',
3606 'vcard' =>
'text/vcard',
3607 'xml' =>
'text/xml',
3608 'xsl' =>
'text/xml',
3609 'mpeg' =>
'video/mpeg',
3610 'mpe' =>
'video/mpeg',
3611 'mpg' =>
'video/mpeg',
3612 'mov' =>
'video/quicktime',
3613 'qt' =>
'video/quicktime',
3614 'rv' =>
'video/vnd.rn-realvideo',
3615 'avi' =>
'video/x-msvideo',
3616 'movie' =>
'video/x-sgi-movie'
3618 if (array_key_exists(strtolower($ext), $mimes)) {
3619 return $mimes[strtolower($ext)];
3621 return 'application/octet-stream';
3635 if (
false !== $qpos) {
3655 $ret = array(
'dirname' =>
'',
'basename' =>
'',
'extension' =>
'',
'filename' =>
'');
3656 $pathinfo = array();
3657 if (preg_match(
'%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im',
$path, $pathinfo)) {
3658 if (array_key_exists(1, $pathinfo)) {
3659 $ret[
'dirname'] = $pathinfo[1];
3661 if (array_key_exists(2, $pathinfo)) {
3662 $ret[
'basename'] = $pathinfo[2];
3664 if (array_key_exists(5, $pathinfo)) {
3665 $ret[
'extension'] = $pathinfo[5];
3667 if (array_key_exists(3, $pathinfo)) {
3668 $ret[
'filename'] = $pathinfo[3];
3672 case PATHINFO_DIRNAME:
3674 return $ret[
'dirname'];
3675 case PATHINFO_BASENAME:
3677 return $ret[
'basename'];
3678 case PATHINFO_EXTENSION:
3680 return $ret[
'extension'];
3681 case PATHINFO_FILENAME:
3683 return $ret[
'filename'];
3703 public function set($name, $value =
'')
3705 if (property_exists($this, $name)) {
3706 $this->$name = $value;
3722 return trim(str_replace(array(
"\r",
"\n"),
'', $str));
3737 return preg_replace(
'/(\r\n|\r|\n)/ms', $breaktype,
$text);
3748 public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename =
'')
3750 $this->sign_cert_file = $cert_filename;
3751 $this->sign_key_file = $key_filename;
3752 $this->sign_key_pass = $key_pass;
3753 $this->sign_extracerts_file = $extracerts_filename;
3765 for ($i = 0; $i < strlen(
$txt); $i++) {
3766 $ord = ord(
$txt[$i]);
3767 if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
3770 $line .=
'=' . sprintf(
'%02X', $ord);
3785 if (!defined(
'PKCS7_TEXT')) {
3786 if ($this->exceptions) {
3791 $privKeyStr = !empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private);
3792 if (
'' != $this->DKIM_passphrase) {
3793 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
3795 $privKey = openssl_pkey_get_private($privKeyStr);
3799 if (version_compare(PHP_VERSION,
'5.3.0') >= 0 and
3800 in_array(
'sha256WithRSAEncryption', openssl_get_md_methods(
true))) {
3801 if (openssl_sign($signHeader, $signature, $privKey,
'sha256WithRSAEncryption')) {
3802 openssl_pkey_free($privKey);
3803 return base64_encode($signature);
3806 $pinfo = openssl_pkey_get_details($privKey);
3807 $hash = hash(
'sha256', $signHeader);
3810 $t =
'3031300d060960864801650304020105000420' . $hash;
3811 $pslen = $pinfo[
'bits'] / 8 - (strlen(
$t) / 2 + 3);
3812 $eb = pack(
'H*',
'0001' . str_repeat(
'FF', $pslen) .
'00' .
$t);
3814 if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) {
3815 openssl_pkey_free($privKey);
3816 return base64_encode($signature);
3819 openssl_pkey_free($privKey);
3831 $signHeader = preg_replace(
'/\r\n\s+/',
' ', $signHeader);
3832 $lines = explode(
"\r\n", $signHeader);
3833 foreach ($lines as $key => $line) {
3834 list($heading, $value) = explode(
':', $line, 2);
3835 $heading = strtolower($heading);
3836 $value = preg_replace(
'/\s{2,}/',
' ', $value);
3837 $lines[$key] = $heading .
':' . trim($value);
3839 $signHeader = implode(
"\r\n", $lines);
3855 $body = str_replace(
"\r\n",
"\n", $body);
3856 $body = str_replace(
"\n",
"\r\n", $body);
3858 while (substr($body, strlen($body) - 4, 4) ==
"\r\n\r\n") {
3859 $body = substr($body, 0, strlen($body) - 2);
3872 public function DKIM_Add($headers_line, $subject, $body)
3874 $DKIMsignatureType =
'rsa-sha256';
3875 $DKIMcanonicalization =
'relaxed/simple';
3876 $DKIMquery =
'dns/txt';
3878 $subject_header =
"Subject: $subject";
3879 $headers = explode($this->LE, $headers_line);
3884 foreach ($headers as
$header) {
3885 if (strpos(
$header,
'From:') === 0) {
3887 $current =
'from_header';
3888 } elseif (strpos(
$header,
'To:') === 0) {
3890 $current =
'to_header';
3891 } elseif (strpos(
$header,
'Date:') === 0) {
3893 $current =
'date_header';
3895 if (!empty($$current) && strpos(
$header,
' =?') === 0) {
3902 $from = str_replace(
'|',
'=7C', $this->
DKIM_QP($from_header));
3903 $to = str_replace(
'|',
'=7C', $this->
DKIM_QP($to_header));
3904 $date = str_replace(
'|',
'=7C', $this->
DKIM_QP($date_header));
3905 $subject = str_replace(
3908 $this->
DKIM_QP($subject_header)
3911 $DKIMlen = strlen($body);
3912 $DKIMb64 = base64_encode(pack(
'H*', hash(
'sha256', $body)));
3913 if (
'' == $this->DKIM_identity) {
3916 $ident =
' i=' . $this->DKIM_identity .
';';
3918 $dkimhdrs =
'DKIM-Signature: v=1; a=' .
3919 $DKIMsignatureType .
'; q=' .
3920 $DKIMquery .
'; l=' .
3922 $this->DKIM_selector .
3924 "\tt=" . $DKIMtime .
'; c=' . $DKIMcanonicalization .
";\r\n" .
3925 "\th=From:To:Date:Subject;\r\n" .
3926 "\td=" . $this->DKIM_domain .
';' . $ident .
"\r\n" .
3930 "\t|$subject;\r\n" .
3931 "\tbh=" . $DKIMb64 .
";\r\n" .
3934 $from_header .
"\r\n" .
3935 $to_header .
"\r\n" .
3936 $date_header .
"\r\n" .
3937 $subject_header .
"\r\n" .
3941 return $dkimhdrs . $signed .
"\r\n";
3953 return (
boolean)preg_match(
'/^(.{'.(self::MAX_LINE_LENGTH + 2).
',})/m', $str);
4023 if (!empty($this->action_function) && is_callable($this->action_function)) {
4025 call_user_func_array($this->action_function,
$params);
4042 $errorMsg =
'<strong>' . $this->getMessage() .
"</strong><br />\n";
isSendmail()
Send messages using $Sendmail.
static rfcDate()
Return an RFC 822 formatted date.
setLanguage($langcode='en', $lang_path='')
Set the language for error messages.
getBccAddresses()
Allows for public read access to 'bcc' property.
__construct($exceptions=null)
Constructor.
addStringAttachment( $string, $filename, $encoding='base64', $type='', $disposition='attachment')
Add a string or binary attachment (non-filesystem).
addCustomHeader($name, $value=null)
Add a custom header.
static isShellSafe($string)
Fix CVE-2016-10033 and CVE-2016-10045 by disallowing potentially unsafe shell characters.
postSend()
Actually send a message.
getReplyToAddresses()
Allows for public read access to 'ReplyTo' property.
mailSend($header, $body)
Send mail using the PHP mail() function.
getAttachments()
Return the array of attachments.
DKIM_Sign($signHeader)
Generate a DKIM signature.
alternativeExists()
Check if this message has an alternative body set.
DKIM_HeaderC($signHeader)
Generate a DKIM canonicalization header.
getCcAddresses()
Allows for public read access to 'cc' property.
addReplyTo($address, $name='')
Add a "Reply-To" address.
setFrom($address, $name='', $auto=true)
Set the From and FromName properties.
attachmentExists()
Check if an attachment (non-inline) is present.
inlineImageExists()
Check if an inline attachment is present.
getAllRecipientAddresses()
Allows for public read access to 'all_recipients' property.
serverHostname()
Get the server hostname.
encodeQ($str, $position='text')
Encode a string using Q encoding.
fixEOL($str)
Ensure consistent line endings in a string.
clearQueuedAddresses($kind)
Clear queued addresses of given kind.
clearCustomHeaders()
Clear all custom headers.
has8bitChars($text)
Does a string contain any 8-bit chars (in any charset)?
getMailMIME()
Get the message MIME type headers.
addCC($address, $name='')
Add a "CC" address.
const STOP_CRITICAL
Error severity: message, plus full stop, critical error reached.
clearAttachments()
Clear all filesystem, string, and binary attachments.
setMessageType()
Set the message type.
const CRLF
SMTP RFC standard line ending.
DKIM_Add($headers_line, $subject, $body)
Create the DKIM header and body in a new message header.
isMail()
Send messages using PHP's mail() function.
mailPassthru($to, $subject, $body, $header, $params)
Call mail() in a safe_mode-aware fashion.
lang($key)
Get an error message in the current language.
setWordWrap()
Apply word wrapping to the message body.
addAttachment($path, $name='', $encoding='base64', $type='', $disposition='attachment')
Add an attachment from a path on the filesystem.
clearCCs()
Clear all CC recipients.
encodeString($str, $encoding='base64')
Encode a string in requested format.
base64EncodeWrapMB($str, $linebreak=null)
Encode and wrap long multibyte strings for mail headers without breaking lines within a character.
addAddress($address, $name='')
Add a "To" address.
attachAll($disposition_type, $boundary)
Attach all file, string, and binary attachments to the message.
getTranslations()
Get the array of strings for the current language.
addrAppend($type, $addr)
Create recipient headers.
static mb_pathinfo($path, $options=null)
Multi-byte-safe pathinfo replacement.
smtpSend($header, $body)
Send mail via SMTP.
addStringEmbeddedImage( $string, $cid, $name='', $encoding='base64', $type='', $disposition='inline')
Add an embedded stringified attachment.
utf8CharBoundary($encodedText, $maxLength)
Find the last character boundary prior to $maxLength in a utf-8 quoted-printable encoded string.
clearReplyTos()
Clear all ReplyTo recipients.
msgHTML($message, $basedir='', $advanced=false)
Create a message body from an HTML string.
createBody()
Assemble the message body.
html2text($html, $advanced=false)
Convert an HTML string into plain text.
punyencodeAddress($address)
Converts IDN in given email address to its ASCII form, also known as punycode, if possible.
const STOP_MESSAGE
Error severity: message only, continue processing.
getBoundary($boundary, $charSet, $contentType, $encoding)
Return the start of a message boundary.
encodeFile($path, $encoding='base64')
Encode a file attachment in requested format.
endBoundary($boundary)
Return the end of a message boundary.
sign($cert_filename, $key_filename, $key_pass, $extracerts_filename='')
Set the public and private key files and password for S/MIME signing.
parseAddresses($addrstr, $useimap=true)
Parse and validate a string containing one or more RFC822-style comma-separated email addresses of th...
addEmbeddedImage($path, $cid, $name='', $encoding='base64', $type='', $disposition='inline')
Add an embedded (inline) attachment from a file.
clearAllRecipients()
Clear all recipient types.
clearBCCs()
Clear all BCC recipients.
secureHeader($str)
Strip newlines to prevent header injection.
DKIM_QP($txt)
Quoted-Printable-encode a DKIM header.
isQmail()
Send messages using qmail.
getCustomHeaders()
Returns all custom headers.
isSMTP()
Send messages using SMTP.
DKIM_BodyC($body)
Generate a DKIM canonicalization body.
isHTML($isHtml=true)
Sets message type to HTML or plain.
addAnAddress($kind, $address, $name='')
Add an address to one of the recipient arrays or to the ReplyTo array.
preSend()
Prepare a message for sending.
textLine($value)
Return a formatted mail line.
wrapText($message, $length, $qp_mode=false)
Word-wrap message.
encodeQP($string, $line_max=76)
Encode a string in quoted-printable format.
hasMultiBytes($str)
Check if a string contains multi-byte characters.
generateId()
Create unique ID.
static validateAddress($address, $patternselect=null)
Check that a string looks like an email address.
smtpClose()
Close the active SMTP session if one exists.
getLastMessageID()
Return the Message-ID header of the last email.
static _mime_types($ext='')
Get the MIME type for a file extension.
getSMTPInstance()
Get an instance to use for SMTP operations.
doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
Perform a callback.
setError($msg)
Add an error message to the error container.
const STOP_CONTINUE
Error severity: message, likely ok to continue processing.
encodeHeader($str, $position='text')
Encode a header string optimally.
headerLine($name, $value)
Format a header line.
encodeQPphp( $string, $line_max=76, $space_conv=false)
Backward compatibility wrapper for an old QP encoding function that was removed.
smtpConnect($options=null)
Initiate a connection to an SMTP server.
idnSupported()
Tells whether IDNs (Internationalized Domain Names) are supported or not.
static filenameToType($filename)
Map a file name to a MIME type.
createHeader()
Assemble message headers.
addrFormat($addr)
Format an address for use in a message header.
isError()
Check if an error occurred.
sendmailSend($header, $body)
Send mail using the $Sendmail program.
getSentMIMEMessage()
Returns the whole MIME message.
clearAddresses()
Clear all To recipients.
static normalizeBreaks($text, $breaktype="\r\n")
Normalize line breaks in a string.
getToAddresses()
Allows for public read access to 'to' property.
edebug($str)
Output debugging info via user-defined method.
addBCC($address, $name='')
Add a "BCC" address.
send()
Create a message and send it.
addOrEnqueueAnAddress($kind, $address, $name)
Add an address to one of the recipient arrays or to the ReplyTo array.
static hasLineLongerThanMax($str)
Detect if a string contains a line longer than the maximum line length allowed.
errorMessage()
Prettify error message output.
PHPMailer - PHP email creation and transport class.
$PHPMAILER_LANG['authenticate']
if(!is_array($argv)) $options
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']