From ca83bbf73eecce5f7bb2f5923c5930576f7ed72f Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 14 Apr 2016 14:48:02 -0700 Subject: [PATCH] Standard mailer and bulk mailer can now be different. eg. Use PHP for standard mails, but use Amazon.com SES service for bulk mailing, mailing lists etc. --- e107_admin/mailout.php | 91 +++++++++++--------- e107_core/xml/default_install.xml | 1 + e107_handlers/e107_class.php | 14 ++- e107_handlers/mail.php | 2 + e107_handlers/mail_manager_class.php | 25 ++++-- e107_handlers/mailout_admin_class.php | 8 +- e107_languages/English/admin/lan_mailout.php | 2 +- 7 files changed, 83 insertions(+), 60 deletions(-) diff --git a/e107_admin/mailout.php b/e107_admin/mailout.php index a03d93d94..2ca701cd5 100644 --- a/e107_admin/mailout.php +++ b/e107_admin/mailout.php @@ -564,52 +564,57 @@ class mailout_main_ui extends e_admin_ui if(trim($_POST['testaddress']) == '') { $mes->addError(LAN_MAILOUT_19); - $subAction = 'error'; + return null; + } + + if(empty($pref['bulkmailer'])) + { + $pref['bulkmailer'] = $pref['mailer']; + } + + $add = ($pref['bulkmailer']) ? " (".strtoupper($pref['bulkmailer']).") " : ' (PHP)'; + + if($pref['bulkmailer'] == 'smtp') + { + $add .= "Port: ".varset($pref['smtp_port'],25); + $add .= " - ".str_replace("secure=", "", $pref['smtp_options']); + } + + $sendto = trim($_POST['testaddress']); + + $subjectSitename = ($_POST['testtemplate'] == 'textonly') ? SITENAME : ''; + + $eml = array( + 'e107_header' => USERID, + 'subject' => LAN_MAILOUT_113." ".$subjectSitename.$add, + 'body' => str_replace("[br]", "\n", LAN_MAILOUT_114), + 'template' => vartrue($_POST['testtemplate'],null), + 'shortcodes' => $this->getExampleShortcodes(), + 'media' => array( + 0 => array('path' => '{e_PLUGIN}gallery/images/butterfly.jpg'), + 1 => array('path' => 'h-v880sXEOQ.youtube'), + ) + ); + + if(E107_DEBUG_LEVEL > 0) + { + $eml['SMTPDebug'] = true; + } + + + $options = array('mailer'=>$pref['bulkmailer']); + + + if (!e107::getEmail($options)->sendEmail($sendto, LAN_MAILOUT_189, $eml)) + { + $mes->addError(($pref['bulkmailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106); } else { + $mes->addSuccess(LAN_MAILOUT_81. ' ('.$sendto.')'); + e107::getAdminLog()->log_event('MAIL_01', $sendto, E_LOG_INFORMATIVE,''); + } - $add = ($pref['mailer']) ? " (".strtoupper($pref['mailer']).") " : ' (PHP)'; - - if($pref['mailer'] == 'smtp') - { - $add .= "Port: ".varset($pref['smtp_port'],25); - $add .= " - ".str_replace("secure=", "", $pref['smtp_options']); - } - - $sendto = trim($_POST['testaddress']); - - $subjectSitename = ($_POST['testtemplate'] == 'textonly') ? SITENAME : ''; - - $eml = array( - 'e107_header' => USERID, - 'subject' => LAN_MAILOUT_113." ".$subjectSitename.$add, - 'body' => str_replace("[br]", "\n", LAN_MAILOUT_114), - 'template' => vartrue($_POST['testtemplate'],null), - 'shortcodes' => $this->getExampleShortcodes(), - 'media' => array( - 0 => array('path' => '{e_PLUGIN}gallery/images/butterfly.jpg'), - 1 => array('path' => 'h-v880sXEOQ.youtube'), - - ) - - ); - - if(E107_DEBUG_LEVEL > 0) - { - $eml['SMTPDebug'] = true; - } - - if (!e107::getEmail()->sendEmail($sendto, LAN_MAILOUT_189, $eml)) - { - $mes->addError(($pref['mailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106); - } - else - { - $mes->addSuccess(LAN_MAILOUT_81. ' ('.$sendto.')'); - e107::getAdminLog()->log_event('MAIL_01', $sendto, E_LOG_INFORMATIVE,''); - } - } } @@ -1087,7 +1092,7 @@ class mailout_main_ui extends e_admin_ui "; - $text .= mailoutAdminClass::mailerPrefsTable($pref); + $text .= mailoutAdminClass::mailerPrefsTable($pref, 'bulkmailer'); /* FIXME - posting SENDMAIL path triggers Mod-Security rules. diff --git a/e107_core/xml/default_install.xml b/e107_core/xml/default_install.xml index 90a6989ff..6582adfc8 100644 --- a/e107_core/xml/default_install.xml +++ b/e107_core/xml/default_install.xml @@ -168,6 +168,7 @@ texthtml 5 php + smtp 0 0 diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 0695eba02..2e6ea2763 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -775,11 +775,17 @@ class e107 * @param string $regpath additional registry path * @return Object */ - public static function getSingleton($class_name, $path = true, $regpath = '') + public static function getSingleton($class_name, $path = true, $regpath = '',$vars=null) { $id = 'core/e107/singleton/'.$class_name.$regpath; + if(!empty($vars)) + { + $id .= '/'; + $id .= is_array($vars) ? crc32(serialize($vars)): crc32($vars); + } + //singleton object found - overload not possible if(self::getRegistry($id)) { @@ -821,7 +827,7 @@ class e107 } if(class_exists($class_name, false)) { - e107::setRegistry($id, new $class_name()); + e107::setRegistry($id, new $class_name($vars)); } return self::getRegistry($id); @@ -1225,9 +1231,9 @@ class e107 * * @return e107Email */ - public static function getEmail() + public static function getEmail($overrides=null) { - return self::getSingleton('e107Email', true); + return self::getSingleton('e107Email', true, null, $overrides); } diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 6a4762fb0..b6e60f79b 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -196,6 +196,8 @@ class e107Email extends PHPMailer $e107 = e107::getInstance(); $pref = e107::pref('core'); $tp = e107::getParser(); + + print_a($overrides); if(defined('MAIL_DEBUG')) { diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php index d1358b6bb..804449d51 100644 --- a/e107_handlers/mail_manager_class.php +++ b/e107_handlers/mail_manager_class.php @@ -216,9 +216,19 @@ class e107MailManager * * @return void */ - public function __construct($overrides = FALSE) + public function __construct($overrides = false) { $this->e107 = e107::getInstance(); + + $pref = e107::pref('core'); + + $bulkmailer = (!empty($pref['bulkmailer'])) ? $pref['bulkmailer'] : $pref['mailer']; + + if($overrides === false) + { + $overrides = array('mailer'=>$bulkmailer); + } + $this->mailOverrides = $overrides; if(deftrue('e_DEBUG')) @@ -247,7 +257,7 @@ class e107MailManager * * @return void */ - public function mailToDb(&$data, $addMissing = FALSE) + public function mailToDb(&$data, $addMissing = false) { $res = array(); $res1 = array(); @@ -745,10 +755,9 @@ class e107MailManager } - // else - { - $result = $this->mailer->sendEmail($email['mail_recipient_email'], $email['mail_recipient_name'], $mailToSend, TRUE); - } + + $result = $this->mailer->sendEmail($email['mail_recipient_email'], $email['mail_recipient_name'], $mailToSend, TRUE); + if($this->debugMode) { @@ -1310,7 +1319,7 @@ class e107MailManager if (!$this->db->update('mail_content',$query)) { - $this->e107->admin_log->e_log_event(10,-1,'MAIL','Activate/hold mail','mail_content: '.$query.'[!br!]Fail: '.$this->db->mySQLlastErrText,FALSE,LOG_TO_ROLLING); + e107::getLog()->e_log_event(10,-1,'MAIL','Activate/hold mail','mail_content: '.$query.'[!br!]Fail: '.$this->db->mySQLlastErrText,FALSE,LOG_TO_ROLLING); return FALSE; } @@ -1319,7 +1328,7 @@ class e107MailManager // echo "Update individual emails: {$query}
"; if (FALSE === $this->db->update('mail_recipients',$query)) { - $this->e107->admin_log->e_log_event(10,-1,'MAIL','Activate/hold mail','mail_recipient: '.$query.'[!br!]Fail: '.$this->db->mySQLlastErrText,FALSE,LOG_TO_ROLLING); + e107::getLog()->e_log_event(10,-1,'MAIL','Activate/hold mail','mail_recipient: '.$query.'[!br!]Fail: '.$this->db->mySQLlastErrText,FALSE,LOG_TO_ROLLING); return FALSE; } return TRUE; diff --git a/e107_handlers/mailout_admin_class.php b/e107_handlers/mailout_admin_class.php index f6d06480c..b7e339112 100644 --- a/e107_handlers/mailout_admin_class.php +++ b/e107_handlers/mailout_admin_class.php @@ -2102,7 +2102,7 @@ class mailoutAdminClass extends e107MailManager - public static function mailerPrefsTable($pref) + public static function mailerPrefsTable($pref, $id='mailer') { $frm = e107::getForm(); @@ -2110,9 +2110,9 @@ class mailoutAdminClass extends e107MailManager $mailers = array('php'=>'php','smtp'=>'smtp','sendmail'=>'sendmail'); $smtp_opts = explode(',',varset($pref['smtp_options'],'')); - $smtpdisp = ($pref['mailer'] != 'smtp') ? "style='display:none;'" : ''; + $smtpdisp = ($pref[$id] != 'smtp') ? "style='display:none;'" : ''; - $text = $frm->select('mailer', $mailers, $pref['mailer'])." + $text = $frm->select($id, $mailers, $pref[$id])." ".LAN_MAILOUT_116.""; $text .= "
@@ -2193,7 +2193,7 @@ class mailoutAdminClass extends e107MailManager e107::js('footer-inline', " - $('#mailer').on('change', function() { + $('#".$id."').on('change', function() { var type = $(this).val(); diff --git a/e107_languages/English/admin/lan_mailout.php b/e107_languages/English/admin/lan_mailout.php index d55984c16..798e0f0b2 100644 --- a/e107_languages/English/admin/lan_mailout.php +++ b/e107_languages/English/admin/lan_mailout.php @@ -125,7 +125,7 @@ define("LAN_MAILOUT_111", "Email Title (not sent)"); define("LAN_MAILOUT_112", "Send test email to"); define("LAN_MAILOUT_113", "Test email from"); define("LAN_MAILOUT_114", "This is a test email, it appears that your email settings are working ok! [br][br] Regards [br] from the e107 website system."); -define("LAN_MAILOUT_115", "Emailing method"); +define("LAN_MAILOUT_115", "Bulk Emailing method"); define("LAN_MAILOUT_116", "If unsure, leave as php"); define("LAN_MAILOUT_117", "complete"); define("LAN_MAILOUT_118", "Click on proceed' to start sending emails. Click on 'cancel' to stop the run. Once complete, select another page. Unsent emails cal be viewed through the 'Mailshot status' screen");