mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 09:26:35 +02:00
New phpmailer 1.7.2 merged from STABLE
This commit is contained in:
parent
3d1f31a563
commit
346d4eab7d
13 changed files with 413 additions and 230 deletions
|
@ -67,8 +67,8 @@ class PHPMailer
|
|||
var $FromName = "Root User";
|
||||
|
||||
/**
|
||||
* Sets the Sender email of the message. If not empty, will be sent via -f to sendmail
|
||||
* or as 'MAIL FROM' in smtp mode.
|
||||
* Sets the Sender email (Return-Path) of the message. If not empty,
|
||||
* will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
|
||||
* @var string
|
||||
*/
|
||||
var $Sender = "";
|
||||
|
@ -79,12 +79,6 @@ class PHPMailer
|
|||
*/
|
||||
var $Subject = "";
|
||||
|
||||
/**
|
||||
* Sets the Precedence level of this email. "bulk" will prevent some bounces
|
||||
* @var string
|
||||
*/
|
||||
var $Precedence = "";
|
||||
|
||||
/**
|
||||
* Sets the Body of the message. This can be either an HTML or text body.
|
||||
* If HTML then run IsHTML(true).
|
||||
|
@ -131,7 +125,7 @@ class PHPMailer
|
|||
* Holds PHPMailer version.
|
||||
* @var string
|
||||
*/
|
||||
var $Version = "1.70";
|
||||
var $Version = "1.72";
|
||||
|
||||
/**
|
||||
* Sets the email address that a reading confirmation will be sent.
|
||||
|
@ -147,7 +141,6 @@ class PHPMailer
|
|||
*/
|
||||
var $Hostname = "";
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// SMTP VARIABLES
|
||||
/////////////////////////////////////////////////
|
||||
|
@ -350,6 +343,7 @@ class PHPMailer
|
|||
function Send() {
|
||||
$header = "";
|
||||
$body = "";
|
||||
$result = true;
|
||||
|
||||
if((count($this->to) + count($this->cc) + count($this->bcc)) < 1)
|
||||
{
|
||||
|
@ -361,6 +355,7 @@ class PHPMailer
|
|||
if(!empty($this->AltBody))
|
||||
$this->ContentType = "multipart/alternative";
|
||||
|
||||
$this->error_count = 0; // reset errors
|
||||
$this->SetMessageType();
|
||||
$header .= $this->CreateHeader();
|
||||
$body = $this->CreateBody();
|
||||
|
@ -368,28 +363,24 @@ class PHPMailer
|
|||
if($body == "") { return false; }
|
||||
|
||||
// Choose the mailer
|
||||
if($this->Mailer == "sendmail")
|
||||
{
|
||||
if(!$this->SendmailSend($header, $body))
|
||||
return false;
|
||||
}
|
||||
elseif($this->Mailer == "mail")
|
||||
{
|
||||
if(!$this->MailSend($header, $body))
|
||||
return false;
|
||||
}
|
||||
elseif($this->Mailer == "smtp")
|
||||
{
|
||||
if(!$this->SmtpSend($header, $body))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
switch($this->Mailer)
|
||||
{
|
||||
case "sendmail":
|
||||
$result = $this->SendmailSend($header, $body);
|
||||
break;
|
||||
case "mail":
|
||||
$result = $this->MailSend($header, $body);
|
||||
break;
|
||||
case "smtp":
|
||||
$result = $this->SmtpSend($header, $body);
|
||||
break;
|
||||
default:
|
||||
$this->SetError($this->Mailer . $this->Lang("mailer_not_supported"));
|
||||
return false;
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,21 +419,20 @@ class PHPMailer
|
|||
* @return bool
|
||||
*/
|
||||
function MailSend($header, $body) {
|
||||
// Cannot add Bcc's to the $to
|
||||
$to = $this->to[0][0]; // no extra comma
|
||||
for($i = 1; $i < count($this->to); $i++)
|
||||
$to .= sprintf(",%s", $this->to[$i][0]);
|
||||
$to = "";
|
||||
for($i = 0; $i < count($this->to); $i++)
|
||||
{
|
||||
if($i != 0) { $to .= ", "; }
|
||||
$to .= $this->to[$i][0];
|
||||
}
|
||||
|
||||
if ($this->Sender != "" && PHP_VERSION >= "4.0")
|
||||
if ($this->Sender != "" && strlen(ini_get("safe_mode"))< 1)
|
||||
{
|
||||
$old_from = ini_get("sendmail_from");
|
||||
ini_set("sendmail_from", $this->Sender);
|
||||
}
|
||||
|
||||
if ($this->Sender != "" && PHP_VERSION >= "4.0.5")
|
||||
{
|
||||
$params = sprintf("-oi -f %s", $this->Sender);
|
||||
$rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header, $params);
|
||||
$rt = @mail($to, $this->EncodeHeader($this->Subject), $body,
|
||||
$header, $params);
|
||||
}
|
||||
else
|
||||
$rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header);
|
||||
|
@ -467,33 +457,12 @@ class PHPMailer
|
|||
* @return bool
|
||||
*/
|
||||
function SmtpSend($header, $body) {
|
||||
// Include SMTP class code, but not twice
|
||||
include_once($this->PluginDir . "class.smtp.php");
|
||||
$error = "";
|
||||
$bad_rcpt = array();
|
||||
|
||||
if($this->smtp == NULL)
|
||||
{
|
||||
if(!$this->SmtpConnect())
|
||||
return false;
|
||||
}
|
||||
|
||||
// Must perform HELO before authentication
|
||||
if ($this->Helo != '')
|
||||
$this->smtp->Hello($this->Helo);
|
||||
else
|
||||
$this->smtp->Hello($this->ServerHostname());
|
||||
|
||||
// If user requests SMTP authentication
|
||||
if($this->SMTPAuth)
|
||||
{
|
||||
if(!$this->smtp->Authenticate($this->Username, $this->Password))
|
||||
{
|
||||
$this->SetError($this->Lang("authenticate"));
|
||||
$this->smtp->Reset();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!$this->SmtpConnect())
|
||||
return false;
|
||||
|
||||
$smtp_from = ($this->Sender == "") ? $this->From : $this->Sender;
|
||||
if(!$this->smtp->Mail($smtp_from))
|
||||
|
@ -521,8 +490,7 @@ class PHPMailer
|
|||
$bad_rcpt[] = $this->bcc[$i][0];
|
||||
}
|
||||
|
||||
// Create error message
|
||||
if(count($bad_rcpt) > 0)
|
||||
if(count($bad_rcpt) > 0) // Create error message
|
||||
{
|
||||
for($i = 0; $i < count($bad_rcpt); $i++)
|
||||
{
|
||||
|
@ -575,7 +543,24 @@ class PHPMailer
|
|||
}
|
||||
|
||||
if($this->smtp->Connect($host, $port, $this->Timeout))
|
||||
{
|
||||
if ($this->Helo != '')
|
||||
$this->smtp->Hello($this->Helo);
|
||||
else
|
||||
$this->smtp->Hello($this->ServerHostname());
|
||||
|
||||
if($this->SMTPAuth)
|
||||
{
|
||||
if(!$this->smtp->Authenticate($this->Username,
|
||||
$this->Password))
|
||||
{
|
||||
$this->SetError($this->Lang("authenticate"));
|
||||
$this->smtp->Reset();
|
||||
$connection = false;
|
||||
}
|
||||
}
|
||||
$connection = true;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
if(!$connection)
|
||||
|
@ -608,7 +593,7 @@ class PHPMailer
|
|||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function SetLanguage($lang_type, $lang_path = "") {
|
||||
function SetLanguage($lang_type, $lang_path = "language/") {
|
||||
if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php'))
|
||||
include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
|
||||
else if(file_exists($lang_path.'phpmailer.lang-en.php'))
|
||||
|
@ -638,11 +623,9 @@ class PHPMailer
|
|||
if(count($addr) > 1)
|
||||
{
|
||||
for($i = 1; $i < count($addr); $i++)
|
||||
$addr_str .= sprintf(", %s", $this->AddrFormat($addr[$i]));
|
||||
$addr_str .= $this->LE;
|
||||
$addr_str .= ", " . $this->AddrFormat($addr[$i]);
|
||||
}
|
||||
else
|
||||
$addr_str .= $this->LE;
|
||||
$addr_str .= $this->LE;
|
||||
|
||||
return $addr_str;
|
||||
}
|
||||
|
@ -656,7 +639,10 @@ class PHPMailer
|
|||
if(empty($addr[1]))
|
||||
$formatted = $addr[0];
|
||||
else
|
||||
$formatted = sprintf('%s <%s>', $this->EncodeHeader($addr[1], 'phrase'), $addr[0]);
|
||||
{
|
||||
$formatted = $this->EncodeHeader($addr[1], 'phrase') . " <" .
|
||||
$addr[0] . ">";
|
||||
}
|
||||
|
||||
return $formatted;
|
||||
}
|
||||
|
@ -776,7 +762,6 @@ class PHPMailer
|
|||
$this->boundary[1] = "b1_" . $uniq_id;
|
||||
$this->boundary[2] = "b2_" . $uniq_id;
|
||||
|
||||
$result .= $this->Received();
|
||||
$result .= $this->HeaderLine("Date", $this->RFCDate());
|
||||
if($this->Sender == "")
|
||||
$result .= $this->HeaderLine("Return-Path", trim($this->From));
|
||||
|
@ -790,6 +775,8 @@ class PHPMailer
|
|||
$result .= $this->AddrAppend("To", $this->to);
|
||||
else if (count($this->cc) == 0)
|
||||
$result .= $this->HeaderLine("To", "undisclosed-recipients:;");
|
||||
if(count($this->cc) > 0)
|
||||
$result .= $this->AddrAppend("Cc", $this->cc);
|
||||
}
|
||||
|
||||
$from = array();
|
||||
|
@ -797,9 +784,6 @@ class PHPMailer
|
|||
$from[0][1] = $this->FromName;
|
||||
$result .= $this->AddrAppend("From", $from);
|
||||
|
||||
if(count($this->cc) > 0)
|
||||
$result .= $this->AddrAppend("Cc", $this->cc);
|
||||
|
||||
// sendmail and mail() extract Bcc from the header before sending
|
||||
if((($this->Mailer == "sendmail") || ($this->Mailer == "mail")) && (count($this->bcc) > 0))
|
||||
$result .= $this->AddrAppend("Bcc", $this->bcc);
|
||||
|
@ -815,10 +799,6 @@ class PHPMailer
|
|||
$result .= $this->HeaderLine("X-Priority", $this->Priority);
|
||||
$result .= $this->HeaderLine("X-Mailer", "PHPMailer [version " . $this->Version . "]");
|
||||
|
||||
if ($this->Precedence != "") {
|
||||
$result .= $this->HeaderLine("Precedence", $this->Precedence);
|
||||
}
|
||||
|
||||
if($this->ConfirmReadingTo != "")
|
||||
{
|
||||
$result .= $this->HeaderLine("Disposition-Notification-To",
|
||||
|
@ -843,7 +823,7 @@ class PHPMailer
|
|||
case "attachments":
|
||||
// fall through
|
||||
case "alt_attachments":
|
||||
if($this->EmbeddedImageCount() > 0)
|
||||
if($this->InlineImageExists())
|
||||
{
|
||||
$result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s",
|
||||
"multipart/related", $this->LE, $this->LE,
|
||||
|
@ -945,8 +925,9 @@ class PHPMailer
|
|||
if($encoding == "") { $encoding = $this->Encoding; }
|
||||
|
||||
$result .= $this->TextLine("--" . $boundary);
|
||||
$result .= sprintf("Content-Type: %s; charset = \"%s\"\n",
|
||||
$result .= sprintf("Content-Type: %s; charset = \"%s\"",
|
||||
$contentType, $charSet);
|
||||
$result .= $this->LE;
|
||||
$result .= $this->HeaderLine("Content-Transfer-Encoding", $encoding);
|
||||
$result .= $this->LE;
|
||||
|
||||
|
@ -1009,7 +990,7 @@ class PHPMailer
|
|||
* @param string $path Path to the attachment.
|
||||
* @param string $name Overrides the attachment name.
|
||||
* @param string $encoding File encoding (see $Encoding).
|
||||
* @param string $type File extension type.
|
||||
* @param string $type File extension (MIME) type.
|
||||
* @return bool
|
||||
*/
|
||||
function AddAttachment($path, $name = "", $encoding = "base64",
|
||||
|
@ -1024,7 +1005,6 @@ class PHPMailer
|
|||
if($name == "")
|
||||
$name = $filename;
|
||||
|
||||
// Append to $attachment array
|
||||
$cur = count($this->attachment);
|
||||
$this->attachment[$cur][0] = $path;
|
||||
$this->attachment[$cur][1] = $filename;
|
||||
|
@ -1127,22 +1107,18 @@ class PHPMailer
|
|||
// chunk_split is found in PHP >= 3.0.6
|
||||
$encoded = chunk_split(base64_encode($str), 76, $this->LE);
|
||||
break;
|
||||
|
||||
case "7bit":
|
||||
case "8bit":
|
||||
$encoded = $this->FixEOL($str);
|
||||
if (substr($encoded, -(strlen($this->LE))) != $this->LE)
|
||||
$encoded .= $this->LE;
|
||||
break;
|
||||
|
||||
case "binary":
|
||||
$encoded = $str;
|
||||
break;
|
||||
|
||||
case "quoted-printable":
|
||||
$encoded = $this->EncodeQP($str);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->SetError($this->Lang("encoding") . $encoding);
|
||||
break;
|
||||
|
@ -1262,7 +1238,7 @@ class PHPMailer
|
|||
* @param string $string String attachment data.
|
||||
* @param string $filename Name of the attachment.
|
||||
* @param string $encoding File encoding (see $Encoding).
|
||||
* @param string $type File extension type.
|
||||
* @param string $type File extension (MIME) type.
|
||||
* @return void
|
||||
*/
|
||||
function AddStringAttachment($string, $filename, $encoding = "base64",
|
||||
|
@ -1281,13 +1257,15 @@ class PHPMailer
|
|||
|
||||
/**
|
||||
* Adds an embedded attachment. This can include images, sounds, and
|
||||
* just about any other document.
|
||||
* just about any other document. Make sure to set the $type to an
|
||||
* image type. For JPEG images use "image/jpeg" and for GIF images
|
||||
* use "image/gif".
|
||||
* @param string $path Path to the attachment.
|
||||
* @param string $cid Content ID of the attachment. Use this to identify
|
||||
* the Id for accessing the image in an HTML form.
|
||||
* @param string $name Overrides the attachment name.
|
||||
* @param string $encoding File encoding (see $Encoding).
|
||||
* @param string $type File extension type.
|
||||
* @param string $type File extension (MIME) type.
|
||||
* @return bool
|
||||
*/
|
||||
function AddEmbeddedImage($path, $cid, $name = "", $encoding = "base64",
|
||||
|
@ -1318,16 +1296,19 @@ class PHPMailer
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the number of embedded images in an email.
|
||||
* Returns true if an inline attachment is present.
|
||||
* @access private
|
||||
* @return int
|
||||
* @return bool
|
||||
*/
|
||||
function EmbeddedImageCount() {
|
||||
$result = 0;
|
||||
function InlineImageExists() {
|
||||
$result = false;
|
||||
for($i = 0; $i < count($this->attachment); $i++)
|
||||
{
|
||||
if($this->attachment[$i][6] == "inline")
|
||||
$result++;
|
||||
{
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -1414,7 +1395,7 @@ class PHPMailer
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the proper RFC 822 formatted date. Returns string.
|
||||
* Returns the proper RFC 822 formatted date.
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
|
@ -1427,36 +1408,6 @@ class PHPMailer
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Received header for message tracing. Returns string.
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function Received() {
|
||||
if ($this->ServerVar('SERVER_NAME') != '')
|
||||
{
|
||||
$protocol = ($this->ServerVar('HTTPS') == 'on') ? 'HTTPS' : 'HTTP';
|
||||
$remote = $this->ServerVar('REMOTE_HOST');
|
||||
if($remote == "")
|
||||
$remote = 'phpmailer';
|
||||
$remote .= ' (['.$this->ServerVar('REMOTE_ADDR').'])';
|
||||
}
|
||||
else
|
||||
{
|
||||
$protocol = 'local';
|
||||
$remote = $this->ServerVar('USER');
|
||||
if($remote == '')
|
||||
$remote = 'phpmailer';
|
||||
}
|
||||
|
||||
$result = sprintf("Received: from %s %s\tby %s " .
|
||||
"with %s (PHPMailer);%s\t%s%s", $remote, $this->LE,
|
||||
$this->ServerHostname(), $protocol, $this->LE,
|
||||
$this->RFCDate(), $this->LE);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate server variable. Should work with both
|
||||
|
@ -1510,7 +1461,7 @@ class PHPMailer
|
|||
if(isset($this->language[$key]))
|
||||
return $this->language[$key];
|
||||
else
|
||||
return "";
|
||||
return "Language string failed to load: " . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1522,7 +1473,7 @@ class PHPMailer
|
|||
}
|
||||
|
||||
/**
|
||||
* Changes every end of line from CR or LF to CRLF. Returns string.
|
||||
* Changes every end of line from CR or LF to CRLF.
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
|
@ -1534,7 +1485,7 @@ class PHPMailer
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds a custom header. Returns void.
|
||||
* Adds a custom header.
|
||||
* @return void
|
||||
*/
|
||||
function AddCustomHeader($custom_header) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue