From c73c07490b73a6f5ef8d5e93944ba6340f10c4d1 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 13 May 2015 17:45:24 -0700 Subject: [PATCH] Fix for notifications to less than 5 people. Notification now come from the site email, not the admin email. --- e107_handlers/mail.php | 2 +- e107_handlers/mail_manager_class.php | 77 ++++++++++++++++++++++------ e107_handlers/notify_class.php | 9 ++-- e107_plugins/user/plugin.xml | 6 +++ 4 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 e107_plugins/user/plugin.xml diff --git a/e107_handlers/mail.php b/e107_handlers/mail.php index a1c4cb8a6..986313fff 100644 --- a/e107_handlers/mail.php +++ b/e107_handlers/mail.php @@ -819,7 +819,6 @@ class e107Email extends PHPMailer } - $identifier = deftrue('MAIL_IDENTIFIER', 'X-e107-id'); if (isset($eml['SMTPDebug'])) { $this->SMTPDebug = $eml['SMTPDebug']; } // 'FALSE' is a valid value! @@ -959,6 +958,7 @@ class e107Email extends PHPMailer $_SERVER["HTTP_CF_CONNECTING_IP"] = $_SERVER['SERVER_ADDR']; $result = $this->Send(); // Actually send email + $_SERVER['PHP_SELF'] = $oldphpself; $_SERVER['REMOTE_ADDR'] = $oldremoteaddr; diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php index fa1a05839..af9201bed 100644 --- a/e107_handlers/mail_manager_class.php +++ b/e107_handlers/mail_manager_class.php @@ -840,18 +840,41 @@ class e107MailManager /** * Given an email block, creates an array of data compatible with PHPMailer, including any necessary substitutions + * $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['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'); */ protected function makeEmailBlock($email) { $mailSubsInfo = array( - 'email_subject' => 'mail_subject', - 'email_sender_email' => 'mail_sender_email', - 'email_sender_name' => 'mail_sender_name', + 'subject' => 'mail_subject', + 'sender_email' => 'mail_sender_email', + 'sender_name' => 'mail_sender_name', // 'email_replyto' - Optional 'reply to' field // 'email_replytonames' - Name(s) corresponding to 'reply to' field - only used if 'replyto' used - 'email_copy_to' => 'mail_copy_to', // - comma-separated list of cc addresses. + 'copy_to' => 'mail_copy_to', // - comma-separated list of cc addresses. //'email_cc_names' - comma-separated list of cc names. Optional, used only if $eml['email_copy_to'] specified - 'email_bcopy_to' => 'mail_bcopy_to', + 'bcopy_to' => 'mail_bcopy_to', // 'email_bcc_names' - comma-separated list of bcc names. Optional, used only if $eml['email_copy_to'] specified //'bouncepath' - Sender field (used for bounces) //'returnreceipt' - email address for notification of receipt (reading) @@ -863,18 +886,30 @@ class e107MailManager 'template' => 'mail_send_style', // required 'shortcodes' => 'mail_target_info' // required ); + + $result = array(); + + if (!isset($email['mail_source_id'])) $email['mail_source_id'] = 0; if (!isset($email['mail_target_id'])) $email['mail_target_id'] = 0; if (!isset($email['mail_recipient_id'])) $email['mail_recipient_id'] = 0; + + + + + foreach ($mailSubsInfo as $k => $v) { if (isset($email[$v])) { $result[$k] = $email[$v]; + //unset($email[$v]); } } + + // Do any substitutions $search = array(); $replace = array(); @@ -883,14 +918,17 @@ class e107MailManager $search[] = '|'.$k.'|'; $replace[] = $v; } + $result['email_body'] = str_replace($search, $replace, $this->currentMailBody); + if ($this->currentTextBody) { $result['mail_body_alt'] = str_replace($search, $replace, $this->currentTextBody); } + $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 @@ -1775,19 +1813,25 @@ class e107MailManager $eCount = 0; // @TODO: Generate alt text etc + foreach ($recipientData as $recip) { // Fill in other bits of email - $emailData['mail_target_info'] = $recip; - $mailToSend = $this->makeEmailBlock($emailData); // Substitute mail-specific variables, attachments etc - - - - - - if (FALSE == $this->mailer->sendEmail($recip['mail_recipient_email'], $recip['mail_recipient_name'], $mailToSend, TRUE)) + // $emailData['mail_target_info'] = $recip ; + $merged = array_merge($emailData,$recip); + $mailToSend = $this->makeEmailBlock($merged); // Substitute mail-specific variables, attachments etc +/* + echo "

MERGED

"; + print_a($merged); + echo "

RETURNED

"; + print_a($mailToSend); + echo "
"; + continue; + + */ + if (FALSE == $this->mailer->sendEmail($recip['mail_recipient_email'], $recip['mail_recipient_name'], $mailToSend, true)) { $tempResult = FALSE; if($this->debugMode) @@ -1814,7 +1858,10 @@ class e107MailManager return $tempResult; } - // To many recipients to send at once - add to the emailing queue + + // ----------- Too many recipients to send at once - add to the emailing queue ---------------- // + + // @TODO - handle any other relevant $extra fields $emailData['mail_total_count'] = count($recipientData); diff --git a/e107_handlers/notify_class.php b/e107_handlers/notify_class.php index d87ad3d59..a03a400c6 100644 --- a/e107_handlers/notify_class.php +++ b/e107_handlers/notify_class.php @@ -219,12 +219,15 @@ class notify if(E107_DEBUG_LEVEL > 0) { $data = array('id'=>$id, 'subject'=>$subject, 'recipients'=> $recipients, 'prefs'=>$this->notify_prefs['event'][$id], 'message'=>$message); + + e107::getMessage()->addDebug("Mailing is simulated only while in DEBUG mode."); e107::getMessage()->addDebug(print_a($data,true)); e107::getLog()->add('Notify Debug', $data, E_LOG_INFORMATIVE, "NOTIFY_DBG"); return; } - + $siteadminemail = e107::getPref('siteadminemail'); + $siteadmin = e107::getPref('siteadmin'); if (count($recipients)) { @@ -238,8 +241,8 @@ class notify 'mail_create_app' => 'notify', 'mail_title' => 'NOTIFY', 'mail_subject' => $subject, - 'mail_sender_email' => e107::getPref('siteadminemail'), - 'mail_sender_name' => e107::getPref('siteadmin'), + 'mail_sender_email' => e107::getPref('replyto_email',$siteadminemail), + 'mail_sender_name' => e107::getPref('replyto_name',$siteadmin), 'mail_notify_complete' => 0, // NEVER notify when this email sent!!!!! 'mail_body' => $message, 'template' => 'notify', diff --git a/e107_plugins/user/plugin.xml b/e107_plugins/user/plugin.xml new file mode 100644 index 000000000..b6fb718bf --- /dev/null +++ b/e107_plugins/user/plugin.xml @@ -0,0 +1,6 @@ + + + + User Theme and Language Menus + user + \ No newline at end of file