From 2f9dae5eedb79f6d7da2435f07353c875c5d54fe Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 26 Aug 2014 15:49:24 -0700 Subject: [PATCH] Email admin->notify template working with new template standard. --- e107_core/templates/email_template.php | 38 ++++++-------------------- e107_handlers/mail.php | 15 ++++++++-- e107_handlers/mail_manager_class.php | 34 ++++++++++++++++++++++- e107_handlers/notify_class.php | 20 ++++++++------ 4 files changed, 65 insertions(+), 42 deletions(-) diff --git a/e107_core/templates/email_template.php b/e107_core/templates/email_template.php index 54f853a38..aecc3d9a9 100644 --- a/e107_core/templates/email_template.php +++ b/e107_core/templates/email_template.php @@ -228,26 +228,7 @@ LAN_SIGNUP_97." {SITENAME}
//------------------------------------------------------------- // 'NOTIFY' TEMPLATE //------------------------------------------------------------- -$NOTIFY_TEMPLATE = array( - 'template_name' => 'Notify', - 'template_type' => 'system', - 'email_overrides' => '', - 'email_header' => " - - - - - -
- ", - 'email_body' => '{BODY}', - 'email_footer' => "

- {SITENAME=link} -
- - ", - 'email_plainText' => '' - ); + //------------------------------------------------------------- @@ -308,14 +289,6 @@ $MONTHLYUPDATE_TEMPLATE = array( -$QUICKADDUSER_TEMPLATE = array( - 'template_name' => 'Quick-Add-User', - 'template_type' => 'quickadd', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => USRLAN_185.USRLAN_186, -// 'email_footer' => 'footer' - ); @@ -421,16 +394,23 @@ $EMAIL_TEMPLATE['quickadduser']['header'] = $EMAIL_TEMPLATE['default']['header' $EMAIL_TEMPLATE['quickadduser']['body'] = USRLAN_185.USRLAN_186; $EMAIL_TEMPLATE['quickadduser']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default footer above. + + // --------------------------------- -// Notify (@see admin-> notify) // TODO +// Notify (@see admin-> notify) $EMAIL_TEMPLATE['notify']['subject'] = '{SITENAME}: {SUBJECT} '; $EMAIL_TEMPLATE['notify']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. $EMAIL_TEMPLATE['notify']['body'] = $EMAIL_TEMPLATE['default']['body']; // will use default header above. $EMAIL_TEMPLATE['notify']['footer'] = $EMAIL_TEMPLATE['default']['footer']; // will use default header above. + +// --------------------------------- + + + // A Dummy Example for theme developers. $EMAIL_TEMPLATE['example']['subject'] = '{SITENAME}: {SUBJECT} '; $EMAIL_TEMPLATE['example']['header'] = $EMAIL_TEMPLATE['default']['header']; // will use default header above. diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 5eb2b21bb..1be3ac1dc 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -606,7 +606,7 @@ class e107Email extends PHPMailer { - if($tmpl = e107::getCoreTemplate('email', $eml['template'], true, true)) // $EMAIL_TEMPLATE['default'] + if($tmpl = e107::getCoreTemplate('email', $eml['template'], true, true)) //FIXME - Core template is failing with template 'notify'. Works with theme template. Issue with core template registry? { // $filter = array("\n", "\t"); // $tmpl['header'] = str_replace($filter,'', $tmpl['header']); @@ -623,6 +623,7 @@ class e107Email extends PHPMailer if($this->debug) { + echo "

e107Email::arraySet() - line ".__LINE__."

"; print_a($tmpl); } @@ -630,6 +631,15 @@ class e107Email extends PHPMailer $this->Subject = $tp->parseTemplate($tmpl['subject'], true, varset($eml['shortcodes'],null)); } + else + { + if($this->debug) + { + echo "

Couldn't find email template: ".$eml['template']."

"; + } + if (vartrue($eml['email_subject'])) $this->Subject = $tp->parseTemplate($eml['email_subject'], true, varset($eml['shortcodes'],null)); + e107::getMessage()->addDebug("Couldn't find email template: ".$eml['template']); + } } else @@ -658,12 +668,11 @@ class e107Email extends PHPMailer if($this->debug) { + echo "

e107Email::arraySet() - line ".__LINE__."

"; print_a($eml); } - - 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']; diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php index 843762c33..55ba7b277 100644 --- a/e107_handlers/mail_manager_class.php +++ b/e107_handlers/mail_manager_class.php @@ -799,6 +799,8 @@ class e107MailManager //'extra_header' - additional headers (format is name: value //'wordwrap' - Set wordwrap value //'split' - If true, sends an individual email to each recipient + 'template' => 'template', // required + 'shortcodes' => 'shortcodes' // required ); $result = array(); if (!isset($email['mail_source_id'])) $email['mail_source_id'] = 0; @@ -828,6 +830,8 @@ class e107MailManager $result['send_html'] = ($email['mail_send_style'] != 'textonly'); $result['add_html_header'] = FALSE; // We look after our own headers + + // Set up any extra mailer parameters that need it if (!vartrue($email['e107_header'])) { @@ -1497,7 +1501,7 @@ class e107MailManager // Get template data, override email settings as appropriate require_once(e_HANDLER.'mail_template_class.php'); $ourTemplate = new e107MailTemplate(); - if (!$ourTemplate->setNewTemplate($templateName)) return FALSE; // Probably template not found if error + if (!$ourTemplate->setNewTemplate($templateName) && empty($emailData['template'])) return FALSE; // Probably template not found if error if (!$ourTemplate->makeEmailBody($emailData['mail_body'], varset($emailData['mail_include_images'], TRUE))) return FALSE; // Create body text $emailData['mail_body_templated'] = $ourTemplate->mainBodyText; $this->currentMailBody = $emailData['mail_body_templated']; // In case we send immediately @@ -1507,6 +1511,17 @@ class e107MailManager { $emailData['mail_overrides'] = $ourTemplate->lastTemplateData['email_overrides']; } + + if(!empty($emailData['template'])) // Quick Fix for new email template standards. + { + $this->currentMailBody = $emailData['mail_body']; + unset($emailData['mail_body_templated']); + + if($this->debugMode) + { + echo "

".$emailData['template']." Template detected

"; + } + } $forceQueue = FALSE; @@ -1516,6 +1531,13 @@ class e107MailManager unset($extra['mail_force_queue']); } + if($this->debugMode) + { + print_a($emailData); + print_a($recipientData); + + } + if ((count($recipientData) <= 5) && !$forceQueue) // Arbitrary upper limit for sending multiple emails immediately { if ($this->mailer == NULL) @@ -1537,9 +1559,19 @@ class e107MailManager if (FALSE == $this->mailer->sendEmail($recip['mail_recipient_email'], $recip['mail_recipient_name'], $mailToSend, TRUE)) { $tempResult = FALSE; + if($this->debugMode) + { + echo "

Failed to send to: ".$recip['mail_recipient_email']." [". $recip['mail_recipient_name'] ."]

"; + print_a($mailToSend); + } } else { // Success here + if($this->debugMode) + { + echo "

Mail Sent successfully to: ".$recip['mail_recipient_email']." [". $recip['mail_recipient_name'] ."]

"; + print_a($mailToSend); + } if ($eCount == 0) { // Only send these on first email - otherwise someone could get inundated! unset($emailData['mail_copy_to']); diff --git a/e107_handlers/notify_class.php b/e107_handlers/notify_class.php index 1fbe517d6..7a43dd106 100644 --- a/e107_handlers/notify_class.php +++ b/e107_handlers/notify_class.php @@ -147,16 +147,18 @@ class notify // Create the mail body $mailData = array( - 'mail_content_status' => MAIL_STATUS_TEMP, - 'mail_create_app' => 'notify', - 'mail_title' => 'NOTIFY', - 'mail_subject' => $subject, - 'mail_sender_email' => e107::getPref('siteadminemail'), - 'mail_sender_name' => e107::getPref('siteadmin'), - 'mail_send_style' => 'textonly', - 'mail_notify_complete' => 0, // NEVER notify when this email sent!!!!! - 'mail_body' => $message + 'mail_content_status' => MAIL_STATUS_TEMP, + 'mail_create_app' => 'notify', + 'mail_title' => 'NOTIFY', + 'mail_subject' => $subject, + 'mail_sender_email' => e107::getPref('siteadminemail'), + 'mail_sender_name' => e107::getPref('siteadmin'), + // 'mail_send_style' => 'textonly', + 'mail_notify_complete' => 0, // NEVER notify when this email sent!!!!! + 'mail_body' => $message, + 'template' => 'notify' ); + $result = $mailer->sendEmails('NOTIFY_TEMPLATE', $mailData, $recipients); $e107->admin_log->e_log_event(10,-1,'NOTIFY',$subject,$message,FALSE,LOG_TO_ROLLING); }