73 public $From =
'root@localhost';
686 private function mailPassthru(
$to, $subject, $body, $header, $params)
689 if (ini_get(
'mbstring.func_overload') & 1) {
697 if (ini_get(
'safe_mode')
or !$this->UseSendmailOptions
or is_null($params)) {
698 $result = @mail(
$to, $subject, $body, $header);
700 $result = @mail(
$to, $subject, $body, $header, $params);
713 if ($this->SMTPDebug <= 0) {
717 if (!in_array($this->Debugoutput, array(
'error_log',
'html',
'echo'))
and is_callable($this->Debugoutput)) {
718 call_user_func($this->Debugoutput, $str, $this->SMTPDebug);
721 switch ($this->Debugoutput) {
729 preg_replace(
'/[\r\n]+/',
'', $str),
738 $str = preg_replace(
'/\r\n?/ms',
"\n", $str);
739 echo gmdate(
'Y-m-d H:i:s') .
"\t" . str_replace(
755 $this->ContentType =
'text/html';
757 $this->ContentType =
'text/plain';
767 $this->Mailer =
'smtp';
776 $this->Mailer =
'mail';
785 $ini_sendmail_path = ini_get(
'sendmail_path');
787 if (!stristr($ini_sendmail_path,
'sendmail')) {
788 $this->Sendmail =
'/usr/sbin/sendmail';
790 $this->Sendmail = $ini_sendmail_path;
792 $this->Mailer =
'sendmail';
801 $ini_sendmail_path = ini_get(
'sendmail_path');
803 if (!stristr($ini_sendmail_path,
'qmail')) {
804 $this->Sendmail =
'/var/qmail/bin/qmail-inject';
806 $this->Sendmail = $ini_sendmail_path;
808 $this->Mailer =
'qmail';
829 public function addCC($address, $name =
'')
841 public function addBCC($address, $name =
'')
871 $address = trim($address);
872 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
873 if (($pos = strrpos($address,
'@')) ===
false) {
875 $error_message = $this->
lang(
'invalid_address') .
" (addAnAddress $kind): $address";
877 $this->
edebug($error_message);
878 if ($this->exceptions) {
883 $params = array($kind, $address, $name);
886 if ($kind !=
'Reply-To') {
887 if (!array_key_exists($address, $this->RecipientsQueue)) {
888 $this->RecipientsQueue[$address] = $params;
892 if (!array_key_exists($address, $this->ReplyToQueue)) {
893 $this->ReplyToQueue[$address] = $params;
900 return call_user_func_array(array($this,
'addAnAddress'), $params);
915 if (!in_array($kind, array(
'to',
'cc',
'bcc',
'Reply-To'))) {
916 $error_message = $this->
lang(
'Invalid recipient kind: ') . $kind;
918 $this->
edebug($error_message);
919 if ($this->exceptions) {
925 $error_message = $this->
lang(
'invalid_address') .
" (addAnAddress $kind): $address";
927 $this->
edebug($error_message);
928 if ($this->exceptions) {
933 if ($kind !=
'Reply-To') {
934 if (!array_key_exists(strtolower($address), $this->all_recipients)) {
935 array_push($this->$kind, array($address, $name));
936 $this->all_recipients[strtolower($address)] =
true;
940 if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
941 $this->ReplyTo[strtolower($address)] = array($address, $name);
960 $addresses = array();
961 if ($useimap
and function_exists(
'imap_rfc822_parse_adrlist')) {
963 $list = imap_rfc822_parse_adrlist($addrstr,
'');
964 foreach ($list
as $address) {
965 if ($address->host !=
'.SYNTAX-ERROR.') {
966 if ($this->
validateAddress($address->mailbox .
'@' . $address->host)) {
967 $addresses[] = array(
968 'name' => (property_exists($address,
'personal') ? $address->personal :
''),
969 'address' => $address->mailbox .
'@' . $address->host
976 $list = explode(
',', $addrstr);
977 foreach ($list
as $address) {
978 $address = trim($address);
980 if (strpos($address,
'<') ===
false) {
983 $addresses[] = array(
985 'address' => $address
989 list($name, $email) = explode(
'<', $address);
990 $email = trim(str_replace(
'>',
'', $email));
992 $addresses[] = array(
993 'name' => trim(str_replace(array(
'"',
"'"),
'', $name)),
1011 public function setFrom($address, $name =
'', $auto =
true)
1013 $address = trim($address);
1014 $name = trim(preg_replace(
'/[\r\n]+/',
'', $name));
1016 if (($pos = strrpos($address,
'@')) ===
false or
1019 $error_message = $this->
lang(
'invalid_address') .
" (setFrom) $address";
1021 $this->
edebug($error_message);
1022 if ($this->exceptions) {
1027 $this->From = $address;
1028 $this->FromName = $name;
1030 if (
empty($this->Sender)) {
1031 $this->Sender = $address;
1070 if (is_null($patternselect)) {
1073 if (is_callable($patternselect)) {
1074 return call_user_func($patternselect, $address);
1077 if (strpos($address,
"\n") !==
false or strpos($address,
"\r") !==
false) {
1080 if (!$patternselect
or $patternselect ==
'auto') {
1083 if (defined(
'PCRE_VERSION')) {
1085 if (version_compare(PCRE_VERSION,
'8.0.3') >= 0) {
1086 $patternselect =
'pcre8';
1088 $patternselect =
'pcre';
1090 } elseif (function_exists(
'extension_loaded')
and extension_loaded(
'pcre')) {
1092 $patternselect =
'pcre';
1095 if (version_compare(PHP_VERSION,
'5.2.0') >= 0) {
1096 $patternselect =
'php';
1098 $patternselect =
'noregex';
1102 switch ($patternselect) {
1110 return (
boolean)preg_match(
1111 '/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)' .
1112 '((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?2)' .
1113 '(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)' .
1114 '([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*' .
1115 '(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)' .
1116 '(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}' .
1117 '|(?!(?:.*[a-f0-9][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:' .
1118 '|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
1119 '|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD',
1124 return (
boolean)preg_match(
1125 '/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>' .
1126 '[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")' .
1127 '(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*' .
1128 '@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})' .
1129 '(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:' .
1130 '[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?' .
1131 '::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:' .
1132 '[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?' .
1133 '::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}' .
1134 '|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD',
1142 return (
boolean)preg_match(
1143 '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}' .
1144 '[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/sD',
1150 return (strlen($address) >= 3
1151 and strpos($address,
'@') >= 1
1152 and strpos($address,
'@') != strlen($address) - 1);
1155 return (
boolean)filter_var($address, FILTER_VALIDATE_EMAIL);
1167 return function_exists(
'idn_to_ascii')
and function_exists(
'mb_convert_encoding');
1186 ($pos = strrpos($address,
'@')) !==
false) {
1187 $domain = substr($address, ++$pos);
1189 if ($this->
has8bitChars($domain)
and @mb_check_encoding($domain, $this->CharSet)) {
1190 $domain = mb_convert_encoding($domain,
'UTF-8', $this->CharSet);
1191 if (($punycode = defined(
'INTL_IDNA_VARIANT_UTS46') ?
1192 idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) :
1193 idn_to_ascii($domain)) !==
false) {
1194 return substr($address, 0, $pos) . $punycode;
1215 $this->mailHeader =
'';
1216 $this->
setError($exc->getMessage());
1217 if ($this->exceptions) {
1232 $this->error_count = 0;
1233 $this->mailHeader =
'';
1236 foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue)
as $params) {
1238 call_user_func_array(array($this,
'addAnAddress'), $params);
1240 if ((count($this->
to) + count($this->cc) + count($this->bcc)) < 1) {
1245 foreach (array(
'From',
'Sender',
'ConfirmReadingTo')
as $address_kind) {
1246 $this->$address_kind = trim($this->$address_kind);
1247 if (
empty($this->$address_kind)) {
1252 $error_message = $this->
lang(
'invalid_address') .
' (punyEncode) ' . $this->$address_kind;
1254 $this->
edebug($error_message);
1255 if ($this->exceptions) {
1264 $this->ContentType =
'multipart/alternative';
1269 if (!$this->AllowEmpty
and empty($this->Body)) {
1274 $this->MIMEHeader =
'';
1279 $this->MIMEHeader .= $tempheaders;
1283 if ($this->Mailer ==
'mail') {
1284 if (count($this->
to) > 0) {
1285 $this->mailHeader .= $this->
addrAppend(
'To', $this->
to);
1287 $this->mailHeader .= $this->
headerLine(
'To',
'undisclosed-recipients:;');
1296 if (!
empty($this->DKIM_domain)
1297 && !
empty($this->DKIM_selector)
1298 && (!
empty($this->DKIM_private_string)
1299 || (!
empty($this->DKIM_private) && file_exists($this->DKIM_private))
1303 $this->MIMEHeader . $this->mailHeader,
1307 $this->MIMEHeader = rtrim($this->MIMEHeader,
"\r\n ") . self::CRLF .
1308 str_replace(
"\r\n",
"\n", $header_dkim) .
self::CRLF;
1312 $this->
setError($exc->getMessage());
1313 if ($this->exceptions) {
1330 switch ($this->Mailer) {
1333 return $this->
sendmailSend($this->MIMEHeader, $this->MIMEBody);
1335 return $this->
smtpSend($this->MIMEHeader, $this->MIMEBody);
1337 return $this->
mailSend($this->MIMEHeader, $this->MIMEBody);
1339 $sendMethod = $this->Mailer.
'Send';
1340 if (method_exists($this, $sendMethod)) {
1341 return $this->$sendMethod($this->MIMEHeader, $this->MIMEBody);
1344 return $this->
mailSend($this->MIMEHeader, $this->MIMEBody);
1347 $this->
setError($exc->getMessage());
1348 $this->
edebug($exc->getMessage());
1349 if ($this->exceptions) {
1368 if (!
empty($this->Sender)
and self::isShellSafe($this->Sender)) {
1369 if ($this->Mailer ==
'qmail') {
1370 $sendmailFmt =
'%s -f%s';
1372 $sendmailFmt =
'%s -oi -f%s -t';
1375 if ($this->Mailer ==
'qmail') {
1376 $sendmailFmt =
'%s';
1378 $sendmailFmt =
'%s -oi -t';
1383 $sendmail = sprintf($sendmailFmt, escapeshellcmd($this->Sendmail), $this->Sender);
1385 if ($this->SingleTo) {
1386 foreach ($this->SingleToArray
as $toAddr) {
1387 if (!@$mail = popen($sendmail,
'w')) {
1390 fputs($mail,
'To: ' . $toAddr .
"\n");
1391 fputs($mail, $header);
1392 fputs($mail, $body);
1393 $result = pclose($mail);
1408 if (!@$mail = popen($sendmail,
'w')) {
1411 fputs($mail, $header);
1412 fputs($mail, $body);
1413 $result = pclose($mail);
1442 if (escapeshellcmd($string) !== $string
1443 or !in_array(escapeshellarg($string), array(
"'$string'",
"\"$string\""))
1448 $length = strlen($string);
1450 for ($i = 0; $i < $length; $i++) {
1456 if (!ctype_alnum($c) && strpos(
'@_-.', $c) ===
false) {
1476 foreach ($this->
to as $toaddr) {
1479 $to = implode(
', ', $toArr);
1485 if (self::isShellSafe($this->Sender)) {
1486 $params = sprintf(
'-f%s', $this->Sender);
1490 $old_from = ini_get(
'sendmail_from');
1491 ini_set(
'sendmail_from', $this->Sender);
1494 if ($this->SingleTo
and count($toArr) > 1) {
1495 foreach ($toArr
as $toAddr) {
1496 $result = $this->mailPassthru($toAddr, $this->Subject, $body, $header, $params);
1497 $this->
doCallback($result, array($toAddr), $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1500 $result = $this->mailPassthru(
$to, $this->Subject, $body, $header, $params);
1501 $this->
doCallback($result, $this->
to, $this->cc, $this->bcc, $this->Subject, $body, $this->From);
1503 if (isset($old_from)) {
1504 ini_set(
'sendmail_from', $old_from);
1519 if (!is_object($this->smtp)) {
1520 $this->smtp =
new SMTP;
1539 $bad_rcpt = array();
1548 if (!$this->smtp->mail($smtp_from)) {
1549 $this->
setError($this->
lang(
'from_failed') . $smtp_from .
' : ' . implode(
',', $this->smtp->getError()));
1554 foreach (array($this->
to, $this->cc, $this->bcc)
as $togroup) {
1555 foreach ($togroup
as $to) {
1556 if (!$this->smtp->recipient(
$to[0])) {
1557 $error = $this->smtp->getError();
1558 $bad_rcpt[] = array(
'to' =>
$to[0],
'error' => $error[
'detail']);
1563 $this->
doCallback($isSent, array(
$to[0]), array(), array(), $this->Subject, $body, $this->From);
1568 if ((count($this->all_recipients) > count($bad_rcpt))
and !$this->smtp->data($header . $body)) {
1571 if ($this->SMTPKeepAlive) {
1572 $this->smtp->reset();
1574 $this->smtp->quit();
1575 $this->smtp->close();
1578 if (count($bad_rcpt) > 0) {
1580 foreach ($bad_rcpt
as $bad) {
1581 $errstr .= $bad[
'to'] .
': ' . $bad[
'error'];
1584 $this->
lang(
'recipients_failed') . $errstr,
1602 if (is_null($this->smtp)) {
1607 if (is_null($options)) {
1612 if ($this->smtp->connected()) {
1616 $this->smtp->setTimeout($this->Timeout);
1617 $this->smtp->setDebugLevel($this->SMTPDebug);
1618 $this->smtp->setDebugOutput($this->Debugoutput);
1619 $this->smtp->setVerp($this->do_verp);
1620 $hosts = explode(
';', $this->Host);
1621 $lastexception =
null;
1623 foreach ($hosts
as $hostentry) {
1624 $hostinfo = array();
1626 '/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*|\[[a-fA-F0-9:]+\]):?([0-9]*)$/',
1631 $this->
edebug(
'Ignoring invalid host: ' . $hostentry);
1641 $tls = ($this->SMTPSecure ==
'tls');
1642 if (
'ssl' == $hostinfo[2]
or (
'' == $hostinfo[2]
and 'ssl' == $this->SMTPSecure)) {
1646 } elseif ($hostinfo[2] ==
'tls') {
1652 $sslext = defined(
'OPENSSL_ALGO_SHA1');
1653 if (
'tls' === $secure
or 'ssl' === $secure) {
1659 $host = $hostinfo[3];
1661 $tport = (integer)$hostinfo[4];
1662 if ($tport > 0
and $tport < 65536) {
1665 if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
1672 $this->smtp->hello($hello);
1678 if ($this->SMTPAutoTLS
and $sslext
and $secure !=
'ssl' and $this->smtp->getServerExt(
'STARTTLS')) {
1682 if (!$this->smtp->startTLS()) {
1686 $this->smtp->hello($hello);
1688 if ($this->SMTPAuth) {
1689 if (!$this->smtp->authenticate(
1702 $lastexception = $exc;
1703 $this->
edebug($exc->getMessage());
1705 $this->smtp->quit();
1710 $this->smtp->close();
1712 if ($this->exceptions
and !is_null($lastexception)) {
1713 throw $lastexception;
1724 if (is_a($this->smtp,
'SMTP')) {
1725 if ($this->smtp->connected()) {
1726 $this->smtp->quit();
1727 $this->smtp->close();
1744 $renamed_langcodes = array(
1753 if (isset($renamed_langcodes[$langcode])) {
1754 $langcode = $renamed_langcodes[$langcode];
1758 $PHPMAILER_LANG = array(
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;
1800 $this->language = $PHPMAILER_LANG;
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 $result .= $this->
headerLine(
'Date', $this->MessageDate ==
'' ? self::rfcDate() : $this->MessageDate);
2036 if ($this->SingleTo) {
2037 if ($this->Mailer !=
'mail') {
2038 foreach ($this->
to as $toaddr) {
2039 $this->SingleToArray[] = $this->
addrFormat($toaddr);
2043 if (count($this->
to) > 0) {
2044 if ($this->Mailer !=
'mail') {
2047 } elseif (count($this->cc) == 0) {
2048 $result .= $this->
headerLine(
'To',
'undisclosed-recipients:;');
2052 $result .= $this->
addrAppend(
'From', array(array(trim($this->From), $this->FromName)));
2055 if (count($this->cc) > 0) {
2056 $result .= $this->
addrAppend(
'Cc', $this->cc);
2061 $this->Mailer ==
'sendmail' or $this->Mailer ==
'qmail' or $this->Mailer ==
'mail'
2063 and count($this->bcc) > 0
2065 $result .= $this->
addrAppend(
'Bcc', $this->bcc);
2068 if (count($this->ReplyTo) > 0) {
2069 $result .= $this->
addrAppend(
'Reply-To', $this->ReplyTo);
2073 if ($this->Mailer !=
'mail') {
2079 if (
'' != $this->MessageID
and preg_match(
'/^<.*@.*>$/', $this->MessageID)) {
2082 $this->lastMessageID = sprintf(
'<%s@%s>', $this->uniqueid, $this->
serverHostname());
2084 $result .= $this->
headerLine(
'Message-ID', $this->lastMessageID);
2085 if (!is_null($this->Priority)) {
2086 $result .= $this->
headerLine(
'X-Priority', $this->Priority);
2088 if ($this->XMailer ==
'') {
2091 'PHPMailer ' . $this->
Version .
' (https://github.com/PHPMailer/PHPMailer)'
2094 $myXmailer = trim($this->XMailer);
2096 $result .= $this->
headerLine(
'X-Mailer', $myXmailer);
2100 if ($this->ConfirmReadingTo !=
'') {
2101 $result .= $this->
headerLine(
'Disposition-Notification-To',
'<' . $this->ConfirmReadingTo .
'>');
2105 foreach ($this->CustomHeader
as $header) {
2111 if (!$this->sign_key_file) {
2112 $result .= $this->
headerLine(
'MIME-Version',
'1.0');
2127 $ismultipart =
true;
2128 switch ($this->message_type) {
2130 $result .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2131 $result .= $this->
textLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
2134 case 'inline_attach':
2136 case 'alt_inline_attach':
2137 $result .= $this->
headerLine(
'Content-Type',
'multipart/mixed;');
2138 $result .= $this->
textLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
2142 $result .= $this->
headerLine(
'Content-Type',
'multipart/alternative;');
2143 $result .= $this->
textLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
2147 $result .= $this->
textLine(
'Content-Type: ' . $this->ContentType .
'; charset=' . $this->CharSet);
2148 $ismultipart =
false;
2152 if ($this->Encoding !=
'7bit') {
2155 if ($this->Encoding ==
'8bit') {
2156 $result .= $this->
headerLine(
'Content-Transfer-Encoding',
'8bit');
2160 $result .= $this->
headerLine(
'Content-Transfer-Encoding', $this->Encoding);
2164 if ($this->Mailer !=
'mail') {
2181 return rtrim($this->MIMEHeader . $this->mailHeader,
"\n\r") . self::CRLF . self::CRLF .
$this->MIMEBody;
2189 return md5(uniqid(
time()));
2208 if ($this->sign_key_file) {
2218 $bodyEncoding =
'7bit';
2220 $bodyCharSet =
'us-ascii';
2224 if (
'base64' != $this->Encoding
and self::hasLineLongerThanMax($this->Body)) {
2225 $bodyEncoding =
'quoted-printable';
2231 if ($altBodyEncoding ==
'8bit' and !$this->
has8bitChars($this->AltBody)) {
2232 $altBodyEncoding =
'7bit';
2234 $altBodyCharSet =
'us-ascii';
2238 if (
'base64' != $altBodyEncoding
and self::hasLineLongerThanMax($this->AltBody)) {
2239 $altBodyEncoding =
'quoted-printable';
2242 $mimepre =
"This is a multi-part message in MIME format." . $this->LE .
$this->LE;
2243 switch ($this->message_type) {
2246 $body .= $this->
getBoundary($this->boundary[1], $bodyCharSet,
'', $bodyEncoding);
2247 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2249 $body .= $this->
attachAll(
'inline', $this->boundary[1]);
2253 $body .= $this->
getBoundary($this->boundary[1], $bodyCharSet,
'', $bodyEncoding);
2254 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2256 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2258 case 'inline_attach':
2260 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2261 $body .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2262 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2264 $body .= $this->
getBoundary($this->boundary[2], $bodyCharSet,
'', $bodyEncoding);
2265 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2267 $body .= $this->
attachAll(
'inline', $this->boundary[2]);
2269 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2273 $body .= $this->
getBoundary($this->boundary[1], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2274 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2276 $body .= $this->
getBoundary($this->boundary[1], $bodyCharSet,
'text/html', $bodyEncoding);
2277 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2279 if (!
empty($this->Ical)) {
2280 $body .= $this->
getBoundary($this->boundary[1],
'',
'text/calendar; method=REQUEST',
'');
2281 $body .= $this->
encodeString($this->Ical, $this->Encoding);
2288 $body .= $this->
getBoundary($this->boundary[1], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2289 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2291 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2292 $body .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2293 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2295 $body .= $this->
getBoundary($this->boundary[2], $bodyCharSet,
'text/html', $bodyEncoding);
2296 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2298 $body .= $this->
attachAll(
'inline', $this->boundary[2]);
2304 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2305 $body .= $this->
headerLine(
'Content-Type',
'multipart/alternative;');
2306 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2308 $body .= $this->
getBoundary($this->boundary[2], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2309 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2311 $body .= $this->
getBoundary($this->boundary[2], $bodyCharSet,
'text/html', $bodyEncoding);
2312 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2316 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2318 case 'alt_inline_attach':
2320 $body .= $this->
textLine(
'--' . $this->boundary[1]);
2321 $body .= $this->
headerLine(
'Content-Type',
'multipart/alternative;');
2322 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[2] .
'"');
2324 $body .= $this->
getBoundary($this->boundary[2], $altBodyCharSet,
'text/plain', $altBodyEncoding);
2325 $body .= $this->
encodeString($this->AltBody, $altBodyEncoding);
2327 $body .= $this->
textLine(
'--' . $this->boundary[2]);
2328 $body .= $this->
headerLine(
'Content-Type',
'multipart/related;');
2329 $body .= $this->
textLine(
"\tboundary=\"" . $this->boundary[3] .
'"');
2331 $body .= $this->
getBoundary($this->boundary[3], $bodyCharSet,
'text/html', $bodyEncoding);
2332 $body .= $this->
encodeString($this->Body, $bodyEncoding);
2334 $body .= $this->
attachAll(
'inline', $this->boundary[3]);
2338 $body .= $this->
attachAll(
'attachment', $this->boundary[1]);
2343 $this->Encoding = $bodyEncoding;
2344 $body .= $this->
encodeString($this->Body, $this->Encoding);
2350 } elseif ($this->sign_key_file) {
2352 if (!defined(
'PKCS7_TEXT')) {
2356 $file = tempnam(sys_get_temp_dir(),
'mail');
2357 if (
false === file_put_contents($file, $body)) {
2360 $signed = tempnam(sys_get_temp_dir(),
'signed');
2362 if (
empty($this->sign_extracerts_file)) {
2363 $sign = @openssl_pkcs7_sign(
2366 'file://' . realpath($this->sign_cert_file),
2367 array(
'file://' . realpath($this->sign_key_file), $this->sign_key_pass),
2371 $sign = @openssl_pkcs7_sign(
2374 'file://' . realpath($this->sign_cert_file),
2375 array(
'file://' . realpath($this->sign_key_file), $this->sign_key_pass),
2378 $this->sign_extracerts_file
2383 $body = file_get_contents($signed);
2386 $parts = explode(
"\n\n", $body, 2);
2387 $this->MIMEHeader .= $parts[0] . $this->LE .
$this->LE;
2396 if ($this->exceptions) {
2416 if ($charSet ==
'') {
2419 if ($contentType ==
'') {
2422 if ($encoding ==
'') {
2426 $result .= sprintf(
'Content-Type: %s; charset=%s', $contentType, $charSet);
2429 if ($encoding !=
'7bit') {
2430 $result .= $this->
headerLine(
'Content-Transfer-Encoding', $encoding);
2466 $this->message_type = implode(
'_', $type);
2467 if ($this->message_type ==
'') {
2469 $this->message_type =
'plain';
2482 return $name .
': ' . $value .
$this->LE;
2508 public function addAttachment(
$path, $name =
'', $encoding =
'base64', $type =
'', $disposition =
'attachment')
2511 if (!@is_file(
$path)) {
2520 $filename = basename(
$path);
2525 $this->attachment[] = array(
2537 $this->
setError($exc->getMessage());
2538 $this->
edebug($exc->getMessage());
2539 if ($this->exceptions) {
2586 if (in_array($inclhash, $incl)) {
2589 $incl[] = $inclhash;
2595 if ($disposition ==
'inline' && array_key_exists($cid, $cidUniq)) {
2598 $cidUniq[$cid] =
true;
2600 $mime[] = sprintf(
'--%s%s',
$boundary, $this->LE);
2602 if (!
empty($name)) {
2604 'Content-Type: %s; name="%s"%s',
2611 'Content-Type: %s%s',
2617 if ($encoding !=
'7bit') {
2618 $mime[] = sprintf(
'Content-Transfer-Encoding: %s%s', $encoding, $this->LE);
2621 if ($disposition ==
'inline') {
2622 $mime[] = sprintf(
'Content-ID: <%s>%s', $cid, $this->LE);
2629 if (!(
empty($disposition))) {
2631 if (preg_match(
'/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) {
2633 'Content-Disposition: %s; filename="%s"%s',
2636 $this->LE . $this->LE
2639 if (!
empty($encoded_name)) {
2641 'Content-Disposition: %s; filename=%s%s',
2644 $this->LE . $this->LE
2648 'Content-Disposition: %s%s',
2650 $this->LE . $this->LE
2675 $mime[] = sprintf(
'--%s--%s',
$boundary, $this->LE);
2677 return implode(
'', $mime);
2692 if (!is_readable(
$path)) {
2695 $magic_quotes = get_magic_quotes_runtime();
2696 if ($magic_quotes) {
2697 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
2698 set_magic_quotes_runtime(
false);
2703 ini_set(
'magic_quotes_runtime',
false);
2706 $file_buffer = file_get_contents(
$path);
2707 $file_buffer = $this->
encodeString($file_buffer, $encoding);
2708 if ($magic_quotes) {
2709 if (version_compare(PHP_VERSION,
'5.3.0',
'<')) {
2710 set_magic_quotes_runtime($magic_quotes);
2712 ini_set(
'magic_quotes_runtime', $magic_quotes);
2715 return $file_buffer;
2716 }
catch (Exception $exc) {
2717 $this->
setError($exc->getMessage());
2733 switch (strtolower($encoding)) {
2735 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2739 $encoded = $this->
fixEOL($str);
2741 if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
2748 case 'quoted-printable':
2769 switch (strtolower($position)) {
2771 if (!preg_match(
'/[\200-\377]/', $str)) {
2773 $encoded = addcslashes($str,
"\0..\37\177\\\"");
2774 if (($str == $encoded) && !preg_match(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2777 return (
"\"$encoded\"");
2780 $matchcount = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $str, $matches);
2784 $matchcount = preg_match_all(
'/[()"]/', $str, $matches);
2788 $matchcount += preg_match_all(
'/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2793 if ($matchcount == 0) {
2797 $maxlen = 75 - 7 - strlen($this->CharSet);
2799 if ($matchcount > strlen($str) / 3) {
2802 if (function_exists(
'mb_strlen') && $this->
hasMultiBytes($str)) {
2807 $encoded = base64_encode($str);
2808 $maxlen -= $maxlen % 4;
2809 $encoded = trim(chunk_split($encoded, $maxlen,
"\n"));
2813 $encoded = $this->
encodeQ($str, $position);
2814 $encoded = $this->
wrapText($encoded, $maxlen,
true);
2815 $encoded = str_replace(
'=' . self::CRLF,
"\n", trim($encoded));
2818 $encoded = preg_replace(
'/^(.*)$/m',
' =?' . $this->CharSet .
"?$encoding?\\1?=", $encoded);
2819 $encoded = trim(str_replace(
"\n", $this->LE, $encoded));
2832 if (function_exists(
'mb_strlen')) {
2833 return (strlen($str) > mb_strlen($str, $this->CharSet));
2846 return (
boolean)preg_match(
'/[\x80-\xFF]/', $text);
2861 $start =
'=?' . $this->CharSet .
'?B?';
2864 if ($linebreak ===
null) {
2868 $mb_length = mb_strlen($str, $this->CharSet);
2870 $length = 75 - strlen($start) - strlen($end);
2872 $ratio = $mb_length / strlen($str);
2874 $avgLength = floor($length * $ratio * .75);
2876 for ($i = 0; $i < $mb_length; $i += $offset) {
2879 $offset = $avgLength - $lookBack;
2880 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2881 $chunk = base64_encode($chunk);
2883 }
while (strlen($chunk) > $length);
2884 $encoded .= $chunk . $linebreak;
2888 $encoded = substr($encoded, 0, -strlen($linebreak));
2904 if (function_exists(
'quoted_printable_encode')) {
2905 return quoted_printable_encode($string);
2908 $string = str_replace(
2909 array(
'%20',
'%0D%0A.',
'%0D%0A',
'%'),
2910 array(
' ',
"\r\n=2E",
"\r\n",
'='),
2911 rawurlencode($string)
2913 return preg_replace(
'/[^\r\n]{' . ($line_max - 3) .
'}[^=\r\n]{2}/',
"$0=\r\n", $string);
2928 $line_max = 76, $space_conv =
false
2931 return $this->
encodeQP($string, $line_max);
2946 $encoded = str_replace(array(
"\r",
"\n"),
'', $str);
2947 switch (strtolower($position)) {
2950 $pattern =
'^A-Za-z0-9!*+\/ -';
2955 $pattern =
'\(\)"';
2962 $pattern =
'\000-\011\013\014\016-\037\075\077\137\177-\377' . $pattern;
2966 if (preg_match_all(
"/[{$pattern}]/", $encoded, $matches)) {
2969 $eqkey = array_search(
'=', $matches[0]);
2970 if (
false !== $eqkey) {
2971 unset($matches[0][$eqkey]);
2972 array_unshift($matches[0],
'=');
2974 foreach (array_unique($matches[0])
as $char) {
2975 $encoded = str_replace($char,
'=' . sprintf(
'%02X', ord($char)), $encoded);
2979 return str_replace(
' ',
'_', $encoded);
2996 $encoding =
'base64',
2998 $disposition =
'attachment'
3005 $this->attachment[] = array(
3008 2 => basename($filename),
3036 if (!@is_file(
$path)) {
3046 $filename = basename(
$path);
3052 $this->attachment[] = array(
3083 $encoding =
'base64',
3085 $disposition =
'inline'
3088 if ($type ==
'' and !
empty($name)) {
3093 $this->attachment[] = array(
3141 return !
empty($this->AltBody);
3154 if ($params[0] == $kind) {
3155 unset($this->RecipientsQueue[$address]);
3167 unset($this->all_recipients[strtolower(
$to[0])]);
3169 $this->
to = array();
3179 foreach ($this->cc
as $cc) {
3180 unset($this->all_recipients[strtolower(
$cc[0])]);
3182 $this->cc = array();
3192 foreach ($this->bcc
as $bcc) {
3193 unset($this->all_recipients[strtolower(
$bcc[0])]);
3195 $this->bcc = array();
3205 $this->ReplyTo = array();
3206 $this->ReplyToQueue = array();
3215 $this->
to = array();
3216 $this->cc = array();
3217 $this->bcc = array();
3218 $this->all_recipients = array();
3219 $this->RecipientsQueue = array();
3228 $this->attachment = array();
3237 $this->CustomHeader = array();
3248 $this->error_count++;
3249 if ($this->Mailer ==
'smtp' and !is_null($this->smtp)) {
3250 $lasterror = $this->smtp->getError();
3251 if (!
empty($lasterror[
'error'])) {
3252 $msg .= $this->
lang(
'smtp_error') . $lasterror[
'error'];
3253 if (!
empty($lasterror[
'detail'])) {
3254 $msg .=
' Detail: '. $lasterror[
'detail'];
3256 if (!
empty($lasterror[
'smtp_code'])) {
3257 $msg .=
' SMTP code: ' . $lasterror[
'smtp_code'];
3259 if (!
empty($lasterror[
'smtp_code_ex'])) {
3260 $msg .=
' Additional SMTP info: ' . $lasterror[
'smtp_code_ex'];
3264 $this->ErrorInfo = $msg;
3277 date_default_timezone_set(@date_default_timezone_get());
3278 return date(
'D, j M Y H:i:s O');
3289 $result =
'localhost.localdomain';
3290 if (!
empty($this->Hostname)) {
3292 } elseif (isset($_SERVER)
and array_key_exists(
'SERVER_NAME', $_SERVER)
and !
empty($_SERVER[
'SERVER_NAME'])) {
3293 $result = $_SERVER[
'SERVER_NAME'];
3294 } elseif (function_exists(
'gethostname') && gethostname() !==
false) {
3295 $result = gethostname();
3296 } elseif (php_uname(
'n') !==
false) {
3297 $result = php_uname(
'n');
3310 if (count($this->language) < 1) {
3314 if (array_key_exists($key, $this->language)) {
3315 if ($key ==
'smtp_connect_failed') {
3319 return $this->language[$key] .
' https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting';
3321 return $this->language[$key];
3335 return ($this->error_count > 0);
3348 $nstr = str_replace(array(
"\r\n",
"\r"),
"\n", $str);
3350 if ($this->LE !==
"\n") {
3351 $nstr = str_replace(
"\n", $this->LE, $nstr);
3367 if ($value ===
null) {
3369 $this->CustomHeader[] = explode(
':', $name, 2);
3371 $this->CustomHeader[] = array($name, $value);
3400 public function msgHTML($message, $basedir =
'', $advanced =
false)
3402 preg_match_all(
'/(src|background)=["\'](.*)["\']/Ui', $message, $images);
3403 if (array_key_exists(2, $images)) {
3404 if (strlen($basedir) > 1 && substr($basedir, -1) !=
'/') {
3408 foreach ($images[2]
as $imgindex =>
$url) {
3410 if (preg_match(
'#^data:(image[^;,]*)(;base64)?,#',
$url, $match)) {
3411 $data = substr(
$url, strpos(
$url,
','));
3413 $data = base64_decode($data);
3415 $data = rawurldecode($data);
3417 $cid = md5(
$url) .
'@phpmailer.0';
3419 $message = str_replace(
3420 $images[0][$imgindex],
3421 $images[1][$imgindex] .
'="cid:' . $cid .
'"',
3431 && (strpos(
$url,
'..') ===
false)
3433 && substr(
$url, 0, 4) !==
'cid:'
3435 && !preg_match(
'#^[a-z][a-z0-9+.-]*:?//#i',
$url)
3437 $filename = basename(
$url);
3438 $directory = dirname(
$url);
3439 if ($directory ==
'.') {
3442 $cid = md5(
$url) .
'@phpmailer.0';
3443 if (strlen($directory) > 1 && substr($directory, -1) !=
'/') {
3447 $basedir . $directory . $filename,
3451 self::_mime_types((
string)self::mb_pathinfo($filename, PATHINFO_EXTENSION))
3454 $message = preg_replace(
3455 '/' . $images[1][$imgindex] .
'=["\']' . preg_quote(
$url,
'/') .
'["\']/Ui',
3456 $images[1][$imgindex] .
'="cid:' . $cid .
'"',
3468 $this->AltBody =
'To view this email message, open it in a program that understands HTML!' .
3496 if (is_callable($advanced)) {
3497 return call_user_func($advanced,
$html);
3499 return html_entity_decode(
3500 trim(strip_tags(preg_replace(
'/<(head|title|style|script)[^>]*>.*?<\/\\1>/si',
'',
$html))),
3516 'xl' =>
'application/excel',
3517 'js' =>
'application/javascript',
3518 'hqx' =>
'application/mac-binhex40',
3519 'cpt' =>
'application/mac-compactpro',
3520 'bin' =>
'application/macbinary',
3521 'doc' =>
'application/msword',
3522 'word' =>
'application/msword',
3523 'xlsx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3524 'xltx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
3525 'potx' =>
'application/vnd.openxmlformats-officedocument.presentationml.template',
3526 'ppsx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
3527 'pptx' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
3528 'sldx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slide',
3529 'docx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
3530 'dotx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
3531 'xlam' =>
'application/vnd.ms-excel.addin.macroEnabled.12',
3532 'xlsb' =>
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
3533 'class' =>
'application/octet-stream',
3534 'dll' =>
'application/octet-stream',
3535 'dms' =>
'application/octet-stream',
3536 'exe' =>
'application/octet-stream',
3537 'lha' =>
'application/octet-stream',
3538 'lzh' =>
'application/octet-stream',
3539 'psd' =>
'application/octet-stream',
3540 'sea' =>
'application/octet-stream',
3541 'so' =>
'application/octet-stream',
3542 'oda' =>
'application/oda',
3543 'pdf' =>
'application/pdf',
3544 'ai' =>
'application/postscript',
3545 'eps' =>
'application/postscript',
3546 'ps' =>
'application/postscript',
3547 'smi' =>
'application/smil',
3548 'smil' =>
'application/smil',
3549 'mif' =>
'application/vnd.mif',
3550 'xls' =>
'application/vnd.ms-excel',
3551 'ppt' =>
'application/vnd.ms-powerpoint',
3552 'wbxml' =>
'application/vnd.wap.wbxml',
3553 'wmlc' =>
'application/vnd.wap.wmlc',
3554 'dcr' =>
'application/x-director',
3555 'dir' =>
'application/x-director',
3556 'dxr' =>
'application/x-director',
3557 'dvi' =>
'application/x-dvi',
3558 'gtar' =>
'application/x-gtar',
3559 'php3' =>
'application/x-httpd-php',
3560 'php4' =>
'application/x-httpd-php',
3561 'php' =>
'application/x-httpd-php',
3562 'phtml' =>
'application/x-httpd-php',
3563 'phps' =>
'application/x-httpd-php-source',
3564 'swf' =>
'application/x-shockwave-flash',
3565 'sit' =>
'application/x-stuffit',
3566 'tar' =>
'application/x-tar',
3567 'tgz' =>
'application/x-tar',
3568 'xht' =>
'application/xhtml+xml',
3569 'xhtml' =>
'application/xhtml+xml',
3570 'zip' =>
'application/zip',
3571 'mid' =>
'audio/midi',
3572 'midi' =>
'audio/midi',
3573 'mp2' =>
'audio/mpeg',
3574 'mp3' =>
'audio/mpeg',
3575 'mpga' =>
'audio/mpeg',
3576 'aif' =>
'audio/x-aiff',
3577 'aifc' =>
'audio/x-aiff',
3578 'aiff' =>
'audio/x-aiff',
3579 'ram' =>
'audio/x-pn-realaudio',
3580 'rm' =>
'audio/x-pn-realaudio',
3581 'rpm' =>
'audio/x-pn-realaudio-plugin',
3582 'ra' =>
'audio/x-realaudio',
3583 'wav' =>
'audio/x-wav',
3584 'bmp' =>
'image/bmp',
3585 'gif' =>
'image/gif',
3586 'jpeg' =>
'image/jpeg',
3587 'jpe' =>
'image/jpeg',
3588 'jpg' =>
'image/jpeg',
3589 'png' =>
'image/png',
3590 'tiff' =>
'image/tiff',
3591 'tif' =>
'image/tiff',
3592 'eml' =>
'message/rfc822',
3593 'css' =>
'text/css',
3594 'html' =>
'text/html',
3595 'htm' =>
'text/html',
3596 'shtml' =>
'text/html',
3597 'log' =>
'text/plain',
3598 'text' =>
'text/plain',
3599 'txt' =>
'text/plain',
3600 'rtx' =>
'text/richtext',
3601 'rtf' =>
'text/rtf',
3602 'vcf' =>
'text/vcard',
3603 'vcard' =>
'text/vcard',
3604 'xml' =>
'text/xml',
3605 'xsl' =>
'text/xml',
3606 'mpeg' =>
'video/mpeg',
3607 'mpe' =>
'video/mpeg',
3608 'mpg' =>
'video/mpeg',
3609 'mov' =>
'video/quicktime',
3610 'qt' =>
'video/quicktime',
3611 'rv' =>
'video/vnd.rn-realvideo',
3612 'avi' =>
'video/x-msvideo',
3613 'movie' =>
'video/x-sgi-movie'
3615 if (array_key_exists(strtolower($ext), $mimes)) {
3616 return $mimes[strtolower($ext)];
3618 return 'application/octet-stream';
3631 $qpos = strpos($filename,
'?');
3632 if (
false !== $qpos) {
3633 $filename = substr($filename, 0, $qpos);
3652 $ret = array(
'dirname' =>
'',
'basename' =>
'',
'extension' =>
'',
'filename' =>
'');
3653 $pathinfo = array();
3654 if (preg_match(
'%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im',
$path, $pathinfo)) {
3655 if (array_key_exists(1, $pathinfo)) {
3656 $ret[
'dirname'] = $pathinfo[1];
3658 if (array_key_exists(2, $pathinfo)) {
3659 $ret[
'basename'] = $pathinfo[2];
3661 if (array_key_exists(5, $pathinfo)) {
3662 $ret[
'extension'] = $pathinfo[5];
3664 if (array_key_exists(3, $pathinfo)) {
3665 $ret[
'filename'] = $pathinfo[3];
3669 case PATHINFO_DIRNAME:
3671 return $ret[
'dirname'];
3672 case PATHINFO_BASENAME:
3674 return $ret[
'basename'];
3675 case PATHINFO_EXTENSION:
3677 return $ret[
'extension'];
3678 case PATHINFO_FILENAME:
3680 return $ret[
'filename'];
3700 public function set($name, $value =
'')
3702 if (property_exists($this, $name)) {
3703 $this->$name = $value;
3719 return trim(str_replace(array(
"\r",
"\n"),
'', $str));
3734 return preg_replace(
'/(\r\n|\r|\n)/ms', $breaktype, $text);
3745 public function sign($cert_filename, $key_filename, $key_pass, $extracerts_filename =
'')
3747 $this->sign_cert_file = $cert_filename;
3748 $this->sign_key_file = $key_filename;
3749 $this->sign_key_pass = $key_pass;
3750 $this->sign_extracerts_file = $extracerts_filename;
3762 for ($i = 0; $i < strlen($txt); $i++) {
3763 $ord = ord($txt[$i]);
3764 if (((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E))) {
3767 $line .=
'=' . sprintf(
'%02X', $ord);
3782 if (!defined(
'PKCS7_TEXT')) {
3783 if ($this->exceptions) {
3788 $privKeyStr = !
empty($this->DKIM_private_string) ? $this->DKIM_private_string : file_get_contents($this->DKIM_private);
3789 if (
'' != $this->DKIM_passphrase) {
3790 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
3792 $privKey = openssl_pkey_get_private($privKeyStr);
3796 if (version_compare(PHP_VERSION,
'5.3.0') >= 0
and
3797 in_array(
'sha256WithRSAEncryption', openssl_get_md_methods(
true))) {
3798 if (openssl_sign($signHeader, $signature, $privKey,
'sha256WithRSAEncryption')) {
3799 openssl_pkey_free($privKey);
3800 return base64_encode($signature);
3803 $pinfo = openssl_pkey_get_details($privKey);
3804 $hash = hash(
'sha256', $signHeader);
3807 $t =
'3031300d060960864801650304020105000420' .
$hash;
3808 $pslen = $pinfo[
'bits'] / 8 - (strlen($t) / 2 + 3);
3809 $eb = pack(
'H*',
'0001' . str_repeat(
'FF', $pslen) .
'00' . $t);
3811 if (openssl_private_encrypt($eb, $signature, $privKey, OPENSSL_NO_PADDING)) {
3812 openssl_pkey_free($privKey);
3813 return base64_encode($signature);
3816 openssl_pkey_free($privKey);
3828 $signHeader = preg_replace(
'/\r\n\s+/',
' ', $signHeader);
3829 $lines = explode(
"\r\n", $signHeader);
3830 foreach ($lines
as $key => $line) {
3831 list($heading, $value) = explode(
':', $line, 2);
3832 $heading = strtolower($heading);
3833 $value = preg_replace(
'/\s{2,}/',
' ', $value);
3834 $lines[$key] = $heading .
':' . trim($value);
3836 $signHeader = implode(
"\r\n", $lines);
3852 $body = str_replace(
"\r\n",
"\n", $body);
3853 $body = str_replace(
"\n",
"\r\n", $body);
3855 while (substr($body, strlen($body) - 4, 4) ==
"\r\n\r\n") {
3856 $body = substr($body, 0, strlen($body) - 2);
3869 public function DKIM_Add($headers_line, $subject, $body)
3871 $DKIMsignatureType =
'rsa-sha256';
3872 $DKIMcanonicalization =
'relaxed/simple';
3873 $DKIMquery =
'dns/txt';
3875 $subject_header =
"Subject: $subject";
3876 $headers = explode($this->LE, $headers_line);
3881 foreach ($headers
as $header) {
3882 if (strpos($header,
'From:') === 0) {
3883 $from_header = $header;
3884 $current =
'from_header';
3885 } elseif (strpos($header,
'To:') === 0) {
3886 $to_header = $header;
3887 $current =
'to_header';
3888 } elseif (strpos($header,
'Date:') === 0) {
3889 $date_header = $header;
3890 $current =
'date_header';
3892 if (!
empty($$current) && strpos($header,
' =?') === 0) {
3893 $$current .= $header;
3899 $from = str_replace(
'|',
'=7C', $this->
DKIM_QP($from_header));
3900 $to = str_replace(
'|',
'=7C', $this->
DKIM_QP($to_header));
3901 $date = str_replace(
'|',
'=7C', $this->
DKIM_QP($date_header));
3902 $subject = str_replace(
3905 $this->
DKIM_QP($subject_header)
3908 $DKIMlen = strlen($body);
3909 $DKIMb64 = base64_encode(pack(
'H*', hash(
'sha256', $body)));
3910 if (
'' == $this->DKIM_identity) {
3913 $ident =
' i=' . $this->DKIM_identity .
';';
3915 $dkimhdrs =
'DKIM-Signature: v=1; a=' .
3916 $DKIMsignatureType .
'; q=' .
3917 $DKIMquery .
'; l=' .
3919 $this->DKIM_selector .
3921 "\tt=" . $DKIMtime .
'; c=' . $DKIMcanonicalization .
";\r\n" .
3922 "\th=From:To:Date:Subject;\r\n" .
3923 "\td=" . $this->DKIM_domain .
';' . $ident .
"\r\n" .
3927 "\t|$subject;\r\n" .
3928 "\tbh=" . $DKIMb64 .
";\r\n" .
3931 $from_header .
"\r\n" .
3932 $to_header .
"\r\n" .
3933 $date_header .
"\r\n" .
3934 $subject_header .
"\r\n" .
3938 return $dkimhdrs . $signed .
"\r\n";
3950 return (
boolean)preg_match(
'/^(.{'.(self::MAX_LINE_LENGTH + 2).
',})/m', $str);
4020 if (!
empty($this->action_function) && is_callable($this->action_function)) {
4021 $params = array($isSent,
$to,
$cc,
$bcc, $subject, $body, $from);
4022 call_user_func_array($this->action_function, $params);
4039 $errorMsg =
'<strong>' . htmlspecialchars($this->getMessage()) .
"</strong><br />\n";