456 for ($i = 0; $i < count($this->to); $i++)
463 $to .= $this->to[$i][0];
466 if ($this->Sender !=
"" && strlen(ini_get(
"safe_mode")) < 1)
468 $old_from = ini_get(
"sendmail_from");
469 ini_set(
"sendmail_from", $this->Sender);
470 $params = sprintf(
"-oi -f %s", $this->Sender);
471 $rt = @mail($to, $this->
EncodeHeader($this->Subject), $body, $header, $params);
474 $rt = @mail($to, $this->
EncodeHeader($this->Subject), $body, $header);
476 if (isset($old_from))
477 ini_set(
"sendmail_from", $old_from);
497 include_once ($this->PluginDir .
"class.smtp.php");
505 $smtp_from = ($this->Sender ==
"") ? $this->From : $this->Sender;
507 if (!$this->smtp->Mail($smtp_from))
509 $error = $this->
Lang(
"from_failed") . $smtp_from;
511 $this->smtp->Reset();
516 for ($i = 0; $i < count($this->to); $i++)
518 if (!$this->smtp->Recipient($this->to[$i][0]))
519 $bad_rcpt[] = $this->to[$i][0];
522 for ($i = 0; $i < count($this->cc); $i++)
524 if (!$this->smtp->Recipient($this->cc[$i][0]))
525 $bad_rcpt[] = $this->cc[$i][0];
528 for ($i = 0; $i < count($this->bcc); $i++)
530 if (!$this->smtp->Recipient($this->bcc[$i][0]))
531 $bad_rcpt[] = $this->bcc[$i][0];
534 if (count($bad_rcpt) > 0)
536 for ($i = 0; $i < count($bad_rcpt); $i++)
543 $error .= $bad_rcpt[$i];
546 $error = $this->
Lang(
"recipients_failed") . $error;
548 $this->smtp->Reset();
552 if (!$this->smtp->Data($header . $body))
555 $this->smtp->Reset();
559 if ($this->SMTPKeepAlive ==
true)
560 $this->smtp->Reset();
575 if ($this->smtp == NULL)
577 $this->smtp =
new SMTP();
580 $this->smtp->do_debug = $this->SMTPDebug;
581 $hosts = explode(
";", $this->Host);
583 $connection = ($this->smtp->Connected());
586 while ($index < count($hosts) && $connection ==
false)
588 if (strstr($hosts[$index],
":"))
589 list($host, $port) = explode(
":", $hosts[$index]);
592 $host = $hosts[$index];
596 if ($this->smtp->Connect($host, $port, $this->Timeout))
598 if ($this->Helo !=
'')
599 $this->smtp->Hello($this->Helo);
605 if (!$this->smtp->Authenticate($this->Username, $this->Password))
608 $this->smtp->Reset();
718 function WrapText($message, $length, $qp_mode =
false)
720 $soft_break = ($qp_mode) ? sprintf(
" =%s", $this->LE) : $this->LE;
722 $message = $this->
FixEOL($message);
724 if (substr($message, -1) == $this->LE)
725 $message = substr($message, 0, -1);
727 $line = explode($this->LE, $message);
730 for ($i = 0; $i < count($line); $i++)
732 $line_part = explode(
" ", $line[$i]);
735 for ($e = 0; $e < count($line_part); $e++)
737 $word = $line_part[$e];
739 if ($qp_mode and (strlen($word) > $length))
741 $space_left = $length - strlen($buf) - 1;
745 if ($space_left > 20)
749 if (substr($word, $len - 1, 1) ==
"=")
752 elseif (substr($word, $len - 2, 1) ==
"=")
755 $part = substr($word, 0, $len);
756 $word = substr($word, $len);
758 $message .= $buf . sprintf(
"=%s", $this->LE);
762 $message .= $buf . $soft_break;
768 while (strlen($word) > 0)
772 if (substr($word, $len - 1, 1) ==
"=")
775 elseif (substr($word, $len - 2, 1) ==
"=")
778 $part = substr($word, 0, $len);
779 $word = substr($word, $len);
781 if (strlen($word) > 0)
782 $message .= $part . sprintf(
"=%s", $this->LE);
790 $buf .= ($e == 0) ? $word : (
" " . $word);
792 if (strlen($buf) > $length and $buf_o !=
"")
794 $message .= $buf_o . $soft_break;
800 $message .= $buf . $this->LE;
842 $uniq_id = md5(uniqid(time()));
843 $this->boundary[1] =
"b1_" . $uniq_id;
844 $this->boundary[2] =
"b2_" . $uniq_id;
849 if ($this->Sender ==
"")
850 $result .= $this->
HeaderLine(
"Return-Path", trim($this->From));
852 $result .= $this->
HeaderLine(
"Return-Path", trim($this->Sender));
855 if ($this->Mailer !=
"mail")
857 if (count($this->to) > 0)
858 $result .= $this->
AddrAppend(
"To", $this->to);
860 else if (count($this->cc) == 0)
861 $result .= $this->
HeaderLine(
"To",
"undisclosed-recipients:;");
863 if (count($this->cc) > 0)
864 $result .= $this->
AddrAppend(
"Cc", $this->cc);
870 $from[0][0] = trim($this->From);
871 $from[0][1] = $this->FromName;
875 if ((($this->Mailer ==
"sendmail") || ($this->Mailer ==
"mail")) && (count($this->bcc) > 0))
876 $result .= $this->
AddrAppend(
"Bcc", $this->bcc);
878 if (count($this->ReplyTo) > 0)
879 $result .= $this->
AddrAppend(
"Reply-to", $this->ReplyTo);
882 if ($this->Mailer !=
"mail")
885 $result .= sprintf(
"Message-ID: <%s@%s>%s", $uniq_id, $this->
ServerHostname(), $this->LE);
886 $result .= $this->
HeaderLine(
"X-Priority", $this->Priority);
887 $result .= $this->
HeaderLine(
"X-Mailer",
"PHPMailer [version " . $this->Version .
"]");
889 if ($this->ConfirmReadingTo !=
"")
891 $result .= $this->
HeaderLine(
"Disposition-Notification-To",
"<" . trim($this->ConfirmReadingTo) .
">");
895 for ($index = 0; $index < count($this->CustomHeader); $index++)
897 $result .= $this->
HeaderLine(trim($this->CustomHeader[$index][0]),
898 $this->
EncodeHeader(trim($this->CustomHeader[$index][1])));
901 $result .= $this->
HeaderLine(
"MIME-Version",
"1.0");
903 switch ($this->message_type)
906 $result .= $this->
HeaderLine(
"Content-Transfer-Encoding", $this->Encoding);
908 $result .= sprintf(
"Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
913 case "alt_attachments":
916 $result .= sprintf(
"Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
925 $result .= $this->
HeaderLine(
"Content-Type",
"multipart/mixed;");
926 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
932 $result .= $this->
HeaderLine(
"Content-Type",
"multipart/alternative;");
934 $result .= $this->
TextLine(
"\tboundary=\"" . $this->boundary[1] .
'"');
938 if ($this->Mailer !=
"mail")
939 $result .= $this->LE . $this->LE;
955 switch ($this->message_type)
958 $result .= $this->
GetBoundary($this->boundary[1],
"",
"text/plain",
"");
960 $result .= $this->
EncodeString($this->AltBody, $this->Encoding);
961 $result .= $this->LE . $this->LE;
962 $result .= $this->
GetBoundary($this->boundary[1],
"",
"text/html",
"");
964 $result .= $this->
EncodeString($this->Body, $this->Encoding);
965 $result .= $this->LE . $this->LE;
971 $result .= $this->
EncodeString($this->Body, $this->Encoding);
976 $result .= $this->
GetBoundary($this->boundary[1],
"",
"",
"");
978 $result .= $this->
EncodeString($this->Body, $this->Encoding);
979 $result .= $this->LE;
984 case "alt_attachments":
985 $result .= sprintf(
"--%s%s", $this->boundary[1], $this->LE);
987 $result .= sprintf(
"Content-Type: %s;%s" .
"\tboundary=\"%s\"%s",
"multipart/alternative", $this->LE,
988 $this->boundary[2], $this->LE . $this->LE);
991 $result .= $this->
GetBoundary($this->boundary[2],
"",
"text/plain",
"") . $this->LE;
993 $result .= $this->
EncodeString($this->AltBody, $this->Encoding);
994 $result .= $this->LE . $this->LE;
997 $result .= $this->
GetBoundary($this->boundary[2],
"",
"text/html",
"") . $this->LE;
999 $result .= $this->
EncodeString($this->Body, $this->Encoding);
1000 $result .= $this->LE . $this->LE;
1002 $result .= $this->
EndBoundary($this->boundary[2]);
1024 $charSet = $this->CharSet;
1027 if ($contentType ==
"")
1029 $contentType = $this->ContentType;
1032 if ($encoding ==
"")
1034 $encoding = $this->Encoding;
1037 $result .= $this->
TextLine(
"--" . $boundary);
1038 $result .= sprintf(
"Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1039 $result .= $this->LE;
1040 $result .= $this->
HeaderLine(
"Content-Transfer-Encoding", $encoding);
1041 $result .= $this->LE;
1111 function AddAttachment($path, $name =
"", $encoding =
"base64", $type =
"application/octet-stream")
1113 if (!@is_file($path))
1119 $filename = basename($path);
1124 $cur = count($this->attachment);
1125 $this->attachment[$cur][0] = $path;
1126 $this->attachment[$cur][1] = $filename;
1127 $this->attachment[$cur][2] = $name;
1128 $this->attachment[$cur][3] = $encoding;
1129 $this->attachment[$cur][4] = $type;
1130 $this->attachment[$cur][5] =
false;
1131 $this->attachment[$cur][6] =
"attachment";
1132 $this->attachment[$cur][7] = 0;
1150 for ($i = 0; $i < count($this->attachment); $i++)
1153 $bString = $this->attachment[$i][5];
1156 $string = $this->attachment[$i][0];
1158 $path = $this->attachment[$i][0];
1160 $filename = $this->attachment[$i][1];
1161 $name = $this->attachment[$i][2];
1162 $encoding = $this->attachment[$i][3];
1163 $type = $this->attachment[$i][4];
1164 $disposition = $this->attachment[$i][6];
1165 $cid = $this->attachment[$i][7];
1167 $mime[] = sprintf(
"--%s%s", $this->boundary[1], $this->LE);
1168 $mime[] = sprintf(
"Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
1169 $mime[] = sprintf(
"Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1171 if ($disposition ==
"inline")
1172 $mime[] = sprintf(
"Content-ID: <%s>%s", $cid, $this->LE);
1174 $mime[] = sprintf(
"Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE . $this->LE);
1186 $mime[] = $this->LE . $this->LE;
1190 $mime[] = $this->
EncodeFile($path, $encoding);
1197 $mime[] = $this->LE . $this->LE;
1201 $mime[] = sprintf(
"--%s--%s", $this->boundary[1], $this->LE);
1203 return join(
"", $mime);
1282 switch (strtolower($position))
1285 if (!preg_match(
'/[\200-\377]/', $str))
1288 $encoded = addcslashes($str,
"\0..\37\177\\\"");
1290 if (($str == $encoded) && !preg_match(
'/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str))
1293 return (
"\"$encoded\"");
1296 $x = preg_match_all(
'/[^\040\041\043-\133\135-\176]/', $str, $matches);
1299 case 'comment': $x = preg_match_all(
'/[()"]/', $str, $matches);
1304 $x += preg_match_all(
'/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1312 $maxlen = 75 - 7 - strlen($this->CharSet);
1315 if (strlen($str) / 3 < $x)
1318 $encoded = base64_encode($str);
1319 $maxlen -= $maxlen % 4;
1320 $encoded = trim(chunk_split($encoded, $maxlen,
"\n"));
1325 $encoded = $this->
EncodeQ($str, $position);
1326 $encoded = $this->
WrapText($encoded, $maxlen,
true);
1327 $encoded = str_replace(
"=" . $this->LE,
"\n", trim($encoded));
1330 $encoded = preg_replace(
'/^(.*)$/m',
" =?" . $this->CharSet .
"?$encoding?\\1?=", $encoded);
1331 $encoded = trim(str_replace(
"\n", $this->LE, $encoded));
1410 $cur = count($this->attachment);
1411 $this->attachment[$cur][0] = $string;
1412 $this->attachment[$cur][1] = $filename;
1413 $this->attachment[$cur][2] = $filename;
1414 $this->attachment[$cur][3] = $encoding;
1415 $this->attachment[$cur][4] = $type;
1416 $this->attachment[$cur][5] =
true;
1417 $this->attachment[$cur][6] =
"attachment";
1418 $this->attachment[$cur][7] = 0;
1434 function AddEmbeddedImage($path, $cid, $name =
"", $encoding =
"base64", $type =
"application/octet-stream")
1436 if (!@is_file($path))
1442 $filename = basename($path);
1448 $cur = count($this->attachment);
1449 $this->attachment[$cur][0] = $path;
1450 $this->attachment[$cur][1] = $filename;
1451 $this->attachment[$cur][2] = $name;
1452 $this->attachment[$cur][3] = $encoding;
1453 $this->attachment[$cur][4] = $type;
1454 $this->attachment[$cur][5] =
false;
1455 $this->attachment[$cur][6] =
"inline";
1456 $this->attachment[$cur][7] = $cid;