diff --git a/e107_admin/mailout.php b/e107_admin/mailout.php index a60e13766..bb34280b7 100644 --- a/e107_admin/mailout.php +++ b/e107_admin/mailout.php @@ -101,21 +101,29 @@ function sendProgress($id) $mailManager = new e107MailManager(); $mailManager->doEmailTask(varset($pref['mail_workpertick'],5)); - $sqld = e107::getDb(); + $sqld = e107::getDb('progress'); - $sqld->select("mail_content","mail_togo_count,mail_sent_count,mail_fail_count","mail_source_id= ".intval($id) ); + $sqld->select("mail_content","mail_total_count,mail_togo_count,mail_sent_count,mail_fail_count","mail_source_id= ".intval($id) ); $row = $sqld->fetch(); $rand = ($row['mail_sent_count'] + $row['mail_fail_count']); - $total = ($row['mail_togo_count'] + $row['mail_sent_count'] + $row['mail_fail_count']); + $total = ($row['mail_total_count']); $errors = ob_get_clean(); + $errors .= " id=".$id; + + e107::getMessage()->addDebug($errors); -// file_put_contents(e_LOG.'send-mail-progress.txt',$errors); + $inc = round(($rand / $total) * 100); + + $errors .= " inc=".$inc; + + file_put_contents(e_LOG.'send-mail-progress.txt',$errors); + e107::getMessage()->addDebug("Returned: ".$inc); return $inc; @@ -394,33 +402,13 @@ class mailout_main_ui extends e_admin_ui $this->processSendActions(); - + $mes = e107::getMessage(); if (getperms('0')) { if (isset($_POST['testemail'])) - { // Send test email - uses standard 'single email' handler - if(trim($_POST['testaddress']) == '') - { - $mes->addError(LAN_MAILOUT_19); - $subAction = 'error'; - } - else - { - $mailheader_e107id = USERID; - 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)) - { - $mes->addError(($pref['mailer'] == 'smtp') ? LAN_MAILOUT_67 : LAN_MAILOUT_106); - } - else - { - $mes->addSuccess(LAN_MAILOUT_81. ' ('.$sendto.')'); - $admin_log->log_event('MAIL_01',$sendto,E_LOG_INFORMATIVE,''); - } - } + { + $this->sendTestEmail(); // Send test email - uses standard 'single email' handler } elseif (isset($_POST['updateprefs'])) { @@ -430,6 +418,43 @@ class mailout_main_ui extends e_admin_ui + } + + private function sendTestEmail() + { + $mes = e107::getMessage(); + $pref = e107::getPref(); + + if(trim($_POST['testaddress']) == '') + { + $mes->addError(LAN_MAILOUT_19); + $subAction = 'error'; + } + else + { + $mailheader_e107id = USERID; + + $add = ($pref['mailer']) ? " (".strtoupper($pref['mailer']).")" : ' (PHP)'; + $sendto = trim($_POST['testaddress']); + + $eml = array( + 'subject' => LAN_MAILOUT_113." ".$add, + 'body' => str_replace("[br]", "\n", LAN_MAILOUT_114), + 'template' => vartrue($_POST['testtemplate'],null) + ); + + 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,''); + } + } + + } @@ -622,7 +647,7 @@ class mailout_main_ui extends e_admin_ui else { $text = "

Ready to Process Mail Queue

"; - $text .= e107::getForm()->progressBar('mail-progress',1, array('btn-label'=>'Start', 'url'=> e_SELF)); + $text .= e107::getForm()->progressBar('mail-progress',1, array('btn-label'=>'Start #'.$id, 'url'=> e_SELF, 'mode'=>$id)); } return $text; @@ -722,6 +747,7 @@ class mailout_main_ui extends e_admin_ui ".LAN_MAILOUT_110."
".$frm->admin_button('testemail', LAN_MAILOUT_112,'other')."  + ".$this->mailAdmin->sendStyleSelect(varset($_POST['testtemplate'], 'textonly'), 'testtemplate')." diff --git a/e107_core/templates/email_template.php b/e107_core/templates/email_template.php index c9e5e5304..68efcc7df 100644 --- a/e107_core/templates/email_template.php +++ b/e107_core/templates/email_template.php @@ -10,44 +10,10 @@ * */ - /** * This file defines the default templates for each type of email which may be sent. * In general it is assumed that HTML emails are being sent (with a plain text alternate part), although simple plain text emails are also possible. * - * Default values are defined for the key elements of an email: - * - * $EMAIL_HEADER - the first part of the email, usually defining the headers, and everything up to and including - * $EMAIL_FOOTER - the last part of the email - it may include a displayed footer, as well as and other 'closing' tags - * - * Taken as a pair, $EMAIL_HEADER.$EMAIL_FOOTER must generate standards-compliant XHTML - * - * $EMAIL_BODY - the body text of the email - essentially, the message. It gets sandwiched between $EMAIL_HEADER and $EMAIL_FOOTER - * This must generate standards-compliant XHTML in its own right, when taken with an appropriate header and footer section. - * Within the template definition, insert the shortcode '{BODY}' to indicate where the passed text of the email is to be stored. - * - * $EMAIL_OVERRIDES may optionally be defined, in which case it can override default mailout settings (see later). Only define this variable - * if you explicitly want overrides - a defined, but empty, variable may have unexpected consequences! - * - * $EMAIL_PLAINTEXT - an alternative template for the alternative text part of HTML emails. Set to empty string if hard-coded default to be used - * - * - * Templates may be defined for specific purposes - * Each template is given a name, which is the name of the variable. - * This variable may be a simple string, in which case it defines the email body, and is only available via code. - * Alternatively the variable may be an array, in which case each element of the array defines a different aspect of the email: - * - * $NAME['template_name'] is a user-friendly name shown in the mass mailer - * $NAME['template_type'] takes values (user|system|all) to define its purpose - only 'user' and 'all' templates are shown in the mass mailer - * $NAME['email_header'] defines the header - optional - * $NAME['email_footer'] defines the footer - optional - * $NAME['email_body'] defines the body text - * $NAME['email_overrides'] defines any mailout settings which are to be overridden (see later) - optional - * - * The format and functionality of these four main array elements correspond exactly to those of the defaults already described. - * - * The template need only define those variables which are to be overridden, in which case the default definitions will be used for the others. - * * * For templated HTML emails, a style sheet MUST be specified in the header field (if its required), in one of the following forms: * @@ -75,7 +41,7 @@ if (!defined('e107_INIT')) { exit; } // @TODO: Move signup email into templated form $includeSiteButton = e107::getPref('sitebutton'); - +/* $SIGNUPEMAIL_SUBJECT = LAN_SIGNUP_96.' {SITENAME}'; $SIGNUPEMAIL_USETHEME = 1; // Use CSS STYLE from THEME: 0 = Off, 1 = external, 2 = embedded $SIGNUPEMAIL_LINKSTYLE = ''; // css to use on links eg. color:red; @@ -84,7 +50,7 @@ $SIGNUPEMAIL_CC = ""; // comma separated email addresses to put in CC of th $SIGNUPEMAIL_BCC = ""; // comma separated email addresses to put in BCC of the signup email. $SIGNUPEMAIL_ATTACHMENTS = ""; // files-path array of attachments. eg. array(e_FILE."myfile.zip",e_FILE."myotherfile.zip"); $SIGNUPEMAIL_BACKGROUNDIMAGE = ""; // absolute path to a background image eg. e_IMAGE."mybackground.jpg"; - +*/ /*=========================================================================== @@ -121,6 +87,7 @@ $EMAIL_OVERRIDES = array( */ // Not used in signup email +/* $EMAIL_HEADER = " @@ -144,58 +111,15 @@ $EMAIL_FOOTER = " $EMAIL_PLAINTEXT = ''; - -/*=========================================================================== - TEMPLATES FOR SPECIFIC EMAIL TYPES -=============================================================================*/ - -/** -Each template is an array whose name must match that used in the code. -The array has two mandatory elements (name and type). -The array may have up to five optional elements, each of which overrides the corresponding default value if present -An empty element sets the field to empty. -An element that is not present results in the default being used. - -Elements are as follows: - 'template_name' - string - mandatory - a 'user-friendly' name for display - 'template_type' - string(user|system|all) - mandatory - 'all' and 'user' templates are available for selection in the bulk mailer - 'email_overrides' - an array - 'email_header' - string - 'email_body' - string - 'email_footer' - string - 'email_plainText' - string - -// If everything is standard apart from the body, the body can be defined as a simple variable - */ -//TODO - integrate into mailout routine -/* -$MAILOUT_HEADER = " - - - -{STYLESHEET} - - -
-"; -$MAILOUT_FOOTER = " -

-{SITENAME=link} -
- -"; - - - -*/ //------------------------------------------------------------- // 'SIGNUP' TEMPLATE //------------------------------------------------------------- //@Deprecated +/* $SIGNUPEMAIL_TEMPLATE = "
@@ -224,76 +148,10 @@ LAN_SIGNUP_97." {SITENAME}
"; - -//------------------------------------------------------------- -// 'NOTIFY' TEMPLATE -//------------------------------------------------------------- +*/ - -//------------------------------------------------------------- -// USER-DEFINED TEMPLATES (for mass mailouts) -//------------------------------------------------------------- -/* -$TEST_TEMPLATE = array( - 'template_name' => 'TEst1', - 'template_type' => 'system', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => '{BODY}', - 'email_footer' => 'footer', - 'email_plainText' => '' - ); -$TEST2_TEMPLATE = array( - 'template_name' => 'TEst2', - 'template_type' => 'all', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => '{BODY}', - 'email_footer' => 'footer' - ); -$TEST3_TEMPLATE = array( - 'template_name' => 'TEst4', - 'template_type' => 'user', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => '{BODY}', - 'email_footer' => 'footer' - ); -$TEST4_TEMPLATE = array( - 'template_name' => 'TEst5', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => '{BODY}', - 'email_footer' => 'footer' - ); - */ -$WHATSNEW_TEMPLATE = array( - 'template_name' => 'WhatsNew', - 'template_type' => 'user', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => 'All the latest news and updates.
{BODY}
To find out more, simply click on the links!', -// 'email_footer' => 'footer' - ); -$MONTHLYUPDATE_TEMPLATE = array( - 'template_name' => 'MonthlyUpdate', - 'template_type' => 'user', - 'email_overrides' => '', -// 'email_header' - any header information (usually loaded from the default) - 'email_body' => 'Just to keep you up to date, here\'s a reminder of what\'s changed in the past month.
- {BODY}
To find out more, simply click on the links!', -// 'email_footer' => 'footer' - ); - - - - - - - - -// ----------------------- Everything above this line is deprecated but may continue to work for a while ------------------------------- // +// ----------------------- Everything above this line is deprecated ------------------------------- // /** Standardized v2 template rewrite diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index 575435782..b56f74bb7 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -608,21 +608,32 @@ class e107Email extends PHPMailer { $tp = e107::getParser(); + // Cleanup legacy key names. ie. remove 'email_' prefix. + foreach($eml as $k=>$v) + { + if(substr($k,0,6) == 'email_') + { + $nkey = substr($k,6); + $eml[$nkey] = $v; + unset($eml[$k]); + } + } + + if(vartrue($eml['template'])) // @see e107_core/templates/email_template.php { - - + if($tmpl = e107::getCoreTemplate('email', $eml['template'], 'front', true)) //FIXME - Core template is failing with template 'notify'. Works with theme template. Issue with core template registry? { - $eml['shortcodes']['BODY'] = $tp->toEmail($eml['email_body']); - $eml['shortcodes']['SUBJECT'] = $eml['email_subject']; + $eml['shortcodes']['BODY'] = $tp->toEmail($eml['body']); + $eml['shortcodes']['SUBJECT'] = $eml['subject']; $eml['shortcodes']['THEME'] = e_THEME.$this->pref['sitetheme'].'/'; // Always use front-end theme path. $emailBody = $tmpl['header']. $tmpl['body'] . $tmpl['footer']; - $eml['email_body'] = $tp->parseTemplate($emailBody, true, varset($eml['shortcodes'],null)); + $eml['body'] = $tp->parseTemplate($emailBody, true, varset($eml['shortcodes'],null)); - // $eml['email_body'] = ($tp->toEmail($tmpl['header']). str_replace('{BODY}', $eml['email_body'], $tmpl['body']). $tp->toEmail($tmpl['footer'])); + // $eml['body'] = ($tp->toEmail($tmpl['header']). str_replace('{BODY}', $eml['body'], $tmpl['body']). $tp->toEmail($tmpl['footer'])); if($this->debug) { @@ -640,31 +651,32 @@ class e107Email extends PHPMailer { echo "

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

"; } - $emailBody = $eml['email_body']; + $emailBody = $eml['body']; - if (vartrue($eml['email_subject'])) $this->Subject = $tp->parseTemplate($eml['email_subject'], true, varset($eml['shortcodes'],null)); + if (vartrue($eml['subject'])) $this->Subject = $tp->parseTemplate($eml['subject'], true, varset($eml['shortcodes'],null)); e107::getMessage()->addDebug("Couldn't find email template: ".$eml['template']); } } else { - if (vartrue($eml['email_subject'])) $this->Subject = $tp->parseTemplate($eml['email_subject'], true, varset($eml['shortcodes'],null)); - // $eml['email_body'] = ($tp->toEmail($tmpl['header']). str_replace('{BODY}', $eml['email_body'], $tmpl['body']). $tp->toEmail($tmpl['footer'])); + if (vartrue($eml['subject'])) $this->Subject = $tp->parseTemplate($eml['subject'], true, varset($eml['shortcodes'],null)); + // $eml['body'] = ($tp->toEmail($tmpl['header']). str_replace('{BODY}', $eml['body'], $tmpl['body']). $tp->toEmail($tmpl['footer'])); } - + + if (isset($eml['SMTPDebug'])) $this->SMTPDebug = $eml['SMTPDebug']; // 'FALSE' is a valid value! - 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 (vartrue($eml['sender_email'])) $this->From = $eml['sender_email']; + if (vartrue($eml['sender_name'])) $this->FromName = $eml['sender_name']; + if (vartrue($eml['replyto'])) $this->AddAddressList('replyto',$eml['replyto'],vartrue($eml['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['body'])) $this->makeBody($eml['body'], $this->allow_html, $this->add_HTML_header); + if (vartrue($eml['attach'])) $this->attach($eml['attach']); + if (vartrue($eml['copy_to'])) $this->AddAddressList('cc',$eml['copy_to'],vartrue($eml['cc_names'],'')); + if (vartrue($eml['bcopy_to'])) $this->AddAddressList('bcc',$eml['bcopy_to'],vartrue($eml['bcc_names'],'')); if (vartrue($eml['bouncepath'])) { @@ -680,8 +692,8 @@ class e107Email extends PHPMailer 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['inline_images'])) $this->addInlineImages($eml['inline_images']); + if (vartrue($eml['priority'])) $this->Priority = $eml['priority']; if (vartrue($eml['e107_header'])) $this->AddCustomHeader("X-e107-id: {$eml['e107_header']}"); if (vartrue($eml['extra_header'])) { @@ -714,23 +726,24 @@ class e107Email extends PHPMailer 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: - $eml['email_subject'] - $eml['email_sender_email'] - 'From' email address - $eml['email_sender_name'] - 'From' name - $eml['email_replyto'] - Optional 'reply to' field - $eml['email_replytonames'] - Name(s) corresponding to 'reply to' field - only used if 'replyto' used + $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 ...) - $eml['email_body'] - message body. May be HTML or text. Added according to the current state of the HTML enable flag - $eml['email_attach'] - string if one file, array of filenames if one or more. - $eml['email_copy_to'] - comma-separated list of cc addresses. - $eml['email_cc_names'] - comma-separated list of cc names. Optional, used only if $eml['email_copy_to'] specified - $eml['email_bcopy_to'] - comma-separated list - $eml['email_bcc_names'] - comma-separated list of bcc names. Optional, used only if $eml['email_copy_to'] specified + $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['email_inline_images'] - array of files for inline images + $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 diff --git a/e107_handlers/mailout_admin_class.php b/e107_handlers/mailout_admin_class.php index a14c3b37d..6b09b994d 100644 --- a/e107_handlers/mailout_admin_class.php +++ b/e107_handlers/mailout_admin_class.php @@ -2043,7 +2043,7 @@ class mailoutAdminClass extends e107MailManager { $ret = array(); - $templates = e107::getCoreTemplate('email'); + $templates = e107::getCoreTemplate('email', false, 'front', false); foreach($templates as $key => $layout) {