mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Cleanup class to work with PHPMailer 6.
This commit is contained in:
@@ -33,7 +33,7 @@ If we do that, can have a single override file, plus a core file
|
||||
5. Logging:
|
||||
- Use rolling log for errors - error string(s) available - sort out entry
|
||||
- Look at support of some other logging options
|
||||
9. Make sure SMTPDebug can be set (TRUE/FALSE)
|
||||
9. Make sure SMTPDebug can be set (true/false)
|
||||
12. Check support for port number - ATM we just override for SSL. Looks as if phpmailer can take it from end of server link.
|
||||
18. Note object iteration - may be useful for dump of object state
|
||||
19. Consider overriding error handler
|
||||
@@ -68,7 +68,7 @@ General notes
|
||||
5. Attachments - note method available for passing string attachments
|
||||
- AddStringAttachment($string,$filename,$encoding,$type)
|
||||
6. Several email address-related methods can accept two comma-separated strings, one for addresses and one for related names
|
||||
7. Its possible to send a text-only email by passing an array of parameters including 'send_html' = FALSE
|
||||
7. Its possible to send a text-only email by passing an array of parameters including 'send_html' = false
|
||||
8. For bulk emailing, must call the 'allSent()' method when complete to ensure SMTP mailer is properly closed.
|
||||
9. For sending through googlemail (and presumably gmail), use TLS
|
||||
10. Note that the 'add_html_header' option adds only the DOCTYPE bits - not the <head>....</head> section
|
||||
@@ -127,15 +127,15 @@ Usage
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
|
||||
//define('MAIL_DEBUG',TRUE);
|
||||
//define('LOG_CALLER', TRUE);
|
||||
//define('MAIL_DEBUG',true);
|
||||
//define('LOG_CALLER', true);
|
||||
|
||||
//require_once(e_HANDLER.'phpmailer/class.phpmailer.php');
|
||||
//require_once(e_HANDLER.'phpmailer/class.smtp.php');
|
||||
//require_once(e_HANDLER.'phpmailer/PHPMailerAutoload.php');
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
// use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\POP3;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
require_once(e_HANDLER.'vendor/autoload.php');
|
||||
@@ -150,21 +150,23 @@ class e107Email extends PHPMailer
|
||||
{
|
||||
private $general_opts = array();
|
||||
private $logEnable = 2; // 0 = log disabled, 1 = 'dry run' (debug and log, no send). 2 = 'log all' (send, and log result)
|
||||
private $logHandle = FALSE; // Save handle of log file if opened
|
||||
|
||||
private $localUseVerp = FALSE; // Use our own variable - PHPMailer one doesn't work with all mailers
|
||||
/** @var resource */
|
||||
private $logHandle = false; // Save handle of log file if opened
|
||||
|
||||
private $localUseVerp = false; // Use our own variable - PHPMailer one doesn't work with all mailers
|
||||
private $save_bouncepath = ''; // Used with VERP
|
||||
|
||||
private $add_email = 0; // 1 includes email detail in log (if logging enabled, of course)
|
||||
private $allow_html = 1; // Flag for HTML conversion - '1' = default, FALSE = disable, TRUE = force.
|
||||
private $add_HTML_header = FALSE; // If TRUE, inserts a standard HTML header at the front of the HTML part of the email (set FALSE for BC)
|
||||
private $allow_html = 1; // Flag for HTML conversion - '1' = default, false = disable, true = force.
|
||||
private $add_HTML_header = false; // If true, inserts a standard HTML header at the front of the HTML part of the email (set false for BC)
|
||||
private $SendCount = 0; // Keep track of how many emails sent since last SMTP open/connect (used for SMTP KeepAlive)
|
||||
private $TotalSent = 0; // Info might be of interest
|
||||
private $TotalErrors = 0; // Count errors in sending emails
|
||||
private $pause_amount = 10; // Number of emails to send before pausing/resetting (or closing if SMTPkeepAlive set)
|
||||
private $pause_time = 1; // Time to pause after sending a block of emails
|
||||
|
||||
public $legacyBody = false; // TRUE enables legacy conversion of plain text body to HTML in HTML emails
|
||||
public $legacyBody = false; // true enables legacy conversion of plain text body to HTML in HTML emails
|
||||
private $debug = false; // echos various debug info when set to true.
|
||||
private $pref = array(); // Store code prefs.
|
||||
private $previewMode = false;
|
||||
@@ -194,13 +196,13 @@ class e107Email extends PHPMailer
|
||||
/**
|
||||
* Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed
|
||||
*
|
||||
* @var array $overrides - array of values which override mail-related prefs. Key is the same as the corresponding pref.
|
||||
* @var array|boolean $overrides - array of values which override mail-related prefs. Key is the same as the corresponding pref.
|
||||
* - second batch of keys can preset values configurable through the arraySet() method
|
||||
* @return null
|
||||
*/
|
||||
public function __construct($overrides = FALSE)
|
||||
public function __construct($overrides = false)
|
||||
{
|
||||
parent::__construct(FALSE); // Parent constructor - no exceptions for now
|
||||
parent::__construct(false); // Parent constructor - no exceptions for now
|
||||
|
||||
|
||||
$pref = e107::pref('core');
|
||||
@@ -222,7 +224,7 @@ class e107Email extends PHPMailer
|
||||
$this->setLanguage(CORE_LC);
|
||||
|
||||
|
||||
if (($overrides === FALSE) || !is_array($overrides))
|
||||
if (($overrides === false) || !is_array($overrides))
|
||||
{
|
||||
$overrides = array();
|
||||
}
|
||||
@@ -260,8 +262,9 @@ class e107Email extends PHPMailer
|
||||
$this->general_opts[$k] = $v;
|
||||
if (strpos($v,'hostname') === 0)
|
||||
{
|
||||
list(,$this->HostName) = explode('=',$v);
|
||||
if ($this->debug) echo "Host name set to: {$this->HostName}<br />";
|
||||
list(,$this->Hostname) = explode('=',$v);
|
||||
|
||||
if ($this->debug) echo "Host name set to: {$this->Hostname}<br />";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,14 +279,14 @@ class e107Email extends PHPMailer
|
||||
if (vartrue($pref['smtp_keepalive'])) $temp_opts[] = 'keepalive'; // Legacy option - remove later
|
||||
foreach ($temp_opts as $k=>$v)
|
||||
{
|
||||
if (strpos($v,'=') !== FALSE)
|
||||
if (strpos($v,'=') !== false)
|
||||
{
|
||||
list($v,$k) = explode('=',$v,2);
|
||||
$smtp_options[trim($v)] = trim($k);
|
||||
}
|
||||
else
|
||||
{
|
||||
$smtp_options[trim($v)] = TRUE; // Simple on/off option
|
||||
$smtp_options[trim($v)] = true; // Simple on/off option
|
||||
}
|
||||
}
|
||||
unset($temp_opts);
|
||||
@@ -316,7 +319,7 @@ class e107Email extends PHPMailer
|
||||
if ($this->debug) echo "Invalid option: {$smtp_options['secure']}<br />";
|
||||
}
|
||||
}
|
||||
$this->SMTPKeepAlive = varset($smtp_options['keepalive'],FALSE); // ***** Control this
|
||||
$this->SMTPKeepAlive = varset($smtp_options['keepalive'],false); // ***** Control this
|
||||
$this->Host = $overrides['smtp_server'];
|
||||
if($overrides['smtp_username'] && $overrides['smtp_password'])
|
||||
{
|
||||
@@ -371,6 +374,8 @@ class e107Email extends PHPMailer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -378,7 +383,7 @@ class e107Email extends PHPMailer
|
||||
* Set log level
|
||||
* @param int $level 0|1|2
|
||||
* @param int $emailDetails 0|1
|
||||
* @return e107Email
|
||||
* @return object e107Email
|
||||
*/
|
||||
public function logEnable($level, $emailDetails = null)
|
||||
{
|
||||
@@ -392,7 +397,7 @@ class e107Email extends PHPMailer
|
||||
|
||||
/**
|
||||
* Disable log completely
|
||||
* @return e107Email
|
||||
* @return object e107Email
|
||||
*/
|
||||
public function logDisable()
|
||||
{
|
||||
@@ -420,17 +425,18 @@ class e107Email extends PHPMailer
|
||||
/**
|
||||
* Log functions - write to a log file
|
||||
* Each entry logged to a separate line
|
||||
*
|
||||
* @return none
|
||||
*
|
||||
* @param bool $logInfo
|
||||
* @return null
|
||||
*/
|
||||
protected function openLog($logInfo = TRUE)
|
||||
protected function openLog($logInfo = true)
|
||||
{
|
||||
if ($this->logEnable && ($this->logHandle === FALSE))
|
||||
if ($this->logEnable && ($this->logHandle === false))
|
||||
{
|
||||
$logFileName = MAIL_LOG_PATH.'mailoutlog.txt';
|
||||
$this->logHandle = fopen($logFileName, 'a'); // Always append to file
|
||||
}
|
||||
if ($this->logHandle !== FALSE)
|
||||
if ($this->logHandle !== false)
|
||||
{
|
||||
fwrite($this->logHandle,"\n\n=====".date('H:i:s y.m.d')."----------------------------------------------------------------=====\r\n");
|
||||
if ($logInfo)
|
||||
@@ -456,19 +462,21 @@ class e107Email extends PHPMailer
|
||||
{
|
||||
if (!isset($t['class']) || ($t['class'] != 'e107Email'))
|
||||
{
|
||||
fwrite($this->logHandle, print_a($t,TRUE)."\r\n"); // Found the caller
|
||||
fwrite($this->logHandle, print_a($t,true)."\r\n"); // Found the caller
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a line to log file - time/date is prepended, and CRLF is appended
|
||||
*
|
||||
* @param string $text - line to add
|
||||
* @return none
|
||||
* @return null
|
||||
*/
|
||||
protected function logLine($text)
|
||||
{
|
||||
@@ -476,6 +484,8 @@ class e107Email extends PHPMailer
|
||||
{
|
||||
fwrite($this->logHandle,date('H:i:s y.m.d').' - '.$text."\r\n");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -497,14 +507,14 @@ class e107Email extends PHPMailer
|
||||
* @param string $addresses - comma separated
|
||||
* @param string $names - either a single name (used for all addresses) or a comma-separated list corresponding to the address list
|
||||
* If the name field for an entry is blank, or there are not enough entries, the address is substituted
|
||||
* @return TRUE if list accepted, FALSE if invalid list name
|
||||
* @return true if list accepted, false if invalid list name
|
||||
*/
|
||||
public function AddAddressList($list = 'to',$addresses,$names = '')
|
||||
public function AddAddressList($list = 'to',$addresses='',$names = '')
|
||||
{
|
||||
$list = trim(strtolower($list));
|
||||
$tmp = explode(',',$addresses);
|
||||
|
||||
if (strpos($names,',') === FALSE)
|
||||
if (strpos($names,',') === false)
|
||||
{
|
||||
$names = array_fill(0,count($tmp),$names); // Same value for all addresses
|
||||
}
|
||||
@@ -518,10 +528,26 @@ class e107Email extends PHPMailer
|
||||
switch ($list)
|
||||
{
|
||||
case 'to' :
|
||||
$this->addAddress($adr, $to_name);
|
||||
try
|
||||
{
|
||||
$this->addAddress($adr, $to_name);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
break;
|
||||
case 'replyto' :
|
||||
$this->addReplyTo($adr, $to_name);
|
||||
try
|
||||
{
|
||||
$this->addReplyTo($adr, $to_name);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
break;
|
||||
case 'cc' :
|
||||
if($this->Mailer == 'mail')
|
||||
@@ -530,7 +556,15 @@ class e107Email extends PHPMailer
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addCC($adr, $to_name);
|
||||
try
|
||||
{
|
||||
$this->addCC($adr, $to_name);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 'bcc' :
|
||||
@@ -540,42 +574,50 @@ class e107Email extends PHPMailer
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addBCC($adr, $to_name);
|
||||
try
|
||||
{
|
||||
$this->addBCC($adr, $to_name);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default :
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create email body, primarily using the inbuilt functionality of phpmailer
|
||||
* Create email body, primarily using the inbuilt functionality of phpmailer
|
||||
*
|
||||
* @param boolean|int $want_HTML determines whether an HTML part of the email is created. 1 uses default setting for HTML part. Set TRUE to enable, FALSE to disable
|
||||
* @param boolean $add_HTML_header - if TRUE, a standard HTML header is added to the front of the HTML part
|
||||
* @param string $message
|
||||
* @param boolean|int $want_HTML determines whether an HTML part of the email is created. 1 uses default setting for HTML part. Set true to enable, false to disable
|
||||
* @param boolean $add_HTML_header - if true, a standard HTML header is added to the front of the HTML part
|
||||
*
|
||||
* @return none
|
||||
* @return null
|
||||
*/
|
||||
public function makeBody($message,$want_HTML = 1, $add_HTML_header = FALSE)
|
||||
public function makeBody($message,$want_HTML = 1, $add_HTML_header = false)
|
||||
{
|
||||
|
||||
switch (varset($this->general_opts['textonly'],'off'))
|
||||
{
|
||||
case 'pref' : // Disable HTML as default
|
||||
if ($want_HTML == 1) $want_HTML = FALSE;
|
||||
if ($want_HTML == 1) $want_HTML = false;
|
||||
break;
|
||||
case 'force' : // Always disable HTML
|
||||
$want_HTML = FALSE;
|
||||
$want_HTML = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$message = str_replace("\t", "", $message); // filter out tabs from templates;
|
||||
|
||||
if ($want_HTML !== FALSE)
|
||||
if ($want_HTML !== false)
|
||||
{
|
||||
// $message = e107::getParser()->toHTML("[html]".$message."[/html]",true); // using toHtml will break media attachment links. (need to retain {e_XXXX )
|
||||
|
||||
@@ -583,10 +625,9 @@ class e107Email extends PHPMailer
|
||||
if ($add_HTML_header)
|
||||
{
|
||||
$message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n
|
||||
<html xmlns='http://www.w3.org/1999/xhtml' >\n".$message;
|
||||
<html xmlns='http://www.w3.org/1999/xhtml' lang='en' >\n".$message;
|
||||
}
|
||||
|
||||
;
|
||||
// !preg_match('/<(table|div|font|br|a|img|b)/i', $message)
|
||||
if ($this->legacyBody && e107::getParser()->isHtml($message) != true) // Assume html if it includes one of these tags
|
||||
{ // Otherwise assume its a plain text message which needs some conversion to render in HTML
|
||||
@@ -598,7 +639,7 @@ class e107Email extends PHPMailer
|
||||
|
||||
$message = htmlspecialchars($message,ENT_QUOTES,$this->CharSet);
|
||||
$message = preg_replace('%(http|ftp|https)(://\S+)%', '<a href="\1\2">\1\2</a>', $message);
|
||||
$message = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i', '\\1<a href="http://\\2">\\2</a>', $message);
|
||||
$message = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/=]+)/i', '\\1<a href="http://\\2">\\2</a>', $message);
|
||||
$message = preg_replace('/([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})/i', '<a href="mailto:\\1">\\1</a>', $message);
|
||||
$message = str_replace("\r\n","\n",$message); // Handle alternative newline characters
|
||||
$message = str_replace("\n\r","\n",$message); // Handle alternative newline characters
|
||||
@@ -613,7 +654,7 @@ class e107Email extends PHPMailer
|
||||
else
|
||||
{ // generate the plain text as the sole part of the email
|
||||
if ($this->debug) echo "Generating plain text email<br />";
|
||||
if (strpos($message,'</style>') !== FALSE)
|
||||
if (strpos($message,'</style>') !== false)
|
||||
{
|
||||
$text = strstr($message,'</style>');
|
||||
}
|
||||
@@ -630,6 +671,8 @@ class e107Email extends PHPMailer
|
||||
$this->Body = $text;
|
||||
$this->AltBody = ''; // Single part email
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -645,7 +688,7 @@ class e107Email extends PHPMailer
|
||||
{
|
||||
if (!$attachments) return;
|
||||
if (!is_array($attachments)) $attachments = array($attachments);
|
||||
$mes = e107::getMessage();
|
||||
// $mes = e107::getMessage();
|
||||
|
||||
foreach($attachments as $attach)
|
||||
{
|
||||
@@ -659,7 +702,15 @@ class e107Email extends PHPMailer
|
||||
else
|
||||
{
|
||||
$ext = pathinfo($attach, PATHINFO_EXTENSION);
|
||||
$this->addAttachment($attach, $tempName,'base64',$this->_mime_types($ext));
|
||||
try
|
||||
{
|
||||
$this->addAttachment($attach, $tempName,'base64',$this->_mime_types($ext));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -669,6 +720,8 @@ class e107Email extends PHPMailer
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -686,7 +739,17 @@ class e107Email extends PHPMailer
|
||||
if(is_readable($inline_img) && !is_dir($inline_img))
|
||||
{
|
||||
$ext = pathinfo($inline_img, PATHINFO_EXTENSION);
|
||||
$this->addEmbeddedImage($inline_img, md5($inline_img), basename($inline_img),'base64',$this->_mime_types($ext));
|
||||
|
||||
try
|
||||
{
|
||||
$this->addEmbeddedImage($inline_img, md5($inline_img), basename($inline_img),'base64',$this->_mime_types($ext));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -699,7 +762,7 @@ class e107Email extends PHPMailer
|
||||
public function preview($eml)
|
||||
{
|
||||
$this->previewMode = true;
|
||||
$mes = e107::getMessage();
|
||||
// $mes = e107::getMessage();
|
||||
|
||||
if (count($eml))
|
||||
{
|
||||
@@ -732,7 +795,7 @@ class e107Email extends PHPMailer
|
||||
|
||||
if($eml['template'] == 'texthtml' || $eml['template'] == 'textonly' )
|
||||
{
|
||||
$text = "<body style='background-color:#FFFFFF'>".$text."</body>";
|
||||
$text = "<body style='background-color:#FFFFFF;'>".$text."</body>";
|
||||
}
|
||||
|
||||
return $text;
|
||||
@@ -902,12 +965,12 @@ class e107Email extends PHPMailer
|
||||
|
||||
$identifier = deftrue('MAIL_IDENTIFIER', 'X-e107-id');
|
||||
|
||||
if (isset($eml['SMTPDebug'])) { $this->SMTPDebug = $eml['SMTPDebug']; } // 'FALSE' is a valid value!
|
||||
if (isset($eml['SMTPDebug'])) { $this->SMTPDebug = $eml['SMTPDebug']; } // 'false' is a valid value!
|
||||
if (!empty($eml['sender_email'])) { $this->From = $eml['sender_email']; }
|
||||
if (!empty($eml['sender_name'])) { $this->FromName = $eml['sender_name']; }
|
||||
if (!empty($eml['replyto'])) { $this->AddAddressList('replyto',$eml['replyto'],vartrue($eml['replytonames'],'')); }
|
||||
if (isset($eml['html'])) { $this->allow_html = $eml['html']; } // 'FALSE' is a valid value!
|
||||
if (isset($eml['html_header'])) { $this->add_HTML_header = $eml['html_header']; } // 'FALSE' is a valid value!
|
||||
if (isset($eml['html'])) { $this->allow_html = $eml['html']; } // 'false' is a valid value!
|
||||
if (isset($eml['html_header'])) { $this->add_HTML_header = $eml['html_header']; } // 'false' is a valid value!
|
||||
if (!empty($eml['body'])) { $this->makeBody($eml['body'], $this->allow_html, $this->add_HTML_header); }
|
||||
if (!empty($eml['attachment'])) { $this->attach($eml['attachment']); }
|
||||
if (!empty($eml['cc'])) { $this->AddAddressList('cc',$eml['cc'],vartrue($eml['cc_names'],'')); }
|
||||
@@ -917,7 +980,7 @@ class e107Email extends PHPMailer
|
||||
if (!empty($eml['priority'])) { $this->Priority = $eml['priority']; }
|
||||
if (!empty($eml['e107_header'])) { $this->addCustomHeader($identifier.": {$eml['e107_header']}"); }
|
||||
if (!empty($eml['wordwrap'])) { $this->WordWrap = $eml['wordwrap']; }
|
||||
if (!empty($eml['split'])) { $this->SingleTo = ($eml['split'] != FALSE); }
|
||||
if (!empty($eml['split'])) { $this->SingleTo = ($eml['split'] != false); }
|
||||
if (!empty($eml['smtp_username'])) { $this->Username = $eml['smtp_username']; }
|
||||
if (!empty($eml['smtp_password'])) { $this->Password = $eml['smtp_password']; }
|
||||
|
||||
@@ -963,45 +1026,45 @@ class e107Email extends PHPMailer
|
||||
|
||||
|
||||
/**
|
||||
Send an email where the bulk of the data is passed in an array. Returns 0 on success.
|
||||
(Even if the array is null, because everything previously set up, this is the preferred entry point)
|
||||
Where parameter not present in the array, doesn't get changed - useful for bulk mailing
|
||||
If doing bulk mailing with repetitive calls, set $bulkmail parameter true, and must call allSent() when completed
|
||||
Some of these parameters have been made compatible with the array calculated by render_email() in signup.php
|
||||
* Send an email where the bulk of the data is passed in an array. Returns 0 on success.
|
||||
* (Even if the array is null, because everything previously set up, this is the preferred entry point)
|
||||
* Where parameter not present in the array, doesn't get changed - useful for bulk mailing
|
||||
* If doing bulk mailing with repetitive calls, set $bulkmail parameter true, and must call allSent() when completed
|
||||
* Some of these parameters have been made compatible with the array calculated by render_email() in signup.php
|
||||
*
|
||||
Possible array parameters:
|
||||
|
||||
|
||||
* @param string $send_to - recipient email address
|
||||
* Possible array parameters:
|
||||
*
|
||||
* @param string $send_to - recipient email address
|
||||
* @param string $to_name - recipient name
|
||||
* @param array $eml - optional array of additional parameters (see BELOW)
|
||||
* @param array $eml {
|
||||
* Optional array of additional parameters (see BELOW)
|
||||
* @type string $eml['subject'] - Email Subject
|
||||
* @type string $eml['sender_email'] - 'From' email address
|
||||
* @type string $eml['sender_name'] - 'From' name
|
||||
* @type string $eml['replyto'] - Optional 'reply to' field
|
||||
* @type string $eml['replytonames'] - Name(s) corresponding to 'reply to' field - only used if 'replyto' used
|
||||
* @type bool $eml['send_html'] - if true, includes HTML part in messages (only those added after this flag)
|
||||
* @type bool $eml['add_html_header'] - if true, adds the 2-line DOCTYPE declaration to the front of the HTML part (but doesn't add <head>...</head>)
|
||||
* @type string $eml['body'] - message body. May be HTML or text. Added according to the current state of the HTML enable flag
|
||||
* @type string|array $eml['attach'] - string if one file, array of filenames if one or more.
|
||||
* @type string $eml['cc'] - comma-separated list of cc addresses.
|
||||
* @type string $eml['cc_names'] - comma-separated list of cc names. Optional, used only if $eml['cc'] specified
|
||||
* @type string $eml['bcc'] - comma-separated list
|
||||
* @type string $eml['bcc_names'] - comma-separated list of bcc names. Optional, used only if $eml['bcc'] specified
|
||||
* @type string $eml['bouncepath'] - Sender field (used for bounces)
|
||||
* @type string $eml['returnreceipt'] - email address for notification of receipt (reading)
|
||||
* @type array $eml['inline_images'] - array of files for inline images
|
||||
* @type int $eml['priority'] - Email priority (1 = High, 3 = Normal, 5 = low)
|
||||
* @type string $eml['e107_header'] - Adds specific 'X-e107-id:' header
|
||||
* @type string $eml['extra_header'] - additional headers (format is name: value
|
||||
* @type string $eml['wordwrap'] - Set wordwrap value
|
||||
* @type bool $eml['split'] - If true, sends an individual email to each recipient
|
||||
* @type string $eml['template'] - template to use. 'default'
|
||||
* @type array $eml['shortcodes'] - array of shortcode values. eg. array('MY_SHORTCODE'=>'12345');
|
||||
* }
|
||||
*
|
||||
* @param string $eml['subject'] - Email Subject
|
||||
* @param string $eml['sender_email'] - 'From' email address
|
||||
* @param string $eml['sender_name'] - 'From' name
|
||||
* @param string $eml['replyto'] - Optional 'reply to' field
|
||||
* @param string $eml['replytonames'] - Name(s) corresponding to 'reply to' field - only used if 'replyto' used
|
||||
* @param bool $eml['send_html'] - if TRUE, includes HTML part in messages (only those added after this flag)
|
||||
* @param bool $eml['add_html_header'] - if TRUE, adds the 2-line DOCTYPE declaration to the front of the HTML part (but doesn't add <head>...</head>)
|
||||
* @param string $eml['body'] - message body. May be HTML or text. Added according to the current state of the HTML enable flag
|
||||
* @param string|array $eml['attach'] - string if one file, array of filenames if one or more.
|
||||
* @param string $eml['cc'] - comma-separated list of cc addresses.
|
||||
* @param string $eml['cc_names'] - comma-separated list of cc names. Optional, used only if $eml['cc'] specified
|
||||
* @param string $eml['bcc'] - comma-separated list
|
||||
* @param string $eml['bcc_names'] - comma-separated list of bcc names. Optional, used only if $eml['bcc'] specified
|
||||
* @param string $eml['bouncepath'] - Sender field (used for bounces)
|
||||
* @param string $eml['returnreceipt'] - email address for notification of receipt (reading)
|
||||
* @param array $eml['inline_images'] - array of files for inline images
|
||||
* @param int $eml['priority'] - Email priority (1 = High, 3 = Normal, 5 = low)
|
||||
* @param string $eml['e107_header'] - Adds specific 'X-e107-id:' header
|
||||
* @param string $eml['extra_header'] - additional headers (format is name: value
|
||||
* @param string $eml['wordwrap'] - Set wordwrap value
|
||||
* @param bool $eml['split'] - If true, sends an individual email to each recipient
|
||||
* @param string $eml['template'] - template to use. 'default'
|
||||
* @param array $eml['shortcodes'] - array of shortcode values. eg. array('MY_SHORTCODE'=>'12345');
|
||||
*
|
||||
* @param boolean $bulkmail - set TRUE if this email is one of a bulk send; FALSE if an isolated email
|
||||
* @return boolean|string - TRUE if success, error message if failure
|
||||
* @param boolean $bulkmail - set true if this email is one of a bulk send; false if an isolated email
|
||||
* @return boolean|string - true if success, error message if failure
|
||||
*/
|
||||
public function sendEmail($send_to, $to_name, $eml = array(), $bulkmail = false)
|
||||
{
|
||||
@@ -1028,9 +1091,10 @@ class e107Email extends PHPMailer
|
||||
|
||||
$this->openLog(); // Delay log open until now, so all parameters set up
|
||||
|
||||
$result = TRUE; // Temporary 'success' flag
|
||||
$this->SendCount++;
|
||||
|
||||
$result = false;
|
||||
|
||||
if ($this->debug == false && (($this->logEnable == 0) || ($this->logEnable == 2)) )
|
||||
{
|
||||
// prevent user/script details being exposed in X-PHP-Script header
|
||||
@@ -1041,7 +1105,15 @@ class e107Email extends PHPMailer
|
||||
$_SERVER["HTTP_X_FORWARDED_FOR"] = $_SERVER['SERVER_ADDR'];
|
||||
$_SERVER["HTTP_CF_CONNECTING_IP"] = $_SERVER['SERVER_ADDR'];
|
||||
|
||||
$result = $this->send(); // Actually send email
|
||||
try
|
||||
{
|
||||
$result = $this->send(); // Actually send email
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$_SERVER['PHP_SELF'] = $oldphpself;
|
||||
@@ -1059,7 +1131,7 @@ class e107Email extends PHPMailer
|
||||
// print_a($this->Body);
|
||||
// echo "<h2>SendEmail()->AltBody</h2>";
|
||||
// print_a($this->AltBody);
|
||||
if (($this->logEnable == 3) && (($this->SendCount % 7) == 4)) $result = FALSE; // Fail one email in 7 for testing
|
||||
if (($this->logEnable == 3) && (($this->SendCount % 7) == 4)) $result = false; // Fail one email in 7 for testing
|
||||
}
|
||||
|
||||
$this->TotalSent++;
|
||||
@@ -1093,14 +1165,14 @@ class e107Email extends PHPMailer
|
||||
if ($result)
|
||||
{
|
||||
$this->closeLog();
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logLine('Error info: '.$this->ErrorInfo);
|
||||
// Error sending email
|
||||
|
||||
|
||||
e107::getLog()->e_log_event(3,debug_backtrace(),"MAIL","Send Failed",$this->ErrorInfo,FALSE,LOG_TO_ROLLING);
|
||||
e107::getLog()->e_log_event(3,debug_backtrace(),"MAIL","Send Failed",$this->ErrorInfo,false,LOG_TO_ROLLING);
|
||||
$this->TotalErrors++;
|
||||
$this->closeLog();
|
||||
return $this->ErrorInfo;
|
||||
@@ -1115,7 +1187,7 @@ class e107Email extends PHPMailer
|
||||
/**
|
||||
* Called after a bulk mailing completed, to tidy up nicely
|
||||
*
|
||||
* @return none
|
||||
* @return null
|
||||
*/
|
||||
public function allSent()
|
||||
{
|
||||
@@ -1124,20 +1196,22 @@ class e107Email extends PHPMailer
|
||||
$this->smtpClose();
|
||||
$this->SendCount = 0;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Evaluates the message and returns modifications for inline images and backgrounds
|
||||
* Also creates an alternative plain text part (unless $this->AltBody already non-empty)
|
||||
* Modification of standard PHPMailer function (which it overrides)
|
||||
* @access public
|
||||
* Evaluates the message and returns modifications for inline images and backgrounds
|
||||
* Also creates an alternative plain text part (unless $this->AltBody already non-empty)
|
||||
* Modification of standard PHPMailer function (which it overrides)
|
||||
*
|
||||
* @param string $message - the mail body to send
|
||||
* @basedir string - optional 'root part' of paths specified in email - prepended as necessary
|
||||
*
|
||||
* @return string none (message saved ready to send)
|
||||
* @access public
|
||||
*
|
||||
* @param string $message - the mail body to send
|
||||
* @param string $basedir - optional 'root part' of paths specified in email - prepended as necessary
|
||||
* @param bool $advanced
|
||||
* @return null (message saved ready to send)
|
||||
*/
|
||||
public function MsgHTML($message, $basedir = '', $advanced=false)
|
||||
{
|
||||
@@ -1207,12 +1281,13 @@ class e107Email extends PHPMailer
|
||||
if ( (strlen($basedir) > 1) && (substr($basedir,-1) != '/') && (substr($basedir,-1) != '\\')) { $basedir .= '/'; }
|
||||
if ( strlen($directory) > 1 && substr($directory,-1) != '/' && substr($directory,-1) != '\\') { $directory .= '/'; }
|
||||
//echo "Add image: {$basedir}|{$directory}|{$filename}<br />";
|
||||
if ( $this->addEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) )
|
||||
|
||||
try
|
||||
{
|
||||
// $images[1][$i] contains 'src' or 'background'
|
||||
$this->addEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType);
|
||||
$message = preg_replace("/".$images[1][$i]."=".$delim.preg_quote($images[3][$i], '/').$delim."/Ui", $images[1][$i]."=".$delim.$cid.$delim, $message);
|
||||
}
|
||||
else
|
||||
catch (Exception $e)
|
||||
{
|
||||
if ($this->debug)
|
||||
{
|
||||
@@ -1264,7 +1339,7 @@ class e107Email extends PHPMailer
|
||||
$this->AltBody = 'To view this email message, enable HTML!' . "\n\n";
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1289,12 +1364,16 @@ class e107Email extends PHPMailer
|
||||
}*/
|
||||
|
||||
|
||||
// Called by PHPMailer when SMTP debug is active.
|
||||
function handlePHPMailerDebug($str,$other)
|
||||
// Called by PHPMailer when SMTP debug is active.
|
||||
/**
|
||||
* @param $str
|
||||
*/
|
||||
function handlePHPMailerDebug($str)
|
||||
{
|
||||
$text = print_a($str,true);
|
||||
e107::getMessage()->addInfo($text);
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Generic e107 Exception handler
|
||||
//--------------------------------------
|
||||
@@ -1310,7 +1389,7 @@ class e107Exception extends Exception
|
||||
'EXCEPT',
|
||||
$this->getCode().':'.$this->getMessage(),
|
||||
$this->getTraceAsString(),
|
||||
FALSE,
|
||||
false,
|
||||
LOG_TO_ROLLING);
|
||||
}
|
||||
}
|
||||
@@ -1340,12 +1419,12 @@ class e107Exception extends Exception
|
||||
* @param string $Cc - comma-separated list of 'copy to' email addresses
|
||||
* @param string $Bcc - comma-separated list of 'blind copy to' email addresses
|
||||
* @param string $returnpath - Sets 'reply to' email address
|
||||
* @param boolean $returnreceipt - TRUE to request receipt
|
||||
* @param boolean $returnreceipt - true to request receipt
|
||||
* @param string $inline - comma separated list of images to send inline
|
||||
*
|
||||
* @return boolean TRUE if send successfully (NOT an indication of receipt!), FALSE if error
|
||||
* @return boolean true if send successfully (NOT an indication of receipt!), false if error
|
||||
*/
|
||||
function sendemail($send_to, $subject, $message, $to_name='', $send_from='', $from_name='', $attachments='', $Cc='', $Bcc='', $returnpath='', $returnreceipt='',$inline ='')
|
||||
function sendemail($send_to, $subject, $message, $to_name='', $send_from='', $from_name='', $attachments='', $Cc='', $Bcc='', $returnpath='', $returnreceipt=false,$inline ='')
|
||||
{
|
||||
global $mailheader_e107id;
|
||||
|
||||
@@ -1369,7 +1448,7 @@ function sendemail($send_to, $subject, $message, $to_name='', $send_from='', $fr
|
||||
|
||||
if (vartrue($mailheader_e107id)) $mail->addCustomHeader($identifier.": {$mailheader_e107id}");
|
||||
|
||||
$mail->legacyBody = TRUE; // Need to handle plain text email conversion to HTML
|
||||
$mail->legacyBody = true; // Need to handle plain text email conversion to HTML
|
||||
$mail->makeBody($message); // Add body, with conversion if required
|
||||
|
||||
if($Cc) $mail->AddAddressList('cc', $Cc);
|
||||
@@ -1378,7 +1457,14 @@ function sendemail($send_to, $subject, $message, $to_name='', $send_from='', $fr
|
||||
|
||||
if (trim($send_from))
|
||||
{
|
||||
$mail->setFrom($send_from, $from_name); // These have already been defaulted to sitewide options, so no need to set again if blank
|
||||
try
|
||||
{
|
||||
$mail->setFrom($send_from, $from_name); // These have already been defaulted to sitewide options, so no need to set again if blank
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
}
|
||||
|
||||
$mail->Subject = $subject;
|
||||
@@ -1394,15 +1480,15 @@ function sendemail($send_to, $subject, $message, $to_name='', $send_from='', $fr
|
||||
|
||||
if (vartrue($returnreceipt)) $mail->ConfirmReadingTo = $returnreceipt;
|
||||
|
||||
if ($mail->sendEmail($send_to,$to_name) === TRUE)
|
||||
if ($mail->sendEmail($send_to,$to_name) === true)
|
||||
{ // Success
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Error info already logged
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
|
Reference in New Issue
Block a user