1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 09:29:45 +01:00

PHPMailer updated to v5.2.13. Cleaned up SMTP options in the admin area.

This commit is contained in:
Cameron 2016-04-08 09:01:10 -07:00
parent eaf23811f5
commit 44d682965c
14 changed files with 1755 additions and 1576 deletions

View File

@ -178,6 +178,10 @@ if($_GET['mode']=="process")
*/ */
class mailout_admin extends e_admin_dispatcher class mailout_admin extends e_admin_dispatcher
{ {
@ -1061,84 +1065,19 @@ class mailout_main_ui extends e_admin_ui
// $text .= "&nbsp;<input type='checkbox' name='mail_mailer_enabled[]' value='{$mailer}' {$check} /> {$mailer}<br />"; // $text .= "&nbsp;<input type='checkbox' name='mail_mailer_enabled[]' value='{$mailer}' {$check} /> {$mailer}<br />";
} }
} }
$text .= "</td></tr>
$text .= "</td></tr>
<tr> <tr>
<td style='vertical-align:top'>".LAN_MAILOUT_115."<br /></td> <td style='vertical-align:top'>".LAN_MAILOUT_115."<br /></td>
<td> <td>";
<select class='tbox input-xxlarge' name='mailer' onchange='disp(this.value)'>\n";
$mailers = array('php','smtp','sendmail');
foreach($mailers as $opt)
{
$sel = ($pref['mailer'] == $opt) ? "selected='selected'" : '';
$text .= "<option value='{$opt}' {$sel}>{$opt}</option>\n";
}
$text .="</select> <span class='field-help'>".LAN_MAILOUT_116."</span><br />";
$text .= mailoutAdminClass::mailerPrefsTable($pref);
// SMTP. -------------->
$smtp_opts = explode(',',varset($pref['smtp_options'],''));
$smtpdisp = ($pref['mailer'] != 'smtp') ? "style='display:none;'" : '';
$text .= "<div id='smtp' {$smtpdisp}>
<table class='table adminlist' style='margin-right:auto;margin-left:0px;border:0px'>
<colgroup>
<col class='col-label' />
<col class='col-control' />
</colgroup>
";
$text .= "
<tr>
<td>".LAN_MAILOUT_87.":&nbsp;&nbsp;</td>
<td>
<input class='tbox' type='text' name='smtp_server' size='40' value='".$pref['smtp_server']."' maxlength='50' />
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_88.":&nbsp;(".LAN_OPTIONAL.")&nbsp;&nbsp;</td>
<td style='width:50%;' >
<input class='tbox' type='text' name='smtp_username' size='40' value=\"".$pref['smtp_username']."\" maxlength='50' />
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_89.":&nbsp;(".LAN_OPTIONAL.")&nbsp;&nbsp;</td>
<td>
<input class='tbox' type='password' name='smtp_password' size='40' value='".$pref['smtp_password']."' maxlength='50' />
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_90."</td><td>
<select class='tbox' name='smtp_options'>\n
<option value=''>".LAN_MAILOUT_96."</option>\n";
$selected = (in_array('secure=SSL',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_ssl'{$selected}>".LAN_MAILOUT_92."</option>\n";
$selected = (in_array('secure=TLS',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_tls'{$selected}>".LAN_MAILOUT_93."</option>\n";
$selected = (in_array('pop3auth',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_pop3auth'{$selected}>".LAN_MAILOUT_91."</option>\n";
$text .= "</select>\n<br />".LAN_MAILOUT_94."</td></tr>";
$text .= "<tr>
<td>".LAN_MAILOUT_57."</td><td>
";
$checked = (vartrue($pref['smtp_keepalive']) ) ? "checked='checked'" : '';
$text .= "<input type='checkbox' name='smtp_keepalive' value='1' {$checked} />
</td>
</tr>";
$checked = (in_array('useVERP',$smtp_opts) ? "checked='checked'" : "");
$text .= "<tr>
<td>".LAN_MAILOUT_95."</td><td>
<input type='checkbox' name='smtp_useVERP' value='1' {$checked} />
</td>
</tr>
</table></div>";
/* FIXME - posting SENDMAIL path triggers Mod-Security rules. /* FIXME - posting SENDMAIL path triggers Mod-Security rules.
@ -1402,6 +1341,7 @@ class mailout_main_ui extends e_admin_ui
$temp['smtp_server'] = $tp->toDB($_POST['smtp_server']); $temp['smtp_server'] = $tp->toDB($_POST['smtp_server']);
$temp['smtp_username'] = $tp->toDB($_POST['smtp_username']); $temp['smtp_username'] = $tp->toDB($_POST['smtp_username']);
$temp['smtp_password'] = $tp->toDB($_POST['smtp_password']); $temp['smtp_password'] = $tp->toDB($_POST['smtp_password']);
$temp['smtp_port'] = intval($_POST['smtp_port']);
$smtp_opts = array(); $smtp_opts = array();
switch (trim($_POST['smtp_options'])) switch (trim($_POST['smtp_options']))
@ -2385,114 +2325,8 @@ function sendImmediately($id)
// MAILER OPTIONS // MAILER OPTIONS
//---------------------------------------------------- //----------------------------------------------------
/* /*
function show_prefs($mailAdmin)
{
return;
$pref = e107::getPref();
$e107 = e107::getInstance();
$frm = e107::getForm();
$mes = e107::getMessage();
$ns = e107::getRender();
e107::getCache()->CachePageMD5 = '_';
$lastload = e107::getCache()->retrieve('emailLastBounce',FALSE,TRUE,TRUE);
$lastBounce = round((time() - $lastload) / 60);
$lastBounceText = ($lastBounce > 1256474) ? "<b>Never</b>" : "<b>".$lastBounce . " minutes </b>ago.";
$text = "
<form method='post' action='".e_SELF."?".e_QUERY."' id='mailsettingsform'>
<fieldset id='mail'>
<legend>".LAN_MAILOUT_110."</legend>
<table class='table adminform'>
<colgroup>
<col class='col-label' />
<col class='col-control' />
</colgroup>
<tbody>
<tr>
<td>".LAN_MAILOUT_110."<br /></td>
<td class='form-inline'>".$frm->admin_button('testemail', LAN_MAILOUT_112,'other')."&nbsp;
<input name='testaddress' class='tbox' type='text' size='40' maxlength='80' value=\"".(varset($_POST['testaddress']) ? $_POST['testaddress'] : USEREMAIL)."\" />
</td>
</tr>
<tr>
<td style='vertical-align:top'>".LAN_MAILOUT_115."<br /></td>
<td>
<select class='tbox' name='mailer' onchange='disp(this.value)'>\n";
$mailers = array('php','smtp','sendmail');
foreach($mailers as $opt)
{
$sel = ($pref['mailer'] == $opt) ? "selected='selected'" : '';
$text .= "<option value='{$opt}' {$sel}>{$opt}</option>\n";
}
$text .="</select> <span class='field-help'>".LAN_MAILOUT_116."</span><br />";
// SMTP. -------------->
$smtp_opts = explode(',',varset($pref['smtp_options'],''));
$smtpdisp = ($pref['mailer'] != 'smtp') ? "style='display:none;'" : '';
$text .= "<div id='smtp' {$smtpdisp}>
<table class='table adminlist' style='margin-right:auto;margin-left:0px;border:0px'>
<colgroup>
<col class='col-label' />
<col class='col-control' />
</colgroup>
";
$text .= "
<tr>
<td>".LAN_MAILOUT_87.":&nbsp;&nbsp;</td>
<td>
<input class='tbox' type='text' name='smtp_server' size='40' value='".$pref['smtp_server']."' maxlength='50' />
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_88.":&nbsp;(".LAN_OPTIONAL.")&nbsp;&nbsp;</td>
<td style='width:50%;' >
<input class='tbox' type='text' name='smtp_username' size='40' value=\"".$pref['smtp_username']."\" maxlength='50' />
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_89.":&nbsp;(".LAN_OPTIONAL.")&nbsp;&nbsp;</td>
<td>
<input class='tbox' type='password' name='smtp_password' size='40' value='".$pref['smtp_password']."' maxlength='50' />
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_90."</td><td>
<select class='tbox' name='smtp_options'>\n
<option value=''>".LAN_MAILOUT_96."</option>\n";
$selected = (in_array('secure=SSL',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_ssl'{$selected}>".LAN_MAILOUT_92."</option>\n";
$selected = (in_array('secure=TLS',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_tls'{$selected}>".LAN_MAILOUT_93."</option>\n";
$selected = (in_array('pop3auth',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_pop3auth'{$selected}>".LAN_MAILOUT_91."</option>\n";
$text .= "</select>\n<br />".LAN_MAILOUT_94."</td></tr>";
$text .= "<tr>
<td>".LAN_MAILOUT_57."</td><td>
";
$checked = (varsettrue($pref['smtp_keepalive']) ) ? "checked='checked'" : '';
$text .= "<input type='checkbox' name='smtp_keepalive' value='1' {$checked} />
</td>
</tr>";
$checked = (in_array('useVERP',$smtp_opts) ? "checked='checked'" : "");
$text .= "<tr>
<td>".LAN_MAILOUT_95."</td><td>
<input type='checkbox' name='smtp_useVERP' value='1' {$checked} />
</td>
</tr>
</table></div>";
*/
/* FIXME - posting SENDMAIL path triggers Mod-Security rules. /* FIXME - posting SENDMAIL path triggers Mod-Security rules.
// Sendmail. --------------> // Sendmail. -------------->
$senddisp = ($pref['mailer'] != 'sendmail') ? "style='display:none;'" : ''; $senddisp = ($pref['mailer'] != 'sendmail') ? "style='display:none;'" : '';
@ -2747,25 +2581,6 @@ function headerjs()
$text = " $text = "
<script type='text/javascript'> <script type='text/javascript'>
function disp(type)
{
if(type == 'smtp')
{
document.getElementById('smtp').style.display = '';
document.getElementById('sendmail').style.display = 'none';
return;
}
if(type =='sendmail')
{
document.getElementById('smtp').style.display = 'none';
document.getElementById('sendmail').style.display = '';
return;
}
document.getElementById('smtp').style.display = 'none';
document.getElementById('sendmail').style.display = 'none';
}
function bouncedisp(type) function bouncedisp(type)
{ {

View File

@ -27,33 +27,14 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
$e_sub_cat = 'prefs'; $e_sub_cat = 'prefs';
e107::lan('core','mailout','admin'); e107::lan('core','mailout','admin');
e107::js('inline',"
function disp(type)
{
if(type == 'smtp')
{
$('#smtp').show('slow');
$('#sendmail').hide('slow');
return;
}
if(type =='sendmail')
{
$('#smtp').hide('slow');
$('#sendmail').show('slow');
return;
}
$('#smtp').hide('slow');
$('#sendmail').hide('slow');
}
",'jquery');
require_once (e_ADMIN."auth.php"); require_once (e_ADMIN."auth.php");
$e_userclass = e107::getUserClass(); $e_userclass = e107::getUserClass();
require_once (e_HANDLER."user_extended_class.php"); require_once (e_HANDLER."user_extended_class.php");
require_once(e_HANDLER.'mailout_admin_class.php'); // Admin tasks handler
$ue = new e107_user_extended(); $ue = new e107_user_extended();
$core_pref = e107::getConfig(); $core_pref = e107::getConfig();
@ -459,114 +440,12 @@ $text .= "<fieldset class='e-hideme' id='core-prefs-email'>
<tr> <tr>
<td style='vertical-align:top'><label for='mailer'>".LAN_MAILOUT_115."</label><br /></td> <td style='vertical-align:top'><label for='mailer'>".LAN_MAILOUT_115."</label><br /></td>
<td> <td>";
<select class='tbox' name='mailer' id='mailer' onchange='disp(this.value)'>\n";
$mailers = array('php','smtp','sendmail');
foreach($mailers as $opt)
{
$sel = ($pref['mailer'] == $opt) ? "selected='selected'" : '';
$text .= "<option value='{$opt}' {$sel}>{$opt}</option>\n";
}
$text .="</select> <span class='field-help'>".LAN_MAILOUT_116."</span><br />";
// SMTP. --------------> $text .= mailoutAdminClass::mailerPrefsTable($pref);
$smtp_opts = explode(',',varset($pref['smtp_options'],''));
$smtpdisp = ($pref['mailer'] != 'smtp') ? "style='display:none;'" : '';
$text .= "<div id='smtp' {$smtpdisp}>
<table class='table adminlist' style='margin-right:auto;margin-left:0px;border:0px'>
<colgroup>
<col class='col-label' />
<col class='col-control' />
</colgroup>
";
$text .= "
<tr>
<td><label for='smtp_server'>".LAN_MAILOUT_87.":&nbsp;&nbsp;</label></td>
<td>
<input class='tbox' type='text' name='smtp_server' id='smtp_server' size='40' value='".vartrue($pref['smtp_server'])."' maxlength='50' autocomplete='off' />
</td>
</tr>
<tr>
<td><label for='smtp_username'>".LAN_MAILOUT_88.":&nbsp;(".LAN_OPTIONAL.")&nbsp;&nbsp;</label></td>
<td style='width:50%;' >
<input class='tbox' type='text' name='smtp_username' id='smtp_username' size='40' value=\"".vartrue($pref['smtp_username'])."\" maxlength='50' autocomplete='off' />
</td>
</tr>
<tr>
<td><label for='smtp_password'>".LAN_MAILOUT_89.":&nbsp;(".LAN_OPTIONAL.")&nbsp;&nbsp;</label></td>
<td>
<input class='tbox' type='password' name='smtp_password' id='smtp_password' size='40' value='".vartrue($pref['smtp_password'])."' maxlength='50' autocomplete='off' />
</td>
</tr>
<tr>
<td><label for='smtp_options'>".LAN_MAILOUT_90."</label></td><td>
";
$sslOpts = array(
'smtp_ssl' => LAN_MAILOUT_92,
'smtp_tls' => LAN_MAILOUT_93,
'smtp_pop3auth' => LAN_MAILOUT_91
);
// $text .= $frm->select('smtp_options', $sslOpts, $smtp_opts, '', LAN_MAILOUT_96);
$text .="<select class='tbox' name='smtp_options' id='smtp_options'>\n
<option value=''>".LAN_MAILOUT_96."</option>\n";
$selected = (in_array('secure=SSL',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_ssl'{$selected}>".LAN_MAILOUT_92."</option>\n";
$selected = (in_array('secure=TLS',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_tls'{$selected}>".LAN_MAILOUT_93."</option>\n";
$selected = (in_array('pop3auth',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_pop3auth'{$selected}>".LAN_MAILOUT_91."</option>\n";
$text .= "</select>";
$text .= "<span class='field-help'>".LAN_MAILOUT_94."</span></td></tr>";
$text .= "<tr>
<td><label for='smtp_keepalive'>".LAN_MAILOUT_57."</label></td><td>\n";
$text .= $frm->radio_switch('smtp_keepalive', $pref['smtp_keepalive'])."
</td>
</tr>";
$text .= "<tr>
<td><label for='smtp_useVERP'>".LAN_MAILOUT_95."</label></td><td>".$frm->radio_switch('smtp_useVERP',(in_array('useVERP',$smtp_opts)))."
</td>
</tr>
</table></div>";
/* FIXME - posting SENDMAIL path triggers Mod-Security rules.
// Sendmail. -------------->
$text .= "<div id='sendmail' {$senddisp}><table style='margin-right:0px;margin-left:auto;border:0px'>";
$text .= "
<tr>
<td>".LAN_MAILOUT_20.":&nbsp;&nbsp;</td>
<td>
<input class='tbox' type='text' name='sendmail' size='60' value=\"".(!$pref['sendmail'] ? "/usr/sbin/sendmail -t -i -r ".$pref['siteadminemail'] : $pref['sendmail'])."\" maxlength='80' />
</td>
</tr>
</table></div>";
*/
$senddisp = (varset($pref['mailer']) != 'sendmail') ? "e-hideme" : '';
$text .= "<div class='s-message info {$senddisp}' id='sendmail' >
Not available in this release
</div>";
$text .="</td> $text .="</td>
</tr> </tr>

View File

@ -297,6 +297,7 @@ City, State, Country
<core name="smtp_username"></core> <core name="smtp_username"></core>
<core name="smtp_password"></core> <core name="smtp_password"></core>
<core name="smtp_options"></core> <core name="smtp_options"></core>
<core name="smtp_port">25</core>
<core name="social_login_active">0</core> <core name="social_login_active">0</core>
<core name="social_login"><![CDATA[array()]]></core> <core name="social_login"><![CDATA[array()]]></core>
<core name="ssl_enabled">0</core> <core name="ssl_enabled">0</core>

View File

@ -1970,12 +1970,13 @@ class e_form
/** /**
* *
* @param string $name * @param string $name
* @param array $option_array * @param array $option_array
* @param boolean $selected [optional] * @param boolean $selected [optional]
* @param string|array $options [optional] * @param string|array $options [optional]
* @param boolean|string $defaultBlank [optional] set to TRUE if the first entry should be blank, or to a string to use it for the blank description. * @param bool $options['useValues'] when true uses array values as the key.
* @return string HTML text for display * @param bool|string $defaultBlank [optional] set to TRUE if the first entry should be blank, or to a string to use it for the blank description.
* @return string HTML text for display
*/ */
function select($name, $option_array, $selected = false, $options = array(), $defaultBlank= false) function select($name, $option_array, $selected = false, $options = array(), $defaultBlank= false)
{ {

View File

@ -180,7 +180,7 @@ class e107Email extends PHPMailer
'smtp_server' => 'smtp_server', 'smtp_server' => 'smtp_server',
'smtp_username' => 'smtp_username', 'smtp_username' => 'smtp_username',
'smtp_password' => 'smtp_password', 'smtp_password' => 'smtp_password',
'smtp_port' => 'smtp_port',
); );
/** /**
* Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed * Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed
@ -210,24 +210,27 @@ class e107Email extends PHPMailer
$this->CharSet = 'utf-8'; $this->CharSet = 'utf-8';
$this->SetLanguage(CORE_LC); $this->SetLanguage(CORE_LC);
$smtpPort = 465;
if (($overrides === FALSE) || !is_array($overrides)) if (($overrides === FALSE) || !is_array($overrides))
{ {
$overrides = array(); $overrides = array();
} }
foreach (array('mailer', 'smtp_server', 'smtp_username', 'smtp_password', 'sendmail', 'siteadminemail', 'siteadmin') as $k) foreach (array('mailer', 'smtp_server', 'smtp_username', 'smtp_password', 'smtp_port', 'sendmail', 'siteadminemail', 'siteadmin') as $k)
{ {
if (!isset($overrides[$k])) $overrides[$k] = $pref[$k]; if (!isset($overrides[$k])) $overrides[$k] = $pref[$k];
} }
if(strpos($overrides['smtp_server'],':')!== false) if(strpos($overrides['smtp_server'],':')!== false)
{ {
list($smtpServer,$smtpPort) = explode(":", $overrides['smtp_server']); list($smtpServer,$smtpPort) = explode(":", $overrides['smtp_server']);
$overrides['smtp_server'] = $smtpServer; $overrides['smtp_server'] = $smtpServer;
} }
else
{
$smtpPort = varset($overrides['smtp_post'], 25);
}
$this->pause_amount = varset($pref['mail_pause'], 10); $this->pause_amount = varset($pref['mail_pause'], 10);
@ -913,35 +916,37 @@ class e107Email extends PHPMailer
Some of these parameters have been made compatible with the array calculated by render_email() in signup.php Some of these parameters have been made compatible with the array calculated by render_email() in signup.php
* *
Possible array parameters: Possible array parameters:
$eml['subject']
$eml['sender_email'] - 'From' email address
$eml['sender_name'] - 'From' name
$eml['replyto'] - Optional 'reply to' field
$eml['replytonames'] - Name(s) corresponding to 'reply to' field - only used if 'replyto' used
$eml['send_html'] - if TRUE, includes HTML part in messages (only those added after this flag)
$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>)
$eml['body'] - message body. May be HTML or text. Added according to the current state of the HTML enable flag
$eml['attach'] - string if one file, array of filenames if one or more.
$eml['copy_to'] - comma-separated list of cc addresses.
$eml['cc_names'] - comma-separated list of cc names. Optional, used only if $eml['copy_to'] specified
$eml['bcopy_to'] - comma-separated list
$eml['bcc_names'] - comma-separated list of bcc names. Optional, used only if $eml['copy_to'] specified
$eml['bouncepath'] - Sender field (used for bounces)
$eml['returnreceipt'] - email address for notification of receipt (reading)
$eml['inline_images'] - array of files for inline images
$eml['priority'] - Email priority (1 = High, 3 = Normal, 5 = low)
$eml['e107_header'] - Adds specific 'X-e107-id:' header
$eml['extra_header'] - additional headers (format is name: value
$eml['wordwrap'] - Set wordwrap value
$eml['split'] - If true, sends an individual email to each recipient
$eml['template'] - template to use. 'default'
$eml['shortcodes'] - array of shortcode values. eg. array('MY_SHORTCODE'=>'12345');
* @param string $send_to - recipient email address * @param string $send_to - recipient email address
* @param string $to_name - recipient name * @param string $to_name - recipient name
* @param array $eml - optional array of additional parameters (see above) * @param array $eml - optional array of additional parameters (see BELOW)
* @param boolean $bulkmail - set TRUE if this email is one of a bulk send; FALSE if an isolated email
* *
* @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['copy_to'] - comma-separated list of cc addresses.
* @param string $eml['cc_names'] - comma-separated list of cc names. Optional, used only if $eml['copy_to'] specified
* @param string $eml['bcopy_to'] - comma-separated list
* @param string $eml['bcc_names'] - comma-separated list of bcc names. Optional, used only if $eml['copy_to'] 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 * @return boolean|string - TRUE if success, error message if failure
*/ */
public function sendEmail($send_to, $to_name, $eml = '', $bulkmail = false) public function sendEmail($send_to, $to_name, $eml = '', $bulkmail = false)
@ -1209,7 +1214,8 @@ class e107MailerException extends phpmailerException
// Called by PHPMailer when SMTP debug is active. // Called by PHPMailer when SMTP debug is active.
function handlePHPMailerDebug($str,$other) function handlePHPMailerDebug($str,$other)
{ {
e107::getMessage()->addInfo($str); $text = print_a($str,true);
e107::getMessage()->addInfo($text);
} }
//-------------------------------------- //--------------------------------------
// Generic e107 Exception handler // Generic e107 Exception handler

View File

@ -2097,5 +2097,137 @@ class mailoutAdminClass extends e107MailManager
*/ */
} }
public static function mailerPrefsTable($pref)
{
$frm = e107::getForm();
$mailers = array('php'=>'php','smtp'=>'smtp','sendmail'=>'sendmail');
$smtp_opts = explode(',',varset($pref['smtp_options'],''));
$smtpdisp = ($pref['mailer'] != 'smtp') ? "style='display:none;'" : '';
$text = $frm->select('mailer', $mailers, $pref['mailer'])."
<span class='field-help'>".LAN_MAILOUT_116."</span>";
$text .= "<div id='smtp' {$smtpdisp}>
<table class='table table-bordered adminlist' style='margin-top:10px;width:auto;margin-right:auto;margin-left:0'>
<colgroup>
<col class='col-label' />
<col class='col-control' />
</colgroup>
";
$ports = array(25=>'25 ('.LAN_DEFAULT.")",26=>'26',465=>'465 (SSL)', 587=>'587', 2465=>'2465', 2525=>'2525', 2587=>'2587');
$text .= "
<tr>
<td>".LAN_MAILOUT_87.":&nbsp;&nbsp;</td>
<td>".$frm->text('smtp_server',$pref['smtp_server'], 50, array('size'=>'xxlarge'))."</td>
</tr>
<tr>
<td>".LAN_MAILOUT_88.":</td>
<td style='width:50%;' >".$frm->text('smtp_username',$pref['smtp_username'], 50, array('size'=>'xxlarge', 'placeholder'=>"(".LAN_OPTIONAL.")"))."</td>
</tr>
<tr>
<td>".LAN_MAILOUT_89.":</td>
<td>".$frm->password('smtp_password',$pref['smtp_password'], 50, array('size'=>'xxlarge', 'placeholder'=>"(".LAN_OPTIONAL.")"))."
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_260."</td>
<td>".$frm->select('smtp_port',$ports, $pref['smtp_port'])."
</td>
</tr>
<tr>
<td>".LAN_MAILOUT_90."</td><td>
<select class='tbox' name='smtp_options'>\n
<option value=''>".LAN_MAILOUT_96."</option>\n";
$selected = (in_array('secure=SSL',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_ssl'{$selected}>".LAN_MAILOUT_92."</option>\n";
$selected = (in_array('secure=TLS',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_tls'{$selected}>".LAN_MAILOUT_93."</option>\n";
$selected = (in_array('pop3auth',$smtp_opts) ? " selected='selected'" : '');
$text .= "<option value='smtp_pop3auth'{$selected}>".LAN_MAILOUT_91."</option>\n";
$text .= "</select></td></tr>";
$text .= "<tr>
<td><label for='smtp_keepalive'>".LAN_MAILOUT_57."</label></td><td>\n";
$text .= $frm->radio_switch('smtp_keepalive', $pref['smtp_keepalive'])."
</td>
</tr>";
$text .= "<tr>
<td><label for='smtp_useVERP'>".LAN_MAILOUT_95."</label></td><td>".$frm->radio_switch('smtp_useVERP',(in_array('useVERP',$smtp_opts)))."
</td>
</tr>
</table></div>";
/* FIXME - posting SENDMAIL path triggers Mod-Security rules. use define() in e107_config.php instead.
// Sendmail. -------------->
$text .= "<div id='sendmail' {$senddisp}><table style='margin-right:0px;margin-left:auto;border:0px'>";
$text .= "
<tr>
<td>".LAN_MAILOUT_20.":&nbsp;&nbsp;</td>
<td>
<input class='tbox' type='text' name='sendmail' size='60' value=\"".(!$pref['sendmail'] ? "/usr/sbin/sendmail -t -i -r ".$pref['siteadminemail'] : $pref['sendmail'])."\" maxlength='80' />
</td>
</tr>
</table></div>";
*/
e107::js('footer-inline', "
$('#mailer').on('change', function() {
var type = $(this).val();
if(type == 'smtp')
{
$('#smtp').show('slow');
$('#sendmail').hide('slow');
return;
}
if(type =='sendmail')
{
$('#smtp').hide('slow');
$('#sendmail').show('slow');
return;
}
$('#smtp').hide('slow');
$('#sendmail').hide('slow');
});
");
return $text;
}
} }
?> ?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,197 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.4
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note 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.
*/
/**
* PHPMailerOAuth - PHPMailer subclass adding OAuth support.
* @package PHPMailer
* @author @sherryl4george
* @author Marcus Bointon (@Synchro) <phpmailer@synchromedia.co.uk>
*/
class PHPMailerOAuth extends PHPMailer
{
/**
* The OAuth user's email address
* @type string
*/
public $oauthUserEmail = '';
/**
* The OAuth refresh token
* @type string
*/
public $oauthRefreshToken = '';
/**
* The OAuth client ID
* @type string
*/
public $oauthClientId = '';
/**
* The OAuth client secret
* @type string
*/
public $oauthClientSecret = '';
/**
* An instance of the OAuth class.
* @type OAuth
* @access protected
*/
protected $oauth = null;
/**
* Get an OAuth instance to use.
* @return OAuth
*/
public function getOAUTHInstance()
{
if (!is_object($this->oauth)) {
$this->oauth = new PHPMailerOAuthGoogle(
$this->oauthUserEmail,
$this->oauthClientSecret,
$this->oauthClientId,
$this->oauthRefreshToken
);
}
return $this->oauth;
}
/**
* Initiate a connection to an SMTP server.
* Overrides the original smtpConnect method to add support for OAuth.
* @param array $options An array of options compatible with stream_context_create()
* @uses SMTP
* @access public
* @throws phpmailerException
* @return boolean
*/
public function smtpConnect($options = array())
{
if (is_null($this->smtp)) {
$this->smtp = $this->getSMTPInstance();
}
if (is_null($this->oauth)) {
$this->oauth = $this->getOAUTHInstance();
}
// Already connected?
if ($this->smtp->connected()) {
return true;
}
$this->smtp->setTimeout($this->Timeout);
$this->smtp->setDebugLevel($this->SMTPDebug);
$this->smtp->setDebugOutput($this->Debugoutput);
$this->smtp->setVerp($this->do_verp);
$hosts = explode(';', $this->Host);
$lastexception = null;
foreach ($hosts as $hostentry) {
$hostinfo = array();
if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
// Not a valid host entry
continue;
}
// $hostinfo[2]: optional ssl or tls prefix
// $hostinfo[3]: the hostname
// $hostinfo[4]: optional port number
// The host string prefix can temporarily override the current setting for SMTPSecure
// If it's not specified, the default value is used
$prefix = '';
$secure = $this->SMTPSecure;
$tls = ($this->SMTPSecure == 'tls');
if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) {
$prefix = 'ssl://';
$tls = false; // Can't have SSL and TLS at the same time
$secure = 'ssl';
} elseif ($hostinfo[2] == 'tls') {
$tls = true;
// tls doesn't use a prefix
$secure = 'tls';
}
//Do we need the OpenSSL extension?
$sslext = defined('OPENSSL_ALGO_SHA1');
if ('tls' === $secure or 'ssl' === $secure) {
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
if (!$sslext) {
throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
}
}
$host = $hostinfo[3];
$port = $this->Port;
$tport = (integer)$hostinfo[4];
if ($tport > 0 and $tport < 65536) {
$port = $tport;
}
if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) {
try {
if ($this->Helo) {
$hello = $this->Helo;
} else {
$hello = $this->serverHostname();
}
$this->smtp->hello($hello);
//Automatically enable TLS encryption if:
// * it's not disabled
// * we have openssl extension
// * we are not already using SSL
// * the server offers STARTTLS
if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) {
$tls = true;
}
if ($tls) {
if (!$this->smtp->startTLS()) {
throw new phpmailerException($this->lang('connect_host'));
}
// We must resend HELO after tls negotiation
$this->smtp->hello($hello);
}
if ($this->SMTPAuth) {
if (!$this->smtp->authenticate(
$this->Username,
$this->Password,
$this->AuthType,
$this->Realm,
$this->Workstation,
$this->oauth
)
) {
throw new phpmailerException($this->lang('authenticate'));
}
}
return true;
} catch (phpmailerException $exc) {
$lastexception = $exc;
$this->edebug($exc->getMessage());
// We must have connected, but then failed TLS or Auth, so close connection nicely
$this->smtp->quit();
}
}
}
// If we get here, all connection attempts have failed, so close connection hard
$this->smtp->close();
// As we've caught all exceptions, just report whatever the last one was
if ($this->exceptions and !is_null($lastexception)) {
throw $lastexception;
}
return false;
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.4
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @note 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.
*/
/**
* PHPMailerOAuthGoogle - Wrapper for League OAuth2 Google provider.
* @package PHPMailer
* @author @sherryl4george
* @author Marcus Bointon (@Synchro) <phpmailer@synchromedia.co.uk>
* @link https://github.com/thephpleague/oauth2-client
*/
class PHPMailerOAuthGoogle
{
private $oauthUserEmail = '';
private $oauthRefreshToken = '';
private $oauthClientId = '';
private $oauthClientSecret = '';
public function __construct(
$UserEmail,
$ClientSecret,
$ClientId,
$RefreshToken
) {
$this->oauthClientId = $ClientId;
$this->oauthClientSecret = $ClientSecret;
$this->oauthRefreshToken = $RefreshToken;
$this->oauthUserEmail = $UserEmail;
}
private function getProvider() {
return new League\OAuth2\Client\Provider\Google([
'clientId' => $this->oauthClientId,
'clientSecret' => $this->oauthClientSecret
]);
}
private function getGrant()
{
return new \League\OAuth2\Client\Grant\RefreshToken();
}
private function getToken()
{
$provider = $this->getProvider();
$grant = $this->getGrant();
return $provider->getAccessToken($grant, ['refresh_token' => $this->oauthRefreshToken]);
}
public function getOauth64()
{
$token = $this->getToken();
return base64_encode("user=" . $this->oauthUserEmail . "\001auth=Bearer " . $token . "\001\001");
}
}

View File

@ -34,18 +34,18 @@ class POP3
* @type string * @type string
* @access public * @access public
*/ */
public $Version = '5.2.8'; public $Version = '5.2.13';
/** /**
* Default POP3 port number. * Default POP3 port number.
* @type int * @type integer
* @access public * @access public
*/ */
public $POP3_PORT = 110; public $POP3_PORT = 110;
/** /**
* Default timeout in seconds. * Default timeout in seconds.
* @type int * @type integer
* @access public * @access public
*/ */
public $POP3_TIMEOUT = 30; public $POP3_TIMEOUT = 30;
@ -61,7 +61,7 @@ class POP3
/** /**
* Debug display level. * Debug display level.
* Options: 0 = no, 1+ = yes * Options: 0 = no, 1+ = yes
* @type int * @type integer
* @access public * @access public
*/ */
public $do_debug = 0; public $do_debug = 0;
@ -75,14 +75,14 @@ class POP3
/** /**
* POP3 port number. * POP3 port number.
* @type int * @type integer
* @access public * @access public
*/ */
public $port; public $port;
/** /**
* POP3 Timeout Value in seconds. * POP3 Timeout Value in seconds.
* @type int * @type integer
* @access public * @access public
*/ */
public $tval; public $tval;
@ -110,54 +110,43 @@ class POP3
/** /**
* Are we connected? * Are we connected?
* @type bool * @type boolean
* @access private * @access private
*/ */
private $connected; private $connected = false;
/** /**
* Error container. * Error container.
* @type array * @type array
* @access private * @access private
*/ */
private $error; private $errors = array();
/** /**
* Line break constant * Line break constant
*/ */
const CRLF = "\r\n"; const CRLF = "\r\n";
/**
* Constructor.
* @access public
*/
public function __construct()
{
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}
/** /**
* Simple static wrapper for all-in-one POP before SMTP * Simple static wrapper for all-in-one POP before SMTP
* @param $host * @param $host
* @param bool $port * @param integer|boolean $port The port number to connect to
* @param bool $tval * @param integer|boolean $timeout The timeout value
* @param string $username * @param string $username
* @param string $password * @param string $password
* @param int $debug_level * @param integer $debug_level
* @return bool * @return boolean
*/ */
public static function popBeforeSmtp( public static function popBeforeSmtp(
$host, $host,
$port = false, $port = false,
$tval = false, $timeout = false,
$username = '', $username = '',
$password = '', $password = '',
$debug_level = 0 $debug_level = 0
) { ) {
$pop = new POP3; $pop = new POP3;
return $pop->authorise($host, $port, $tval, $username, $password, $debug_level); return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
} }
/** /**
@ -165,34 +154,34 @@ class POP3
* A connect, login, disconnect sequence * A connect, login, disconnect sequence
* appropriate for POP-before SMTP authorisation. * appropriate for POP-before SMTP authorisation.
* @access public * @access public
* @param string $host * @param string $host The hostname to connect to
* @param bool|int $port * @param integer|boolean $port The port number to connect to
* @param bool|int $tval * @param integer|boolean $timeout The timeout value
* @param string $username * @param string $username
* @param string $password * @param string $password
* @param int $debug_level * @param integer $debug_level
* @return bool * @return boolean
*/ */
public function authorise($host, $port = false, $tval = false, $username = '', $password = '', $debug_level = 0) public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
{ {
$this->host = $host; $this->host = $host;
// If no port value provided, use default // If no port value provided, use default
if ($port === false) { if (false === $port) {
$this->port = $this->POP3_PORT; $this->port = $this->POP3_PORT;
} else { } else {
$this->port = $port; $this->port = (integer)$port;
} }
// If no timeout value provided, use default // If no timeout value provided, use default
if ($tval === false) { if (false === $timeout) {
$this->tval = $this->POP3_TIMEOUT; $this->tval = $this->POP3_TIMEOUT;
} else { } else {
$this->tval = $tval; $this->tval = (integer)$timeout;
} }
$this->do_debug = $debug_level; $this->do_debug = $debug_level;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
// Refresh the error log // Reset the error log
$this->error = null; $this->errors = array();
// connect // connect
$result = $this->connect($this->host, $this->port, $this->tval); $result = $this->connect($this->host, $this->port, $this->tval);
if ($result) { if ($result) {
@ -211,7 +200,7 @@ class POP3
* Connect to a POP3 server. * Connect to a POP3 server.
* @access public * @access public
* @param string $host * @param string $host
* @param bool|int $port * @param integer|boolean $port
* @param integer $tval * @param integer $tval
* @return boolean * @return boolean
*/ */
@ -226,6 +215,10 @@ class POP3
//Rather than suppress it with @fsockopen, capture it cleanly instead //Rather than suppress it with @fsockopen, capture it cleanly instead
set_error_handler(array($this, 'catchWarning')); set_error_handler(array($this, 'catchWarning'));
if (false === $port) {
$port = $this->POP3_PORT;
}
// connect to the POP3 server // connect to the POP3 server
$this->pop_conn = fsockopen( $this->pop_conn = fsockopen(
$host, // POP3 Host $host, // POP3 Host
@ -236,34 +229,20 @@ class POP3
); // Timeout (seconds) ); // Timeout (seconds)
// Restore the error handler // Restore the error handler
restore_error_handler(); restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
}
// Did we connect? // Did we connect?
if ($this->pop_conn == false) { if (false === $this->pop_conn) {
// It would appear not... // It would appear not...
$this->error = array( $this->setError(array(
'error' => "Failed to connect to server $host on port $port", 'error' => "Failed to connect to server $host on port $port",
'errno' => $errno, 'errno' => $errno,
'errstr' => $errstr 'errstr' => $errstr
); ));
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false; return false;
} }
// Increase the stream time-out // Increase the stream time-out
// Check for PHP 4.3.0 or later stream_set_timeout($this->pop_conn, $tval, 0);
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 // Get the POP3 server response
$pop3_response = $this->getResponse(); $pop3_response = $this->getResponse();
@ -286,12 +265,8 @@ class POP3
*/ */
public function login($username = '', $password = '') public function login($username = '', $password = '')
{ {
if ($this->connected == false) { if (!$this->connected) {
$this->error = 'Not connected to POP3 server'; $this->setError('Not connected to POP3 server');
if ($this->do_debug >= 1) {
$this->displayErrors();
}
} }
if (empty($username)) { if (empty($username)) {
$username = $this->username; $username = $this->username;
@ -323,7 +298,11 @@ class POP3
$this->sendString('QUIT'); $this->sendString('QUIT');
//The QUIT command may cause the daemon to exit, which will kill our connection //The QUIT command may cause the daemon to exit, which will kill our connection
//So ignore errors here //So ignore errors here
@fclose($this->pop_conn); try {
@fclose($this->pop_conn);
} catch (Exception $e) {
//Do nothing
};
} }
/** /**
@ -369,14 +348,11 @@ class POP3
private function checkResponse($string) private function checkResponse($string)
{ {
if (substr($string, 0, 3) !== '+OK') { if (substr($string, 0, 3) !== '+OK') {
$this->error = array( $this->setError(array(
'error' => "Server reported an error: $string", 'error' => "Server reported an error: $string",
'errno' => 0, 'errno' => 0,
'errstr' => '' 'errstr' => ''
); ));
if ($this->do_debug >= 1) {
$this->displayErrors();
}
return false; return false;
} else { } else {
return true; return true;
@ -384,16 +360,20 @@ class POP3
} }
/** /**
* Display errors if debug is enabled. * Add an error to the internal error store.
* @access private * Also display debug output if it's enabled.
* @param $error
*/ */
private function displayErrors() private function setError($error)
{ {
echo '<pre>'; $this->errors[] = $error;
foreach ($this->error as $single_error) { if ($this->do_debug >= 1) {
print_r($single_error); echo '<pre>';
foreach ($this->errors as $error) {
print_r($error);
}
echo '</pre>';
} }
echo '</pre>';
} }
/** /**
@ -406,12 +386,12 @@ class POP3
*/ */
private function catchWarning($errno, $errstr, $errfile, $errline) private function catchWarning($errno, $errstr, $errfile, $errline)
{ {
$this->error[] = array( $this->setError(array(
'error' => "Connecting to the POP3 server raised a PHP warning: ", 'error' => "Connecting to the POP3 server raised a PHP warning: ",
'errno' => $errno, 'errno' => $errno,
'errstr' => $errstr, 'errstr' => $errstr,
'errfile' => $errfile, 'errfile' => $errfile,
'errline' => $errline 'errline' => $errline
); ));
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
<?php
/**
* Get an OAuth2 token from Google.
* * Install this script on your server so that it's accessible
* as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
* e.g.: http://localhost/phpmail/get_oauth_token.php
* * Ensure dependencies are installed with 'composer install'
* * Set up an app in your Google developer console
* * Set the script address as the app's redirect URL
* If no refresh token is obtained when running this file, revoke access to your app
* using link: https://accounts.google.com/b/0/IssuedAuthSubTokens and run the script again.
* This script requires PHP 5.4 or later
*/
require 'vendor/autoload.php';
session_start();
//If this automatic URL doesn't work, set it yourself manually
$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
//$redirectUri = 'http://localhost/phpmailer/get_oauth_token.php';
$clientId = 'RANDOMCHARS-----duv1n2.apps.googleusercontent.com';
$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
//All details obtained by setting up app in Google developer console.
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
$provider = new League\OAuth2\Client\Provider\Google (
[
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'redirectUri' => $redirectUri,
'scopes' => ['https://mail.google.com/'],
'accessType' => 'offline'
]
);
if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->state;
header('Location: ' . $authUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
$provider->accessType = 'offline';
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken(
'authorization_code',
[
'code' => $_GET['code']
]
);
// Use this to interact with an API on the users behalf
// echo $token->accessToken.'<br>';
// Use this to get a new access token if the old one expires
echo 'Refresh Token: ' . $token->refreshToken;
// Unix timestamp of when the token will expire, and need refreshing
// echo $token->expires;
}

View File

@ -1,509 +0,0 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/phpmailer/mailout_process.php,v $
* $Revision$
* $Date$
* $Author$
|
| Modifications in hand to work with most recent mailout.php
To do:
1. Admin log entries?
2. Option to add user name in subject line - support |...| and {...} - done; test
3. Strip bbcode from plain text emails (ideally needs updated parser).
4. Support phpmailer 2.0 options
5. Log cancellation of email run
|
+----------------------------------------------------------------------------+
*/
require_once("../../class2.php");
if(!getperms("W")){ header("location:".e_BASE."index.php"); exit; }
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_mailout.php");
// Directory for log (if enabled)
//FIXME need another name
define('MAIL_LOG_PATH',e_LOG);
$HEADER = "";
$FOOTER = "";
define("e_PAGETITLE",LAN_MAILOUT_60);
require_once(HEADERF);
set_time_limit(18000);
session_write_close();
// $logenable - 0 = log disabled, 1 = 'dry run' (debug and log, no send). 2 = 'log all' (send, and log result). 3 = 'dry run' with failures
// $add_email - 1 includes email detail in log
list($logenable,$add_email) = explode(',',varset($pref['mail_log_options'],'0,0'));
if($_POST['cancel_emails'])
{
$sql -> db_Delete("generic", "gen_datestamp='".intval($_POST['mail_id'])."' ");
$text = "<div style='text-align:center;width:220px'><br />".LAN_MAILOUT_66; // Cancelled Successfully;
$text .= "<div style='text-align:center;margin-left:auto;margin-right:auto;position:absolute;left:10px;top:110px'>
<br /><input type='button' class='btn btn-primary button' name='close' value='Close' onclick=\"window.close()\" />
</div></div>";
$ns -> tablerender(LAN_MAILOUT_59, $text);
echo "</body></html>";
exit;
}
ob_implicit_flush();
if (e_QUERY)
{
$tmp = explode('.',e_QUERY);
$mail_id = intval(varset($tmp[0],0)); // ID in 'generic' table corresponding to the recipient entries
$mail_text_id = intval(varset($tmp[1],0)); // Record number in 'generic' table corresponding to the email data
}
else
{
$mail_id = intval(varset($_POST['mail_id'],0)); // ID in 'generic' table corresponding to the recipient entries
$mail_text_id = intval(varset($_POST['mail_text_id'],0)); // ID in 'generic' table corresponding to the recipient entries
}
if (($mail_id == 0) || ($mail_text_id == 0))
{
echo "Invalid parameters: {$mail_id}, {$mail_text_id}!<br />";
exit;
}
// Get the email itself from the 'generic' table
$qry = "SELECT * FROM #generic WHERE `gen_id` = {$mail_text_id} AND gen_type='savemail' and gen_datestamp = '".$mail_id."' ";
if (!$sql -> db_Select_gen($qry))
{
echo "Email not found<br />";
exit;
}
if (!$row = $sql->db_Fetch())
{
echo "Can't read email<br />";
exit;
}
$email_info = unserialize($row['gen_chardata']); // Gives us sender_name, sender_email, email_body
//--------------------------------------------------
// Configure mailout handler (PHPMailer or other)
//--------------------------------------------------
require(e_HANDLER."phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->From = vartrue($email_info['sender_email'],$pref['siteadminemail']);
$mail->FromName = vartrue($email_info['sender_name'], $pref['siteadmin']);
// $mail->Host = "smtp1.site.com;smtp2.site.com";
if ($pref['mailer']== 'smtp')
{
$mail->Mailer = "smtp";
$mail->SMTPKeepAlive = vartrue($pref['smtp_keepalive']) ? TRUE : FALSE;
if($pref['smtp_server'])
{
$mail->Host = $pref['smtp_server'];
}
if($pref['smtp_username'] && $pref['smtp_password'])
{
$mail->SMTPAuth = TRUE;
$mail->Username = $pref['smtp_username'];
$mail->Password = $pref['smtp_password'];
$mail->PluginDir = e_HANDLER."phpmailer/";
}
}
elseif ($pref['mailer']== 'sendmail')
{
$mail->Mailer = "sendmail";
$mail->Sendmail = ($pref['sendmail']) ? $pref['sendmail'] : "/usr/sbin/sendmail -t -i -r ".$pref['siteadminemail'];
}
else
{
$mail->Mailer = "mail";
}
$message_subject = stripslashes($tp -> toHTML($email_info['email_subject'],FALSE,RAWTEXT));
$mail->WordWrap = 50;
$mail->CharSet = CHARSET;
$mail->IsHTML(TRUE);
$mail->SMTPDebug = (e_MENU == "debug") ? TRUE : FALSE;
if($email_info['copy_to'])
{
$tmp = explode(",",$email_info['copy_to']);
foreach($tmp as $addc)
{
$mail->AddCC(trim($addc));
}
}
if($email_info['bcopy_to'])
{
$tmp = explode(",",$email_info['bcopy_to']);
foreach($tmp as $addc)
{
$mail->AddBCC(trim($addc));
}
}
if($pref['mail_bounce_email'] !='')
{
$mail->Sender = $pref['mail_bounce_email'];
}
$attach = trim($email_info['attach']);
if(is_readable(e_DOWNLOAD.$attach))
{
$attach_link = e_DOWNLOAD.$attach;
}
else
{
$attach_link = e_UPLOAD.$attach;
}
if (($temp = strrchr($attach,'/')) !== FALSE)
{ // Just specify filename as attachment - no path
$attach = substr($temp,1);
}
if ($attach != "" && !$mail->AddAttachment($attach_link, $attach))
{
$mss = LAN_MAILOUT_58."<br />{$attach_link}->{$attach}"; // problem with attachment.
$ns->tablerender("Error", $mss);
exit;
}
// ---------------------------- Setup the Email ----------------------------->
$mail_head = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n";
$mail_head .= "<html xmlns='http://www.w3.org/1999/xhtml' >\n";
$mail_head .= "<head><meta http-equiv='content-type' content='text/html; charset=".CHARSET."' />\n";
if (vartrue($email_info['use_theme']))
{
$theme = $THEMES_DIRECTORY.$pref['sitetheme']."/";
$style_css = file_get_contents(e_THEME.$pref['sitetheme']."/style.css");
$mail_head .= "<style>\n".$style_css."\n</style>";
$message_body = $mail_head;
$message_body .= "</head>\n<body>\n";
$message_body .= "<div style='padding:10px;width:97%'><div class='forumheader3'>\n";
$message_body .= $tp -> toEmail($email_info['email_body'])."</div></div></body></html>";
}
else
{
$message_body = $mail_head;
$message_body .= "</head>\n<body>\n";
$message_body .= $tp -> toEmail($email_info['email_body'])."</body></html>";
$message_body = str_replace("&quot;", '"', $message_body);
$message_body = str_replace('src="', 'src="'.SITEURL, $message_body);
}
$message_body = stripslashes($message_body);
// ---------------- Display Progress and Send Emails. ----------------------->
echo "<div class='fcaption'>&nbsp;".LAN_MAILOUT_59."</div>";
// $qry = "SELECT g.*,u.* FROM #generic AS g LEFT JOIN #user AS u ON g.gen_user_id = u.user_id WHERE g.gen_type='sendmail' and g.gen_datestamp = '".intval($_POST['mail_id'])."' ";
// All the user info is in the generic table now - simplifies the query a bit
$qry = "SELECT g.* FROM #generic AS g WHERE g.gen_type='sendmail' and g.gen_datestamp = '".$mail_id."' ";
$count = $sql -> db_Select_gen($qry);
// echo date("H:i:s d.m.y")." Start of mail run by ".USERNAME." - {$count} emails to go. ID: {$mail_id}. Subject: ".$mail_subject."<br />";
if(!$count)
{
echo "<div style='text-align:center;width:200px'><br />".LAN_MAILOUT_61."</div>";
echo "</body></html>";
echo "<div style='text-align:center;margin-left:auto;margin-right:auto;position:absolute;left:10px;top:110px'>
<input type='button' class='btn btn-default button' name='close' value='Close' onclick=\"window.close()\" />
</div>";
exit;
}
$c = 0; $d=0;
$cur = 0;
$send_ok = 0; $send_fail = 0;
$pause_count = 1;
$pause_amount = ($pref['mail_pause']) ? $pref['mail_pause'] : 10;
$pause_time = ($pref['mail_pausetime']) ? $pref['mail_pausetime'] : 1;
$unit = (1/$count)* 100; // Percentage 'weight' of each email
echo "<div class='blocks' style='text-align:left;width:199px'><div id='bar' class='bar' style='border:0px;width:".$cur."%' >&nbsp;</div></div>";
echo "<div class='percents'><span id='numbers'>".($c+1)." / ".$count." (" . $cur . "</span>%) &nbsp;".LAN_MAILOUT_117."</div>";
stopwatch();
// Debug/mailout log
if ($logenable)
{
$logfilename = MAIL_LOG_PATH.'mailoutlog.txt';
$loghandle = fopen($logfilename, 'a'); // Always append to file
fwrite($loghandle,"=====----------------------------------------------------------------------------------=====\r\n");
fwrite($loghandle,date("H:i:s d.m.y")." Start of mail run by ".USERNAME." - {$count} emails to go. ID: {$mail_id}. Subject: ".$mail_subject."\r\n");
if ($add_email)
{
fwrite($loghandle, "From: ".$mail->From.' ('.$mail->FromName.")\r\n");
fwrite($loghandle, "Subject: ".$mail->Subject."\r\n");
fwrite($loghandle, "CC: ".$email_info['copy_to']."\r\n");
fwrite($loghandle, "BCC: ".$email_info['bcopy_to']."\r\n");
fwrite($loghandle, "Attach: ".$attach."\r\n");
fwrite($loghandle, "Body: ".$email_info['email_body']."\r\n");
fwrite($loghandle,"-----------------------------------------------------------\r\n");
}
}
while($row = $sql-> db_Fetch())
{
//-------------------------------
// Send one email
//-------------------------------
$mail_info = unserialize($row['gen_chardata']); // Has most of the info needed
$activator = (substr(SITEURL, -1) == "/" ? SITEURL."signup.php?activate.".$row['gen_user_id'].".".$mail_info['user_signup'] : SITEURL."/signup.php?activate.".$row['gen_user_id'].".".$mail_info['user_signup']);
$signup_link = ($mail_info['user_signup']) ? "<a href='{$activator}'>{$activator}</a>" : "";
// Allow username in subject
$mail_subject = str_replace(array('|USERNAME|','{USERNAME}'),$mail_info['user_name'],$message_subject);
$mail->Subject = $mail_subject;
// Allow username, userID, signup link in body
$search = array('|USERNAME|','|USERID|','|SIGNUP_LINK|');
$replace = array($mail_info['user_name'],$row['gen_user_id'],$signup_link);
$mes_body = str_replace($search,$replace,$message_body);
$alt_body = str_replace($search,$replace,stripslashes($tp->toText($email_info['email_body'])));
$mail->Body = $mes_body;
$mail->AltBody = $alt_body;
$mail->AddAddress($mail_info['user_email'], $mail_info['user_name']);
if ($row['gen_user_id'])
{
$mail_custom = $row['gen_user_id'];
}
else
{
$mail_custom = md5($mail_info['user_name'].$mail_info['user_email']);
}
$mail_custom = "X-e107-id: ".$mail_id.'/'.$mail_custom;
$mail->AddCustomHeader($mail_custom);
$debug_message = '';
if (($logenable == 0) || ($logenable == 2))
{ // Actually send email
$mail_result = $mail->Send();
}
else
{ // Debug mode - decide result of email here
$mail_result = TRUE;
if (($logenable == 3) && (($c % 7) == 4)) $mail_result = FALSE; // Fail one email in 7 for testing
$debug_message = 'Debug';
}
if ($mail_result)
{
$send_ok++;
$sql2->db_Delete('generic',"gen_id={$row['gen_id']}"); // Mail sent - delete from database
}
else
{
$send_fail++;
$mail_info['send_result'] = 'Fail: '.$mail->ErrorInfo.$debug_message;
$temp = serialize($mail_info);
// Log any error info we can
$sql2->db_Update('generic',"`gen_chardata`='{$temp}' WHERE gen_id={$row['gen_id']}");
}
if ($logenable)
{
fwrite($loghandle,date("H:i:s d.m.y")." Send to {$mail_info['user_name']} at {$mail_info['user_email']} Mail-ID={$mail_custom} - {$mail_result}\r\n");
}
$mail->ClearAddresses();
$mail->ClearCustomHeaders();
// --------- One email sent
$cur = round((($c / $count) * 100) + $unit);
// Do we need next line?
// echo str_pad(' ',4096)."<br />\n"; // Put out lots of spaces and a newline - works wonders for XHTML compliance!
// $d = ($c==0) ? 10 : round($width + $d); // Line doesn't do anything
// echo "<div class='percents'>".($c+1)." / ".$count." (" . $cur . "%) &nbsp;".LAN_MAILOUT_117."</div>";
echo "<script type='text/javascript'>setnum('".($c+1)."','{$count}','{$cur}');</script>\n";
/* if($cur != $prev)
{ // Update 'completed' segment of progress bar
echo "<script type='text/javascript'>inc('".$cur."%');</script>\n";
}
$prev = $cur;
*/ ob_flush();
flush();
if($pause_count > $pause_amount)
{
sleep($pause_time);
$pause_count = 1;
}
// Default sleep to reduce server-load: 1 second.
sleep(1);
$c++;
$pause_count++;
}
ob_end_flush();
echo "<div style='position:absolute;left:10px;top:50px'><br />";
echo LAN_MAILOUT_62." ".$send_ok."<br />";
echo LAN_MAILOUT_63." ".$send_fail."<br />";
echo LAN_MAILOUT_64." ".stopwatch()." ".LAN_MAILOUT_65."<br />";
echo "</div>";
// Complete - need to log something against the mailshot entry, and maybe write an admin log entry.
$log_string = date("H:i:s d.m.y")." End of ".($logenable == 1 ? 'debug ' : '')."mail run by ".USERNAME." - {$send_ok} succeeded, {$send_fail} failed. Subject: ".$mail_subject;
if (!is_array($email_info['send_results'])) $email_info['send_results'] = array();
$email_info['send_results'][] = $log_string;
$sql->db_Update('generic',"`gen_chardata`='".serialize($email_info)."' WHERE `gen_id` = {$mail_text_id} AND `gen_type`='savemail' and `gen_datestamp` = '".$mail_id."' ");
$mail->ClearAttachments();
if ($pref['mailer']== 'smtp')
{
$mail->SmtpClose();
}
echo "<div style='text-align:center;margin-left:auto;margin-right:auto;position:absolute;left:10px;top:110px'>
<br /><input type='button' class='btn btn-default button' name='close' value='Close' onclick=\"window.close()\" />
</div>";
echo "</body></html>";
if ($logenable)
{
fwrite($loghandle,$log_string."\r\n");
fclose($loghandle);
}
function headerjs(){
$text = "
<style type='text/css'><!--
div.percents div.blocks img.blocks{
margin: 1px;
height: 20px;
padding: 1px;
border: 1px solid #000;
width: 199px;
background: #fff;
color: #000;
float: left;
clear: right;
z-index: 9;
position:relative;
}
.percents {
background: #FFF;
border: 1px solid #CCC;
margin: 1px;
height: 20px;
position:absolute;
vertical-align:middle;
width:199px;
z-index:10;
left: 10px;
top: 38px;
text-align: center;
color:black;
}
.blocks {
margin-top: 1px;
height: 21px;
position: absolute;
z-index:11;
left: 12px;
top: 38px;
}
.bar {
background: #EEE;
background-color:red;
filter: alpha(opacity=50);
height:21px;
-moz-opacity: 0.5;
opacity: 0.5;
-khtml-opacity: .5
}
-->
</style>";
$text .= "
<script type='text/javascript'>
function inc(amount)
{
document.getElementById('bar').style.width= amount;
}
function setnum(v1,v2,v3)
{
this_el = document.getElementById('numbers');
if (this_el) this_el.innerHTML = v1+' / '+v2+' ('+v3;
document.getElementById('bar').style.width= v3+'%';
}
</script>";
return $text;
}
function stopwatch(){
static $mt_previous = 0;
list($usec, $sec) = explode(" ",microtime());
$mt_current = (float)$usec + (float)$sec;
if (!$mt_previous) {
$mt_previous = $mt_current;
return "";
} else {
$mt_diff = ($mt_current - $mt_previous);
$mt_previous = $mt_current;
return round(sprintf('%.16f',$mt_diff),2);
}
}
?>

View File

@ -274,7 +274,7 @@ define("LAN_MAILOUT_255", "Templated Email, ID: ");
define("LAN_MAILOUT_256", "Return"); define("LAN_MAILOUT_256", "Return");
define("LAN_MAILOUT_257", "Generated template"); define("LAN_MAILOUT_257", "Generated template");
//define("LAN_MAILOUT_258", "Template: ");//LAN_TEMPLATE //define("LAN_MAILOUT_258", "Template: ");//LAN_TEMPLATE
define("LAN_MAILOUT_259", ""); define("LAN_MAILOUT_260", "SMTP Port");
define("LAN_SEND", "Send"); define("LAN_SEND", "Send");