Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #543 from mbabker/phpmailer

Update PHPMailer to version 5.2
  • Loading branch information...
commit 30f5a2369fb2c7ed48ca222afe13211fcfc5935c 2 parents 588c45d + 9bf7fcc
@eddieajau eddieajau authored
View
23 libraries/phpmailer/language/phpmailer.lang-en.php
@@ -1,23 +0,0 @@
-<?php
-/**
- * PHPMailer language file.
- * English Version
- */
-
-$PHPMAILER_LANG = array();
-
-$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
- 'recipient email address.';
-$PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
-$PHPMAILER_LANG["execute"] = 'Could not execute: ';
-$PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
-$PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
-$PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
-$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
- 'recipients failed: ';
-$PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
-$PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
-$PHPMAILER_LANG["file_access"] = 'Could not access file: ';
-$PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
-$PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
-$PHPMAILER_LANG["signing"] = 'Signing Error: ';
View
24 libraries/phpmailer/language/phpmailer.lang-joomla.php
@@ -7,22 +7,22 @@
// no direct access
defined('JPATH_PLATFORM') or die;
-$PHPMAILER_LANG["provide_address"] = JText::_('PHPMAILER_PROVIDE_ADDRESS');
-$PHPMAILER_LANG["mailer_not_supported"] = JText::_('PHPMAILER_MAILER_IS_NOT_SUPPORTED');
-$PHPMAILER_LANG["execute"] = JText::_('PHPMAILER_EXECUTE');
-$PHPMAILER_LANG["instantiate"] = JText::_('PHPMAILER_INSTANTIATE');
$PHPMAILER_LANG["authenticate"] = JText::_('PHPMAILER_AUTHENTICATE');
-$PHPMAILER_LANG["from_failed"] = JText::_('PHPMAILER_FROM_FAILED');
-$PHPMAILER_LANG["recipients_failed"] = JText::_('PHPMAILER_RECIPIENTS_FAILED');
-$PHPMAILER_LANG["data_not_accepted"] = JText::_('PHPMAILER_DATA_NOT_ACCEPTED');
$PHPMAILER_LANG["connect_host"] = JText::_('PHPMAILER_CONNECT_HOST');
+$PHPMAILER_LANG["data_not_accepted"] = JText::_('PHPMAILER_DATA_NOT_ACCEPTED');
+$PHPMAILER_LANG['empty_message'] = JText::_('PHPMAILER_EMPTY_MESSAGE');
+$PHPMAILER_LANG["encoding"] = JText::_('PHPMAILER_ENCODING');
+$PHPMAILER_LANG["execute"] = JText::_('PHPMAILER_EXECUTE');
$PHPMAILER_LANG["file_access"] = JText::_('PHPMAILER_FILE_ACCESS');
$PHPMAILER_LANG["file_open"] = JText::_('PHPMAILER_FILE_OPEN');
-$PHPMAILER_LANG["encoding"] = JText::_('PHPMAILER_ENCODING');
-$PHPMAILER_LANG["signing"] = JText::_('PHPMAILER_SIGNING_ERROR');
-$PHPMAILER_LANG['smtp_error'] = JText::_('PHPMAILER_SMTP_ERROR');
-$PHPMAILER_LANG['empty_message'] = JText::_('PHPMAILER_EMPTY_MESSAGE');
+$PHPMAILER_LANG["from_failed"] = JText::_('PHPMAILER_FROM_FAILED');
+$PHPMAILER_LANG["instantiate"] = JText::_('PHPMAILER_INSTANTIATE');
$PHPMAILER_LANG['invalid_address'] = JText::_('PHPMAILER_INVALID_ADDRESS');
-$PHPMAILER_LANG['variable_set'] = JText::_('PHPMAILER_VARIABLE_SET');
+$PHPMAILER_LANG["mailer_not_supported"] = JText::_('PHPMAILER_MAILER_IS_NOT_SUPPORTED');
+$PHPMAILER_LANG["provide_address"] = JText::_('PHPMAILER_PROVIDE_ADDRESS');
+$PHPMAILER_LANG["recipients_failed"] = JText::_('PHPMAILER_RECIPIENTS_FAILED');
+$PHPMAILER_LANG["signing"] = JText::_('PHPMAILER_SIGNING_ERROR');
$PHPMAILER_LANG['smtp_connect_failed'] = JText::_('PHPMAILER_SMTP_CONNECT_FAILED');
+$PHPMAILER_LANG['smtp_error'] = JText::_('PHPMAILER_SMTP_ERROR');
$PHPMAILER_LANG['tls'] = JText::_('PHPMAILER_TLS');
+$PHPMAILER_LANG['variable_set'] = JText::_('PHPMAILER_VARIABLE_SET');
View
761 libraries/phpmailer/phpmailer.php
@@ -2,15 +2,15 @@
/*~ class.phpmailer.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
-| Version: 5.1 |
-| Contact: via sourceforge.net support pages (also www.worxware.com) |
-| Info: http://phpmailer.sourceforge.net |
-| Support: http://sourceforge.net/projects/phpmailer/ |
+| Version: 5.2 |
+| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
| ------------------------------------------------------------------------- |
-| Admin: Andy Prevost (project admininistrator) |
+| Admin: Jim Jagielski (project admininistrator) |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
+| : Jim Jagielski (jimjag) jimjag@gmail.com |
| Founder: Brent R. Matzelle (original founder) |
+| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved. |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
@@ -19,11 +19,6 @@
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
-| ------------------------------------------------------------------------- |
-| We offer a number of paid services (www.worxware.com): |
-| - Web Hosting on highly optimized fast and secure servers |
-| - Technology Consulting |
-| - Oursourcing (highly qualified programmers and graphic designers) |
'---------------------------------------------------------------------------'
*/
@@ -33,8 +28,10 @@
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
+ * @author Jim Jagielski
+ * @copyright 2010 - 2011 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
- * @version $Id$
+ * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
@@ -119,6 +116,20 @@ class PHPMailer {
public $AltBody = '';
/**
+ * Stores the complete compiled MIME message body.
+ * @var string
+ * @access protected
+ */
+ protected $MIMEBody = '';
+
+ /**
+ * Stores the complete compiled MIME message headers.
+ * @var string
+ * @access protected
+ */
+ protected $MIMEHeader = '';
+
+ /**
* Sets word wrapping on the body of the message to a given number of
* characters.
* @var int
@@ -163,7 +174,7 @@ class PHPMailer {
* If empty, a unique id will be generated.
* @var string
*/
- public $MessageID = '';
+ public $MessageID = '';
/////////////////////////////////////////////////
// PROPERTIES FOR SMTP
@@ -177,19 +188,19 @@ class PHPMailer {
* Hosts will be tried in order.
* @var string
*/
- public $Host = 'localhost';
+ public $Host = 'localhost';
/**
* Sets the default SMTP server port.
* @var int
*/
- public $Port = 25;
+ public $Port = 25;
/**
* Sets the SMTP HELO of the message (Default is $Hostname).
* @var string
*/
- public $Helo = '';
+ public $Helo = '';
/**
* Sets connection prefix.
@@ -202,32 +213,32 @@ class PHPMailer {
* Sets SMTP authentication. Utilizes the Username and Password variables.
* @var bool
*/
- public $SMTPAuth = false;
+ public $SMTPAuth = false;
/**
* Sets SMTP username.
* @var string
*/
- public $Username = '';
+ public $Username = '';
/**
* Sets SMTP password.
* @var string
*/
- public $Password = '';
+ public $Password = '';
/**
* Sets the SMTP server timeout in seconds.
* This function will not work with the win32 version.
* @var int
*/
- public $Timeout = 10;
+ public $Timeout = 10;
/**
* Sets SMTP class debugging on or off.
* @var bool
*/
- public $SMTPDebug = false;
+ public $SMTPDebug = false;
/**
* Prevents the SMTP connection from being closed after each mail
@@ -242,9 +253,9 @@ class PHPMailer {
* emails, instead of sending to entire TO addresses
* @var bool
*/
- public $SingleTo = false;
+ public $SingleTo = false;
- /**
+ /**
* If SingleTo is true, this provides the array to hold the email addresses
* @var bool
*/
@@ -271,6 +282,12 @@ class PHPMailer {
/**
* Used with DKIM DNS Resource Record
+ * @var string
+ */
+ public $DKIM_passphrase = '';
+
+ /**
+ * Used with DKIM DNS Resource Record
* optional, in format of email address 'you@yourdomain.com'
* @var string
*/
@@ -300,28 +317,34 @@ class PHPMailer {
* Sets the PHPMailer Version number
* @var string
*/
- public $Version = '5.1';
+ public $Version = '5.2';
+
+ /**
+ * What to use in the X-Mailer header
+ * @var string
+ */
+ public $XMailer = '';
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
- private $smtp = NULL;
- private $to = array();
- private $cc = array();
- private $bcc = array();
- private $ReplyTo = array();
- private $all_recipients = array();
- private $attachment = array();
- private $CustomHeader = array();
- private $message_type = '';
- private $boundary = array();
- protected $language = array();
- private $error_count = 0;
- private $sign_cert_file = "";
- private $sign_key_file = "";
- private $sign_key_pass = "";
- private $exceptions = false;
+ protected $smtp = NULL;
+ protected $to = array();
+ protected $cc = array();
+ protected $bcc = array();
+ protected $ReplyTo = array();
+ protected $all_recipients = array();
+ protected $attachment = array();
+ protected $CustomHeader = array();
+ protected $message_type = '';
+ protected $boundary = array();
+ protected $language = array();
+ protected $error_count = 0;
+ protected $sign_cert_file = '';
+ protected $sign_key_file = '';
+ protected $sign_key_pass = '';
+ protected $exceptions = false;
/////////////////////////////////////////////////
// CONSTANTS
@@ -389,9 +412,9 @@ public function IsSendmail() {
*/
public function IsQmail() {
if (stristr(ini_get('sendmail_path'), 'qmail')) {
- $this->Sendmail = '/var/qmail/bin/sendmail';
+ $this->Sendmail = '/var/qmail/bin/sendmail';
}
- $this->Mailer = 'sendmail';
+ $this->Mailer = 'sendmail';
}
/////////////////////////////////////////////////
@@ -447,11 +470,15 @@ public function AddReplyTo($address, $name = '') {
* @param string $address The email address to send to
* @param string $name
* @return boolean true on success, false if address already used or invalid in some way
- * @access private
+ * @access protected
*/
- private function AddAnAddress($kind, $address, $name = '') {
+ protected function AddAnAddress($kind, $address, $name = '') {
if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
- echo 'Invalid recipient array: ' . kind;
+ $this->SetError($this->Lang('Invalid recipient array').': '.$kind);
+ if ($this->exceptions) {
+ throw new phpmailerException('Invalid recipient array: ' . $kind);
+ }
+ echo $this->Lang('Invalid recipient array').': '.$kind;
return false;
}
$address = trim($address);
@@ -485,7 +512,7 @@ private function AddAnAddress($kind, $address, $name = '') {
* @param string $name
* @return boolean
*/
- public function SetFrom($address, $name = '',$auto=1) {
+ public function SetFrom($address, $name = '', $auto = 1) {
$address = trim($address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
if (!self::ValidateAddress($address)) {
@@ -544,39 +571,66 @@ public static function ValidateAddress($address) {
*/
public function Send() {
try {
- if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
- throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
+ if(!$this->PreSend()) return false;
+ return $this->PostSend();
+ } catch (phpmailerException $e) {
+ $this->SetError($e->getMessage());
+ if ($this->exceptions) {
+ throw $e;
+ }
+ return false;
}
+ }
- // Set whether the message is multipart/alternative
- if(!empty($this->AltBody)) {
- $this->ContentType = 'multipart/alternative';
- }
+ protected function PreSend() {
+ try {
+ if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
+ throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
+ }
- $this->error_count = 0; // reset errors
- $this->SetMessageType();
- $header = $this->CreateHeader();
- $body = $this->CreateBody();
+ // Set whether the message is multipart/alternative
+ if(!empty($this->AltBody)) {
+ $this->ContentType = 'multipart/alternative';
+ }
+ $this->error_count = 0; // reset errors
+ $this->SetMessageType();
+ //Refuse to send an empty message
if (empty($this->Body)) {
throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
}
+ $this->MIMEHeader = $this->CreateHeader();
+ $this->MIMEBody = $this->CreateBody();
+
+
// digitally sign with DKIM if enabled
if ($this->DKIM_domain && $this->DKIM_private) {
- $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
- $header = str_replace("\r\n","\n",$header_dkim) . $header;
+ $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
+ $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
+ }
+
+ return true;
+ } catch (phpmailerException $e) {
+ $this->SetError($e->getMessage());
+ if ($this->exceptions) {
+ throw $e;
+ }
+ return false;
}
+ }
+ protected function PostSend() {
+ try {
// Choose the mailer and send through it
- switch($this->Mailer) {
- case 'sendmail':
- return $this->SendmailSend($header, $body);
- case 'smtp':
- return $this->SmtpSend($header, $body);
- default:
- return $this->MailSend($header, $body);
- }
+ switch($this->Mailer) {
+ case 'sendmail':
+ return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
+ case 'smtp':
+ return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
+ default:
+ return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
+ }
} catch (phpmailerException $e) {
$this->SetError($e->getMessage());
@@ -603,16 +657,16 @@ protected function SendmailSend($header, $body) {
}
if ($this->SingleTo === true) {
foreach ($this->SingleToArray as $key => $val) {
- if(!@$mail = popen($sendmail, 'w')) {
+ if(!@$mail = popen($sendmail, 'w')) {
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
- }
+ }
fputs($mail, "To: " . $val . "\n");
- fputs($mail, $header);
- fputs($mail, $body);
- $result = pclose($mail);
+ fputs($mail, $header);
+ fputs($mail, $body);
+ $result = pclose($mail);
// implement call back function if it exists
$isSent = ($result == 0) ? 1 : 0;
- $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+ $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
if($result != 0) {
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
@@ -620,14 +674,14 @@ protected function SendmailSend($header, $body) {
} else {
if(!@$mail = popen($sendmail, 'w')) {
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
- }
+ }
fputs($mail, $header);
fputs($mail, $body);
$result = pclose($mail);
// implement call back function if it exists
$isSent = ($result == 0) ? 1 : 0;
- $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
- if($result != 0) {
+ $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
+ if($result != 0) {
throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
}
@@ -648,8 +702,12 @@ protected function MailSend($header, $body) {
}
$to = implode(', ', $toArr);
- $params = sprintf("-oi -f %s", $this->Sender);
- if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
+ if (empty($this->Sender)) {
+ $params = "-oi -f %s";
+ } else {
+ $params = sprintf("-oi -f %s", $this->Sender);
+ }
+ if ($this->Sender != '' and !ini_get('safe_mode')) {
$old_from = ini_get('sendmail_from');
ini_set('sendmail_from', $this->Sender);
if ($this->SingleTo === true && count($toArr) > 1) {
@@ -657,13 +715,13 @@ protected function MailSend($header, $body) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+ $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
+ $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
}
} else {
if ($this->SingleTo === true && count($toArr) > 1) {
@@ -671,13 +729,13 @@ protected function MailSend($header, $body) {
$rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+ $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
}
} else {
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
// implement call back function if it exists
$isSent = ($rt == 1) ? 1 : 0;
- $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
+ $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
}
}
if (isset($old_from)) {
@@ -716,11 +774,11 @@ protected function SmtpSend($header, $body) {
$bad_rcpt[] = $to[0];
// implement call back function if it exists
$isSent = 0;
- $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
+ $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
} else {
// implement call back function if it exists
$isSent = 1;
- $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
+ $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
}
}
foreach($this->cc as $cc) {
@@ -728,11 +786,11 @@ protected function SmtpSend($header, $body) {
$bad_rcpt[] = $cc[0];
// implement call back function if it exists
$isSent = 0;
- $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
+ $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
} else {
// implement call back function if it exists
$isSent = 1;
- $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
+ $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
}
}
foreach($this->bcc as $bcc) {
@@ -740,11 +798,11 @@ protected function SmtpSend($header, $body) {
$bad_rcpt[] = $bcc[0];
// implement call back function if it exists
$isSent = 0;
- $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
+ $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
} else {
// implement call back function if it exists
$isSent = 1;
- $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
+ $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
}
}
@@ -782,43 +840,43 @@ public function SmtpConnect() {
// Retry while there is no connection
try {
while($index < count($hosts) && !$connection) {
- $hostinfo = array();
+ $hostinfo = array();
if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
- $host = $hostinfo[1];
- $port = $hostinfo[2];
- } else {
- $host = $hosts[$index];
- $port = $this->Port;
- }
+ $host = $hostinfo[1];
+ $port = $hostinfo[2];
+ } else {
+ $host = $hosts[$index];
+ $port = $this->Port;
+ }
- $tls = ($this->SMTPSecure == 'tls');
- $ssl = ($this->SMTPSecure == 'ssl');
+ $tls = ($this->SMTPSecure == 'tls');
+ $ssl = ($this->SMTPSecure == 'ssl');
- if($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
+ if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
- $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
- $this->smtp->Hello($hello);
+ $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
+ $this->smtp->Hello($hello);
- if($tls) {
- if(!$this->smtp->StartTLS()) {
+ if ($tls) {
+ if (!$this->smtp->StartTLS()) {
throw new phpmailerException($this->Lang('tls'));
- }
+ }
//We must resend HELO after tls negotiation
- $this->smtp->Hello($hello);
- }
+ $this->smtp->Hello($hello);
+ }
- $connection = true;
- if($this->SMTPAuth) {
- if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
+ $connection = true;
+ if ($this->SMTPAuth) {
+ if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
throw new phpmailerException($this->Lang('authenticate'));
+ }
}
}
- }
- $index++;
- if(!$connection) {
+ $index++;
+ if (!$connection) {
throw new phpmailerException($this->Lang('connect_host'));
- }
+ }
}
} catch (phpmailerException $e) {
$this->smtp->Reset();
@@ -844,9 +902,9 @@ public function SmtpClose() {
* Sets the language for all class error messages.
* Returns false if it cannot load the language file. The default language is English.
* @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
- * @param string $lang_path Path to the language file directory
- * @access public
- */
+ * @param string $lang_path Path to the language file directory
+ * @access public
+ */
function SetLanguage($langcode = 'en', $lang_path = 'language/') {
//Define full set of translatable strings
$PHPMAILER_LANG = array(
@@ -912,7 +970,7 @@ public function AddrAppend($type, $addr) {
* @return string
*/
public function AddrFormat($addr) {
- if(empty($addr[1])) {
+ if (empty($addr[1])) {
return $this->SecureHeader($addr[0]);
} else {
return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
@@ -942,7 +1000,7 @@ public function WrapText($message, $length, $qp_mode = false) {
$line = explode($this->LE, $message);
$message = '';
- for ($i=0 ;$i < count($line); $i++) {
+ for ($i = 0 ;$i < count($line); $i++) {
$line_part = explode(' ', $line[$i]);
$buf = '';
for ($e = 0; $e<count($line_part); $e++) {
@@ -1056,7 +1114,9 @@ public function SetWordWrap() {
switch($this->message_type) {
case 'alt':
- case 'alt_attachments':
+ case 'alt_inline':
+ case 'alt_attach':
+ case 'alt_inline_attach':
$this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
break;
default:
@@ -1077,6 +1137,7 @@ public function CreateHeader() {
$uniq_id = md5(uniqid(time()));
$this->boundary[1] = 'b1_' . $uniq_id;
$this->boundary[2] = 'b2_' . $uniq_id;
+ $this->boundary[3] = 'b3_' . $uniq_id;
$result .= $this->HeaderLine('Date', self::RFCDate());
if($this->Sender == '') {
@@ -1092,13 +1153,13 @@ public function CreateHeader() {
$this->SingleToArray[] = $this->AddrFormat($t);
}
} else {
- if(count($this->to) > 0) {
- $result .= $this->AddrAppend('To', $this->to);
- } elseif (count($this->cc) == 0) {
- $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
+ if(count($this->to) > 0) {
+ $result .= $this->AddrAppend('To', $this->to);
+ } elseif (count($this->cc) == 0) {
+ $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
+ }
}
}
- }
$from = array();
$from[0][0] = trim($this->From);
@@ -1125,12 +1186,16 @@ public function CreateHeader() {
}
if($this->MessageID != '') {
- $result .= $this->HeaderLine('Message-ID',$this->MessageID);
+ $result .= $this->HeaderLine('Message-ID', $this->MessageID);
} else {
$result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
}
$result .= $this->HeaderLine('X-Priority', $this->Priority);
- $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
+ if($this->XMailer) {
+ $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
+ } else {
+ $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
+ }
if($this->ConfirmReadingTo != '') {
$result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
@@ -1158,18 +1223,21 @@ public function GetMailMIME() {
switch($this->message_type) {
case 'plain':
$result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
- $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
+ $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
break;
- case 'attachments':
- case 'alt_attachments':
- if($this->InlineImageExists()){
- $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
- } else {
- $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
- $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
- }
+ case 'inline':
+ $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
+ $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
+ break;
+ case 'attach':
+ case 'inline_attach':
+ case 'alt_attach':
+ case 'alt_inline_attach':
+ $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
+ $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
break;
case 'alt':
+ case 'alt_inline':
$result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
break;
@@ -1197,6 +1265,33 @@ public function CreateBody() {
$this->SetWordWrap();
switch($this->message_type) {
+ case 'plain':
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ break;
+ case 'inline':
+ $body .= $this->GetBoundary($this->boundary[1], '', '', '');
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->AttachAll("inline", $this->boundary[1]);
+ break;
+ case 'attach':
+ $body .= $this->GetBoundary($this->boundary[1], '', '', '');
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->AttachAll("attachment", $this->boundary[1]);
+ break;
+ case 'inline_attach':
+ $body .= $this->TextLine("--" . $this->boundary[1]);
+ $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
+ $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+ $body .= $this->LE;
+ $body .= $this->GetBoundary($this->boundary[2], '', '', '');
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->AttachAll("inline", $this->boundary[2]);
+ $body .= $this->LE;
+ $body .= $this->AttachAll("attachment", $this->boundary[1]);
+ break;
case 'alt':
$body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
$body .= $this->EncodeString($this->AltBody, $this->Encoding);
@@ -1206,41 +1301,71 @@ public function CreateBody() {
$body .= $this->LE.$this->LE;
$body .= $this->EndBoundary($this->boundary[1]);
break;
- case 'plain':
+ case 'alt_inline':
+ $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
+ $body .= $this->EncodeString($this->AltBody, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->TextLine("--" . $this->boundary[1]);
+ $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
+ $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+ $body .= $this->LE;
+ $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
$body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->AttachAll("inline", $this->boundary[2]);
+ $body .= $this->LE;
+ $body .= $this->EndBoundary($this->boundary[1]);
break;
- case 'attachments':
- $body .= $this->GetBoundary($this->boundary[1], '', '', '');
+ case 'alt_attach':
+ $body .= $this->TextLine("--" . $this->boundary[1]);
+ $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
+ $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+ $body .= $this->LE;
+ $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
+ $body .= $this->EncodeString($this->AltBody, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
$body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->EndBoundary($this->boundary[2]);
$body .= $this->LE;
- $body .= $this->AttachAll();
+ $body .= $this->AttachAll("attachment", $this->boundary[1]);
break;
- case 'alt_attachments':
- $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
- $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
- $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
+ case 'alt_inline_attach':
+ $body .= $this->TextLine("--" . $this->boundary[1]);
+ $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
+ $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+ $body .= $this->LE;
+ $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
$body .= $this->EncodeString($this->AltBody, $this->Encoding);
$body .= $this->LE.$this->LE;
- $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
+ $body .= $this->TextLine("--" . $this->boundary[2]);
+ $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
+ $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
+ $body .= $this->LE;
+ $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
$body .= $this->EncodeString($this->Body, $this->Encoding);
$body .= $this->LE.$this->LE;
+ $body .= $this->AttachAll("inline", $this->boundary[3]);
+ $body .= $this->LE;
$body .= $this->EndBoundary($this->boundary[2]);
- $body .= $this->AttachAll();
+ $body .= $this->LE;
+ $body .= $this->AttachAll("attachment", $this->boundary[1]);
break;
}
- if($this->IsError()) {
+ if ($this->IsError()) {
$body = '';
- } else if ($this->sign_key_file) {
+ } elseif ($this->sign_key_file) {
try {
$file = tempnam('', 'mail');
file_put_contents($file, $body); //TODO check this worked
- $signed = tempnam("", "signed");
+ $signed = tempnam("", "signed");
if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
@unlink($file);
@unlink($signed);
$body = file_get_contents($signed);
- } else {
+ } else {
@unlink($file);
@unlink($signed);
throw new phpmailerException($this->Lang("signing").openssl_error_string());
@@ -1258,9 +1383,10 @@ public function CreateBody() {
/**
* Returns the start of a message boundary.
- * @access private
+ * @access protected
+ * @return string
*/
- private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
+ protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
$result = '';
if($charSet == '') {
$charSet = $this->CharSet;
@@ -1272,7 +1398,7 @@ private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
$encoding = $this->Encoding;
}
$result .= $this->TextLine('--' . $boundary);
- $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
+ $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
$result .= $this->LE;
$result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
$result .= $this->LE;
@@ -1282,31 +1408,25 @@ private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
/**
* Returns the end of a message boundary.
- * @access private
+ * @access protected
+ * @return string
*/
- private function EndBoundary($boundary) {
+ protected function EndBoundary($boundary) {
return $this->LE . '--' . $boundary . '--' . $this->LE;
}
/**
* Sets the message type.
- * @access private
+ * @access protected
* @return void
*/
- private function SetMessageType() {
- if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
- $this->message_type = 'plain';
- } else {
- if(count($this->attachment) > 0) {
- $this->message_type = 'attachments';
- }
- if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
- $this->message_type = 'alt';
- }
- if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
- $this->message_type = 'alt_attachments';
- }
- }
+ protected function SetMessageType() {
+ $this->message_type = array();
+ if($this->AlternativeExists()) $this->message_type[] = "alt";
+ if($this->InlineImageExists()) $this->message_type[] = "inline";
+ if($this->AttachmentExists()) $this->message_type[] = "attach";
+ $this->message_type = implode("_", $this->message_type);
+ if($this->message_type == "") $this->message_type = "plain";
}
/**
@@ -1343,13 +1463,13 @@ public function TextLine($value) {
*/
public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
try {
- if(!@is_file($path)) {
+ if ( !@is_file($path) ) {
throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
- }
- $filename = basename($path);
- if($name == '') {
- $name = $filename;
- }
+ }
+ $filename = basename($path);
+ if ( $name == '' ) {
+ $name = $filename;
+ }
$this->attachment[] = array(
0 => $path,
@@ -1386,10 +1506,10 @@ public function GetAttachments() {
/**
* Attaches all fs, string, and binary attachments to the message.
* Returns an empty string on failure.
- * @access private
+ * @access protected
* @return string
*/
- private function AttachAll() {
+ protected function AttachAll($disposition_type, $boundary) {
// Return text of body
$mime = array();
$cidUniq = array();
@@ -1397,54 +1517,58 @@ private function AttachAll() {
// Add all attachments
foreach ($this->attachment as $attachment) {
- // Check for string attachment
- $bString = $attachment[5];
- if ($bString) {
- $string = $attachment[0];
- } else {
- $path = $attachment[0];
- }
+ // CHECK IF IT IS A VALID DISPOSITION_FILTER
+ if($attachment[6] == $disposition_type) {
+ // Check for string attachment
+ $bString = $attachment[5];
+ if ($bString) {
+ $string = $attachment[0];
+ } else {
+ $path = $attachment[0];
+ }
- if (in_array($attachment[0], $incl)) { continue; }
- $filename = $attachment[1];
- $name = $attachment[2];
- $encoding = $attachment[3];
- $type = $attachment[4];
- $disposition = $attachment[6];
- $cid = $attachment[7];
- $incl[] = $attachment[0];
- if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
- $cidUniq[$cid] = true;
-
- $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
- $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
- $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
-
- if($disposition == 'inline') {
- $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
- }
+ $inclhash = md5(serialize($attachment));
+ if (in_array($inclhash, $incl)) { continue; }
+ $incl[] = $inclhash;
+ $filename = $attachment[1];
+ $name = $attachment[2];
+ $encoding = $attachment[3];
+ $type = $attachment[4];
+ $disposition = $attachment[6];
+ $cid = $attachment[7];
+ if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
+ $cidUniq[$cid] = true;
+
+ $mime[] = sprintf("--%s%s", $boundary, $this->LE);
+ $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
+ $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
+
+ if($disposition == 'inline') {
+ $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
+ }
- $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
+ $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
- // Encode as string attachment
- if($bString) {
- $mime[] = $this->EncodeString($string, $encoding);
- if($this->IsError()) {
- return '';
- }
- $mime[] = $this->LE.$this->LE;
- } else {
- $mime[] = $this->EncodeFile($path, $encoding);
- if($this->IsError()) {
- return '';
+ // Encode as string attachment
+ if($bString) {
+ $mime[] = $this->EncodeString($string, $encoding);
+ if($this->IsError()) {
+ return '';
+ }
+ $mime[] = $this->LE.$this->LE;
+ } else {
+ $mime[] = $this->EncodeFile($path, $encoding);
+ if($this->IsError()) {
+ return '';
+ }
+ $mime[] = $this->LE.$this->LE;
}
- $mime[] = $this->LE.$this->LE;
}
}
- $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
+ $mime[] = sprintf("--%s--%s", $boundary, $this->LE);
- return join('', $mime);
+ return implode("", $mime);
}
/**
@@ -1453,27 +1577,29 @@ private function AttachAll() {
* @param string $path The full path to the file
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
* @see EncodeFile()
- * @access private
+ * @access protected
* @return string
*/
- private function EncodeFile($path, $encoding = 'base64') {
+ protected function EncodeFile($path, $encoding = 'base64') {
try {
if (!is_readable($path)) {
throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
- }
- if (function_exists('get_magic_quotes')) {
+ }
+ if (function_exists('get_magic_quotes')) {
function get_magic_quotes() {
- return false;
+ return false;
}
-}
- if (PHP_VERSION < 6) {
- $magic_quotes = get_magic_quotes_runtime();
- set_magic_quotes_runtime(0);
- }
- $file_buffer = file_get_contents($path);
- $file_buffer = $this->EncodeString($file_buffer, $encoding);
- if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
- return $file_buffer;
+ }
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ $magic_quotes = get_magic_quotes_runtime();
+ set_magic_quotes_runtime(0);
+ }
+ $file_buffer = file_get_contents($path);
+ $file_buffer = $this->EncodeString($file_buffer, $encoding);
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ set_magic_quotes_runtime($magic_quotes);
+ }
+ return $file_buffer;
} catch (Exception $e) {
$this->SetError($e->getMessage());
return '';
@@ -1488,7 +1614,7 @@ function get_magic_quotes() {
* @access public
* @return string
*/
- public function EncodeString ($str, $encoding = 'base64') {
+ public function EncodeString($str, $encoding = 'base64') {
$encoded = '';
switch(strtolower($encoding)) {
case 'base64':
@@ -1519,7 +1645,7 @@ public function EncodeString ($str, $encoding = 'base64') {
* @access public
* @return string
*/
- public function EncodeHeader ($str, $position = 'text') {
+ public function EncodeHeader($str, $position = 'text') {
$x = 0;
switch (strtolower($position)) {
@@ -1553,8 +1679,8 @@ public function EncodeHeader ($str, $position = 'text') {
if (strlen($str)/3 < $x) {
$encoding = 'B';
if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
- // Use a custom function which correctly encodes and wraps long
- // multibyte strings without breaking lines within a character
+ // Use a custom function which correctly encodes and wraps long
+ // multibyte strings without breaking lines within a character
$encoded = $this->Base64EncodeWrapMB($str);
} else {
$encoded = base64_encode($str);
@@ -1637,7 +1763,7 @@ public function Base64EncodeWrapMB($str) {
* @return string
*/
public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
- $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
+ $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
$lines = preg_split('/(?:\r\n|\r|\n)/', $input);
$eol = "\r\n";
$escape = '=';
@@ -1718,7 +1844,7 @@ public function EncodeQP($string, $line_max = 76, $space_conv = false) {
* @access public
* @return string
*/
- public function EncodeQ ($str, $position = 'text') {
+ public function EncodeQ($str, $position = 'text') {
// There should not be any EOL in the string
$encoded = preg_replace('/[\r\n]*/', '', $str);
@@ -1733,7 +1859,7 @@ public function EncodeQ ($str, $position = 'text') {
// Replace every high ascii, control =, ? and _ characters
//TODO using /e (equivalent to eval()) is probably not a good idea
$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
- "'='.sprintf('%02X', ord('\\1'))", $encoded);
+ "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
break;
}
@@ -1782,13 +1908,13 @@ public function AddStringAttachment($string, $filename, $encoding = 'base64', $t
*/
public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
- if(!@is_file($path)) {
+ if ( !@is_file($path) ) {
$this->SetError($this->Lang('file_access') . $path);
return false;
}
$filename = basename($path);
- if($name == '') {
+ if ( $name == '' ) {
$name = $filename;
}
@@ -1807,6 +1933,20 @@ public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64',
return true;
}
+ public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
+ // Append to $attachment array
+ $this->attachment[] = array(
+ 0 => $string,
+ 1 => $filename,
+ 2 => basename($filename),
+ 3 => $encoding,
+ 4 => $type,
+ 5 => true, // isStringAttachment
+ 6 => 'inline',
+ 7 => $cid
+ );
+ }
+
/**
* Returns true if an inline attachment is present.
* @access public
@@ -1821,6 +1961,19 @@ public function InlineImageExists() {
return false;
}
+ public function AttachmentExists() {
+ foreach($this->attachment as $attachment) {
+ if ($attachment[6] == 'attachment') {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public function AlternativeExists() {
+ return strlen($this->AltBody)>0;
+ }
+
/////////////////////////////////////////////////
// CLASS METHODS, MESSAGE RESET
/////////////////////////////////////////////////
@@ -1933,10 +2086,10 @@ public static function RFCDate() {
/**
* Returns the server hostname or 'localhost.localdomain' if unknown.
- * @access private
+ * @access protected
* @return string
*/
- private function ServerHostname() {
+ protected function ServerHostname() {
if (!empty($this->Hostname)) {
$result = $this->Hostname;
} elseif (isset($_SERVER['SERVER_NAME'])) {
@@ -1950,10 +2103,10 @@ private function ServerHostname() {
/**
* Returns a message in the appropriate language.
- * @access private
+ * @access protected
* @return string
*/
- private function Lang($key) {
+ protected function Lang($key) {
if(count($this->language) < 1) {
$this->SetLanguage('en'); // set the default language
}
@@ -1976,10 +2129,10 @@ public function IsError() {
/**
* Changes every end of line from CR or LF to CRLF.
- * @access private
+ * @access public
* @return string
*/
- private function FixEOL($str) {
+ public function FixEOL($str) {
$str = str_replace("\r\n", "\n", $str);
$str = str_replace("\r", "\n", $str);
$str = str_replace("\n", $this->LE, $str);
@@ -2000,21 +2153,21 @@ public function AddCustomHeader($custom_header) {
* @access public
* @return $message
*/
- public function MsgHTML($message,$basedir='') {
+ public function MsgHTML($message, $basedir = '') {
preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
if(isset($images[2])) {
foreach($images[2] as $i => $url) {
// do not change urls for absolute images (thanks to corvuscorax)
- if (!preg_match('#^[A-z]+://#',$url)) {
+ if (!preg_match('#^[A-z]+://#', $url)) {
$filename = basename($url);
$directory = dirname($url);
- ($directory == '.')?$directory='':'';
+ ($directory == '.') ? $directory='': '';
$cid = 'cid:' . md5($filename);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$mimeType = self::_mime_types($ext);
- if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
- if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
- if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
+ if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
+ if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
+ if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
$message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
}
}
@@ -2022,11 +2175,11 @@ public function MsgHTML($message,$basedir='') {
}
$this->IsHTML(true);
$this->Body = $message;
- $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
- if ( !empty($textMsg) && empty($this->AltBody) ) {
+ $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
+ if (!empty($textMsg) && empty($this->AltBody)) {
$this->AltBody = html_entity_decode($textMsg);
}
- if ( empty($this->AltBody) ) {
+ if (empty($this->AltBody)) {
$this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
}
}
@@ -2128,34 +2281,34 @@ public static function _mime_types($ext = '') {
'xl' => 'application/excel',
'eml' => 'message/rfc822'
);
- return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
+ return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
}
/**
- * Set (or reset) Class Objects (variables)
- *
- * Usage Example:
- * $page->set('X-Priority', '3');
- *
- * @access public
- * @param string $name Parameter Name
- * @param mixed $value Parameter Value
- * NOTE: will not work with arrays, there are no arrays to set/reset
+ * Set (or reset) Class Objects (variables)
+ *
+ * Usage Example:
+ * $page->set('X-Priority', '3');
+ *
+ * @access public
+ * @param string $name Parameter Name
+ * @param mixed $value Parameter Value
+ * NOTE: will not work with arrays, there are no arrays to set/reset
* @todo Should this not be using __set() magic function?
- */
- public function set ( $name, $value = '' ) {
+ */
+ public function set($name, $value = '') {
try {
- if ( isset($this->$name) ) {
- $this->$name = $value;
- } else {
+ if (isset($this->$name) ) {
+ $this->$name = $value;
+ } else {
throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
- }
+ }
} catch (Exception $e) {
$this->SetError($e->getMessage());
if ($e->getCode() == self::STOP_CRITICAL) {
- return false;
+ return false;
+ }
}
- }
return true;
}
@@ -2192,18 +2345,18 @@ public function Sign($cert_filename, $key_filename, $key_pass) {
* @param string $key_pass Password for private key
*/
public function DKIM_QP($txt) {
- $tmp="";
- $line="";
- for ($i=0;$i<strlen($txt);$i++) {
- $ord=ord($txt[$i]);
+ $tmp = '';
+ $line = '';
+ for ($i = 0; $i < strlen($txt); $i++) {
+ $ord = ord($txt[$i]);
if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
- $line.=$txt[$i];
+ $line .= $txt[$i];
} else {
- $line.="=".sprintf("%02X",$ord);
+ $line .= "=".sprintf("%02X", $ord);
}
}
return $line;
-}
+ }
/**
* Generate DKIM signature
@@ -2213,8 +2366,8 @@ public function DKIM_QP($txt) {
*/
public function DKIM_Sign($s) {
$privKeyStr = file_get_contents($this->DKIM_private);
- if ($this->DKIM_passphrase!='') {
- $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
+ if ($this->DKIM_passphrase != '') {
+ $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
} else {
$privKey = $privKeyStr;
}
@@ -2230,15 +2383,15 @@ public function DKIM_Sign($s) {
* @param string $s Header
*/
public function DKIM_HeaderC($s) {
- $s=preg_replace("/\r\n\s+/"," ",$s);
- $lines=explode("\r\n",$s);
- foreach ($lines as $key=>$line) {
- list($heading,$value)=explode(":",$line,2);
- $heading=strtolower($heading);
- $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
- $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
- }
- $s=implode("\r\n",$lines);
+ $s = preg_replace("/\r\n\s+/", " ", $s);
+ $lines = explode("\r\n", $s);
+ foreach ($lines as $key => $line) {
+ list($heading, $value) = explode(":", $line, 2);
+ $heading = strtolower($heading);
+ $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces
+ $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value
+ }
+ $s = implode("\r\n", $lines);
return $s;
}
@@ -2251,11 +2404,11 @@ public function DKIM_HeaderC($s) {
public function DKIM_BodyC($body) {
if ($body == '') return "\r\n";
// stabilize line endings
- $body=str_replace("\r\n","\n",$body);
- $body=str_replace("\n","\r\n",$body);
+ $body = str_replace("\r\n", "\n", $body);
+ $body = str_replace("\n", "\r\n", $body);
// END stabilize line endings
- while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
- $body=substr($body,0,strlen($body)-2);
+ while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
+ $body = substr($body, 0, strlen($body) - 2);
}
return $body;
}
@@ -2268,23 +2421,23 @@ public function DKIM_BodyC($body) {
* @param string $subject Subject
* @param string $body Body
*/
- public function DKIM_Add($headers_line,$subject,$body) {
+ public function DKIM_Add($headers_line, $subject, $body) {
$DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
$DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
$DKIMquery = 'dns/txt'; // Query method
$DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
$subject_header = "Subject: $subject";
- $headers = explode("\r\n",$headers_line);
+ $headers = explode($this->LE, $headers_line);
foreach($headers as $header) {
- if (strpos($header,'From:') === 0) {
- $from_header=$header;
- } elseif (strpos($header,'To:') === 0) {
- $to_header=$header;
+ if (strpos($header, 'From:') === 0) {
+ $from_header = $header;
+ } elseif (strpos($header, 'To:') === 0) {
+ $to_header = $header;
}
}
- $from = str_replace('|','=7C',$this->DKIM_QP($from_header));
- $to = str_replace('|','=7C',$this->DKIM_QP($to_header));
- $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
+ $from = str_replace('|', '=7C', $this->DKIM_QP($from_header));
+ $to = str_replace('|', '=7C', $this->DKIM_QP($to_header));
+ $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
$body = $this->DKIM_BodyC($body);
$DKIMlen = strlen($body) ; // Length of body
$DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
@@ -2303,10 +2456,10 @@ public function DKIM_Add($headers_line,$subject,$body) {
return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
}
- protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
+ protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
if (!empty($this->action_function) && function_exists($this->action_function)) {
- $params = array($isSent,$to,$cc,$bcc,$subject,$body);
- call_user_func_array($this->action_function,$params);
+ $params = array($isSent, $to, $cc, $bcc, $subject, $body);
+ call_user_func_array($this->action_function, $params);
}
}
}
View
410 libraries/phpmailer/pop3.php
@@ -0,0 +1,410 @@
+<?php
+/*~ class.pop3.php
+.---------------------------------------------------------------------------.
+| Software: PHPMailer - PHP email class |
+| Version: 5.2 |
+| Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ |
+| ------------------------------------------------------------------------- |
+| Admin: Jim Jagielski (project admininistrator) |
+| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
+| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
+| : Jim Jagielski (jimjag) jimjag@gmail.com |
+| Founder: Brent R. Matzelle (original founder) |
+| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved. |
+| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
+| Copyright (c) 2001-2003, Brent R. Matzelle |
+| ------------------------------------------------------------------------- |
+| License: Distributed under the Lesser General Public License (LGPL) |
+| http://www.gnu.org/copyleft/lesser.html |
+| This program is distributed in the hope that it will be useful - WITHOUT |
+| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
+| FITNESS FOR A PARTICULAR PURPOSE. |
+'---------------------------------------------------------------------------'
+*/
+
+/**
+ * PHPMailer - PHP POP Before SMTP Authentication Class
+ * NOTE: Designed for use with PHP version 5 and up
+ * @package PHPMailer
+ * @author Andy Prevost
+ * @author Marcus Bointon
+ * @author Jim Jagielski
+ * @copyright 2010 - 2011 Jim Jagielski
+ * @copyright 2004 - 2009 Andy Prevost
+ * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
+ * @version $Id: class.pop3.php 450 2010-06-23 16:46:33Z coolbru $
+ */
+
+/**
+ * POP Before SMTP Authentication Class
+ * Version 5.2.0
+ *
+ * Author: Richard Davey (rich@corephp.co.uk)
+ * Modifications: Andy Prevost
+ * License: LGPL, see PHPMailer License
+ *
+ * Specifically for PHPMailer to allow POP before SMTP authentication.
+ * Does not yet work with APOP - if you have an APOP account, contact Richard Davey
+ * and we can test changes to this script.
+ *
+ * This class is based on the structure of the SMTP class originally authored by Chris Ryan
+ *
+ * This class is rfc 1939 compliant and implements all the commands
+ * required for POP3 connection, authentication and disconnection.
+ *
+ * @package PHPMailer
+ * @author Richard Davey
+ */
+
+class POP3 {
+ /**
+ * Default POP3 port
+ * @var int
+ */
+ public $POP3_PORT = 110;
+
+ /**
+ * Default Timeout
+ * @var int
+ */
+ public $POP3_TIMEOUT = 30;
+
+ /**
+ * POP3 Carriage Return + Line Feed
+ * @var string
+ */
+ public $CRLF = "\r\n";
+
+ /**
+ * Displaying Debug warnings? (0 = now, 1+ = yes)
+ * @var int
+ */
+ public $do_debug = 2;
+
+ /**
+ * POP3 Mail Server
+ * @var string
+ */
+ public $host;
+
+ /**
+ * POP3 Port
+ * @var int
+ */
+ public $port;
+
+ /**
+ * POP3 Timeout Value
+ * @var int
+ */
+ public $tval;
+
+ /**
+ * POP3 Username
+ * @var string
+ */
+ public $username;
+
+ /**
+ * POP3 Password
+ * @var string
+ */
+ public $password;
+
+ /**
+ * Sets the POP3 PHPMailer Version number
+ * @var string
+ */
+ public $Version = '5.2';
+
+ /////////////////////////////////////////////////
+ // PROPERTIES, PRIVATE AND PROTECTED
+ /////////////////////////////////////////////////
+
+ private $pop_conn;
+ private $connected;
+ private $error; // Error log array
+
+ /**
+ * Constructor, sets the initial values
+ * @access public
+ * @return POP3
+ */
+ public function __construct() {
+ $this->pop_conn = 0;
+ $this->connected = false;
+ $this->error = null;
+ }
+
+ /**
+ * Combination of public events - connect, login, disconnect
+ * @access public
+ * @param string $host
+ * @param integer $port
+ * @param integer $tval
+ * @param string $username
+ * @param string $password
+ */
+ public function Authorise ($host, $port = false, $tval = false, $username, $password, $debug_level = 0) {
+ $this->host = $host;
+
+ // If no port value is passed, retrieve it
+ if ($port == false) {
+ $this->port = $this->POP3_PORT;
+ } else {
+ $this->port = $port;
+ }
+
+ // If no port value is passed, retrieve it
+ if ($tval == false) {
+ $this->tval = $this->POP3_TIMEOUT;
+ } else {
+ $this->tval = $tval;
+ }
+
+ $this->do_debug = $debug_level;
+ $this->username = $username;
+ $this->password = $password;
+
+ // Refresh the error log
+ $this->error = null;
+
+ // Connect
+ $result = $this->Connect($this->host, $this->port, $this->tval);
+
+ if ($result) {
+ $login_result = $this->Login($this->username, $this->password);
+
+ if ($login_result) {
+ $this->Disconnect();
+
+ return true;
+ }
+
+ }
+
+ // We need to disconnect regardless if the login succeeded
+ $this->Disconnect();
+
+ return false;
+ }
+
+ /**
+ * Connect to the POP3 server
+ * @access public
+ * @param string $host
+ * @param integer $port
+ * @param integer $tval
+ * @return boolean
+ */
+ public function Connect ($host, $port = false, $tval = 30) {
+ // Are we already connected?
+ if ($this->connected) {
+ return true;
+ }
+
+ /*
+ On Windows this will raise a PHP Warning error if the hostname doesn't exist.
+ Rather than supress it with @fsockopen, let's capture it cleanly instead
+ */
+
+ set_error_handler(array(&$this, 'catchWarning'));
+
+ // Connect to the POP3 server
+ $this->pop_conn = fsockopen($host, // POP3 Host
+ $port, // Port #
+ $errno, // Error Number
+ $errstr, // Error Message
+ $tval); // Timeout (seconds)
+
+ // Restore the error handler
+ restore_error_handler();
+
+ // Does the Error Log now contain anything?
+ if ($this->error && $this->do_debug >= 1) {
+ $this->displayErrors();
+ }
+
+ // Did we connect?
+ if ($this->pop_conn == false) {
+ // It would appear not...
+ $this->error = array(
+ 'error' => "Failed to connect to server $host on port $port",
+ 'errno' => $errno,
+ 'errstr' => $errstr
+ );
+
+ if ($this->do_debug >= 1) {
+ $this->displayErrors();
+ }
+
+ return false;
+ }
+
+ // Increase the stream time-out
+
+ // Check for PHP 4.3.0 or later
+ if (version_compare(phpversion(), '5.0.0', 'ge')) {
+ stream_set_timeout($this->pop_conn, $tval, 0);
+ } else {
+ // Does not work on Windows
+ if (substr(PHP_OS, 0, 3) !== 'WIN') {
+ socket_set_timeout($this->pop_conn, $tval, 0);
+ }
+ }
+
+ // Get the POP3 server response
+ $pop3_response = $this->getResponse();
+
+ // Check for the +OK
+ if ($this->checkResponse($pop3_response)) {
+ // The connection is established and the POP3 server is talking
+ $this->connected = true;
+ return true;
+ }
+
+ }
+
+ /**
+ * Login to the POP3 server (does not support APOP yet)
+ * @access public
+ * @param string $username
+ * @param string $password
+ * @return boolean
+ */
+ public function Login ($username = '', $password = '') {
+ if ($this->connected == false) {
+ $this->error = 'Not connected to POP3 server';
+
+ if ($this->do_debug >= 1) {
+ $this->displayErrors();
+ }
+ }
+
+ if (empty($username)) {
+ $username = $this->username;
+ }
+
+ if (empty($password)) {
+ $password = $this->password;
+ }
+
+ $pop_username = "USER $username" . $this->CRLF;
+ $pop_password = "PASS $password" . $this->CRLF;
+
+ // Send the Username
+ $this->sendString($pop_username);
+ $pop3_response = $this->getResponse();
+
+ if ($this->checkResponse($pop3_response)) {
+ // Send the Password
+ $this->sendString($pop_password);
+ $pop3_response = $this->getResponse();
+
+ if ($this->checkResponse($pop3_response)) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Disconnect from the POP3 server
+ * @access public
+ */
+ public function Disconnect () {
+ $this->sendString('QUIT');
+
+ fclose($this->pop_conn);
+ }
+
+ /////////////////////////////////////////////////
+ // Private Methods
+ /////////////////////////////////////////////////
+
+ /**
+ * Get the socket response back.
+ * $size is the maximum number of bytes to retrieve
+ * @access private
+ * @param integer $size
+ * @return string
+ */
+ private function getResponse ($size = 128) {
+ $pop3_response = fgets($this->pop_conn, $size);
+
+ return $pop3_response;
+ }
+
+ /**
+ * Send a string down the open socket connection to the POP3 server
+ * @access private
+ * @param string $string
+ * @return integer
+ */
+ private function sendString ($string) {
+ $bytes_sent = fwrite($this->pop_conn, $string, strlen($string));
+
+ return $bytes_sent;
+ }
+
+ /**
+ * Checks the POP3 server response for +OK or -ERR
+ * @access private
+ * @param string $string
+ * @return boolean
+ */
+ private function checkResponse ($string) {
+ if (substr($string, 0, 3) !== '+OK') {
+ $this->error = array(