From e44d83ca65979a1b18886d65242c85c724243feb Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 15 Aug 2014 21:18:15 -0700 Subject: [PATCH] First commit of standardized email template. --- e107_admin/prefs.php | 24 ++++++- e107_core/templates/email_template.php | 39 +++++++++++- e107_handlers/mail.php | 86 +++++++++++++++++--------- 3 files changed, 117 insertions(+), 32 deletions(-) diff --git a/e107_admin/prefs.php b/e107_admin/prefs.php index 4104486ae..f6cc076de 100644 --- a/e107_admin/prefs.php +++ b/e107_admin/prefs.php @@ -217,13 +217,33 @@ function sendTest() else { $mailheader_e107id = USERID; - require_once(e_HANDLER.'mail.php'); + // require_once(e_HANDLER.'mail.php'); $add = ($pref['mailer']) ? " (".strtoupper($pref['mailer']).")" : ' (PHP)'; $sendto = trim($_POST['testaddress']); - if (!sendemail($sendto, LAN_MAILOUT_113." ".SITENAME.$add, str_replace("[br]", "\n", LAN_MAILOUT_114),LAN_MAILOUT_189)) + + + $eml = array(); + + $eml['email_subject'] = LAN_MAILOUT_113." ".SITENAME.$add; + $eml['email_sender_email'] = null; + $eml['email_sender_name'] = null; + $eml['email_replyto'] = null; + $eml['email_replytonames'] = null; + $eml['send_html'] = true; + $eml['add_html_header'] = null; + $eml['email_body'] = str_replace("[br]", "
", LAN_MAILOUT_114); + $eml['email_attach'] = null; + $eml['template'] = 'default'; + $eml['e107_header'] = USERID; + + if (!e107::getEmail()->sendEmail($sendto, LAN_MAILOUT_189, $eml)) { $mes->addError(($pref['mailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106); } + // if (!sendemail($sendto, LAN_MAILOUT_113." ".SITENAME.$add, str_replace("[br]", "\n", LAN_MAILOUT_114),LAN_MAILOUT_189)) + // { + // $mes->addError(($pref['mailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106); + // } else { $mes->addSuccess(LAN_MAILOUT_81. ' ('.$sendto.')'); diff --git a/e107_core/templates/email_template.php b/e107_core/templates/email_template.php index 6be78599d..f01555658 100644 --- a/e107_core/templates/email_template.php +++ b/e107_core/templates/email_template.php @@ -334,7 +334,44 @@ $QUICKADDUSER_TEMPLATE = array( 'email_body' => USRLAN_185.USRLAN_186, // 'email_footer' => 'footer' ); - + + + + + +/** Standardized v2 template rewrite + * Format for individual emails sent by e107 (not bulk emails for now) - a work in progress - bulk could be ported later. + * @see e107Email::sendEmail(); + * Aim: to make email templates follow the same spec. as other templates while remaining as intuitive as other v2 templates in e107. + */ + + +// Default - test email and when no template specified. + +$EMAIL_TEMPLATE['default']['name'] = 'Default'; +$EMAIL_TEMPLATE['default']['overrides'] = ''; +$EMAIL_TEMPLATE['default']['header'] = " + + + + + + + +
+ "; + +$EMAIL_TEMPLATE['default']['body'] = "{BODY}"; + +$EMAIL_TEMPLATE['default']['footer'] = "

+ {SITENAME=link} +
+ + "; + ?> \ No newline at end of file diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 7c1b7648a..779ec4593 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -155,6 +155,7 @@ class e107Email extends PHPMailer public $legacyBody = FALSE; // TRUE enables legacy conversion of plain text body to HTML in HTML emails + /** * Constructor sets up all the global options, and sensible defaults - it should be the only place the prefs are accessed * @@ -184,6 +185,7 @@ class e107Email extends PHPMailer } $this->pause_amount = varset($pref['mail_pause'], 10); $this->pause_time = varset($pref['mail_pausetime'], 1); + $this->allow_html = varset($pref['mail_sendstyle'],'textonly') == 'texthtml' ? true : 1; if (varsettrue($pref['mail_options'])) $this->general_opts = explode(',',$pref['mail_options'],''); if (defined('MAIL_DEBUG')) echo 'Mail_options: '.$pref['mail_options'].' Count: '.count($this->general_opts).'
'; @@ -482,7 +484,7 @@ class e107Email extends PHPMailer $want_HTML = FALSE; break; } - + if ($want_HTML !== FALSE) { if (defined('MAIL_DEBUG')) echo "Generating multipart email
"; @@ -577,49 +579,74 @@ class e107Email extends PHPMailer * Where parameter not present, doesn't change it - so can repeatedly call this function for bulk mailing, or to build up the list * (Note that there is no requirement to use this method for everything; parameters can be set by mixing this method with individual setting) * - * @param array $paramlist - list of parameters to set/change. Key is parameter name. @see{sendEmail()} for list of parameters + * @param array $eml - list of parameters to set/change. Key is parameter name. @see{sendEmail()} for list of parameters * * @return int zero if no errors detected */ - public function arraySet($paramlist) + public function arraySet($eml) { - if (isset($paramlist['SMTPDebug'])) $this->SMTPDebug = $paramlist['SMTPDebug']; // 'FALSE' is a valid value! - if (varsettrue($paramlist['email_subject'])) $this->Subject = $paramlist['email_subject']; - if (varsettrue($paramlist['email_sender_email'])) $this->From = $paramlist['email_sender_email']; - if (varsettrue($paramlist['email_sender_name'])) $this->FromName = $paramlist['email_sender_name']; - if (varsettrue($paramlist['email_replyto'])) $this->AddAddressList('replyto',$paramlist['email_replyto'],varsettrue($paramlist['email_replytonames'],'')); - if (isset($paramlist['send_html'])) $this->allow_html = $paramlist['send_html']; // 'FALSE' is a valid value! - if (isset($paramlist['add_html_header'])) $this->add_HTML_header = $paramlist['add_html_header']; // 'FALSE' is a valid value! - if (varsettrue($paramlist['email_body'])) $this->makeBody($paramlist['email_body'], $this->allow_html, $this->add_HTML_header); - if (varsettrue($paramlist['email_attach'])) $this->attach($paramlist['email_attach']); - if (varsettrue($paramlist['email_copy_to'])) $this->AddAddressList('cc',$paramlist['email_copy_to'],varsettrue($paramlist['email_cc_names'],'')); - if (varsettrue($paramlist['email_bcopy_to'])) $this->AddAddressList('bcc',$paramlist['email_bcopy_to'],varsettrue($paramlist['email_bcc_names'],'')); - if (varsettrue($paramlist['bouncepath'])) + + if(vartrue($eml['template'])) // @see e107_core/templates/email_template.php { - $this->Sender = $paramlist['bouncepath']; // Bounce path - $this->save_bouncepath = $paramlist['bouncepath']; // Bounce path - } - if (varsettrue($paramlist['returnreceipt'])) $this->ConfirmReadingTo = $paramlist['returnreceipt']; - if (varsettrue($paramlist['email_inline_images'])) $this->addInlineImages($paramlist['email_inline_images']); - if (varsettrue($paramlist['email_priority'])) $this->Priority = $paramlist['email_priority']; - if (varsettrue($paramlist['e107_header'])) $this->AddCustomHeader("X-e107-id: {$paramlist['e107_header']}"); - if (varsettrue($paramlist['extra_header'])) - { - if (is_array($paramlist['extra_header'])) + $tp = e107::getParser(); + + if($tmpl = e107::getCoreTemplate('email','default', true, true)) // $EMAIL_TEMPLATE['default'] { - foreach($paramlist['extra_header'] as $eh) + $filter = array("\n", "\t"); + $tmpl['header'] = str_replace($filter,'', $tmpl['header']); + $tmpl['footer'] = str_replace($filter,'', $tmpl['footer']); + + $eml['email_body'] = ($tp->toEmail($tmpl['header']). str_replace('{BODY}', $eml['email_body'], $tmpl['body']). $tp->toEmail($tmpl['footer'])); + unset($eml['add_html_header']); // disable other headers when template is used. + } + + } + + + if (isset($eml['SMTPDebug'])) $this->SMTPDebug = $eml['SMTPDebug']; // 'FALSE' is a valid value! + if (vartrue($eml['email_subject'])) $this->Subject = $eml['email_subject']; + if (vartrue($eml['email_sender_email'])) $this->From = $eml['email_sender_email']; + if (vartrue($eml['email_sender_name'])) $this->FromName = $eml['email_sender_name']; + if (vartrue($eml['email_replyto'])) $this->AddAddressList('replyto',$eml['email_replyto'],vartrue($eml['email_replytonames'],'')); + if (isset($eml['send_html'])) $this->allow_html = $eml['send_html']; // 'FALSE' is a valid value! + if (isset($eml['add_html_header'])) $this->add_HTML_header = $eml['add_html_header']; // 'FALSE' is a valid value! + if (vartrue($eml['email_body'])) $this->makeBody($eml['email_body'], $this->allow_html, $this->add_HTML_header); + if (vartrue($eml['email_attach'])) $this->attach($eml['email_attach']); + if (vartrue($eml['email_copy_to'])) $this->AddAddressList('cc',$eml['email_copy_to'],vartrue($eml['email_cc_names'],'')); + if (vartrue($eml['email_bcopy_to'])) $this->AddAddressList('bcc',$eml['email_bcopy_to'],vartrue($eml['email_bcc_names'],'')); + + if (vartrue($eml['bouncepath'])) + { + $this->Sender = $eml['bouncepath']; // Bounce path + $this->save_bouncepath = $eml['bouncepath']; // Bounce path + } + + + + + + + if (vartrue($eml['returnreceipt'])) $this->ConfirmReadingTo = $eml['returnreceipt']; + if (vartrue($eml['email_inline_images'])) $this->addInlineImages($eml['email_inline_images']); + if (vartrue($eml['email_priority'])) $this->Priority = $eml['email_priority']; + if (vartrue($eml['e107_header'])) $this->AddCustomHeader("X-e107-id: {$eml['e107_header']}"); + if (vartrue($eml['extra_header'])) + { + if (is_array($eml['extra_header'])) + { + foreach($eml['extra_header'] as $eh) { $this->addCustomHeader($eh); } } else { - $this->addCustomHeader($paramlist['extra_header']); + $this->addCustomHeader($eml['extra_header']); } } - if (varset($paramlist['wordwrap'])) $this->WordWrap = $paramlist['wordwrap']; - if (varsettrue($paramlist['split'])) $this->SingleTo = ($paramlist['split'] != FALSE); + if (varset($eml['wordwrap'])) $this->WordWrap = $eml['wordwrap']; + if (vartrue($eml['split'])) $this->SingleTo = ($eml['split'] != FALSE); return 0; // No error } @@ -654,6 +681,7 @@ class e107Email extends PHPMailer $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' * @param string $send_to - recipient email address * @param string $to_name - recipient name