1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-16 20:28:28 +01:00

Email notification improvements and fixes. (work in progress).

This commit is contained in:
Cameron 2015-05-12 01:45:00 -07:00
parent e4516a4ea7
commit 3a238bf622
8 changed files with 346 additions and 85 deletions

View File

@ -294,8 +294,8 @@ class mailout_main_ui extends e_admin_ui
'mail_fail_count' => array('title' => LAN_MAILOUT_128, 'noedit'=>true, 'type'=>'number'),
'mail_bounce_count' => array('title' => LAN_MAILOUT_144, 'noedit'=>true, 'type'=>'number'),
'mail_start_send' => array('title' => LAN_MAILOUT_131,'noedit'=>true, 'type'=>'number', 'proc' => 'sdatetime'),
'mail_end_send' => array('title' => LAN_MAILOUT_132, 'noedit'=>true, 'type'=>'number', 'proc' => 'sdatetime'),
'mail_start_send' => array('title' => LAN_MAILOUT_131,'noedit'=>true, 'type'=>'datestamp'),
'mail_end_send' => array('title' => LAN_MAILOUT_132, 'noedit'=>true, 'type'=>'datestamp'),
'mail_create_date' => array('title' => LAN_MAILOUT_130, 'type'=>null, 'noedit'=>true, 'data'=>'int'),
'mail_creator' => array('title' => LAN_MAILOUT_85, 'type'=>null, 'noedit'=>true, 'data'=>'int'),
'mail_create_app' => array('title' => LAN_MAILOUT_133, 'type'=>null, 'noedit'=>true,'data'=>'str'),
@ -705,7 +705,8 @@ class mailout_main_ui extends e_admin_ui
'USERID' =>'555',
'MAILREF' => '123',
'NEWSLETTER' => SITEURL."newsletter/?id=example1234567",
'UNSUBSCRIBE' => SITEURL."unsubscribe/?id=example1234567",
'UNSUBSCRIBE' => SITEURL."unsubscribe.php?id=example1234567",
'UNSUBSCRIBE_MESSAGE'=> "This email was sent to test@email.com. If you don't want to receive these emails in the future, please <a href='".SITEURL."unsubscribe.php?id=example1234567'>unsubscribe</a>. ",
'ACTIVATION_LINK' => "<a href='http://whereever.to.activate.com/'>http://whereever.to.activate.com/</a>",
'USERURL' => "www.user-website.com",
'PASSWORD' => "test-password",

View File

@ -84,73 +84,6 @@ $EMAIL_OVERRIDES = array(
);
*/
// Not used in signup email
/*
$EMAIL_HEADER = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns='http://www.w3.org/1999/xhtml' >
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
{STYLESHEET}
</head>
<body>
<div style='padding:10px'>
";
$EMAIL_BODY = 'Software malfunction - no email body text specified for template'; // Help debug
// Not used in signup email
$EMAIL_FOOTER = "
<br /><br />
{SITENAME=link}
</div>
</body>
</html>";
$EMAIL_PLAINTEXT = '';
*/
//-------------------------------------------------------------
// 'SIGNUP' TEMPLATE
//-------------------------------------------------------------
//@Deprecated
/*
$SIGNUPEMAIL_TEMPLATE = "
<div style='padding:10px'>
<div style='text-align:left; width:90%'>
".LAN_EMAIL_01." {USERNAME},<br />
<br />".
LAN_SIGNUP_97." {SITENAME}<br />
".LAN_SIGNUP_21."<br />
<br />
{ACTIVATION_LINK}<br />
<br />
".LAN_SIGNUP_59."<br />
<br />
".LAN_SIGNUP_18."<br />
<br />
".LAN_LOGINNAME.": <b> {LOGINNAME} </b><br />
".LAN_PASSWORD.": <b> {PASSWORD} </b><br />
<br />
".LAN_EMAIL_04."<br />
".LAN_EMAIL_05."<br />
<br />
".LAN_EMAIL_06."<br />
<br />
{SITENAME}<br />
{SITEURL}
<br /><br />".($includeSiteButton ? "<a href='".SITEURL."' title=''><img src='".e_IMAGE_ABS.str_replace('{e_IMAGE}', '', $includeSiteButton)."' alt='' /></a>" : '')."
</div>
</div>
";
*/
// ----------------------- Everything above this line is deprecated ------------------------------- //
/** Standardized v2 template rewrite
*
@ -174,6 +107,7 @@ $EMAIL_TEMPLATE['default']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHT
div#body { padding:10px; width: 93%; max-width:800px; background-color: #FFFFFF; border-radius: 5px; font-family: helvetica,arial }
.video-thumbnail { max-width: 400px }
.media img { max-width:600px }
.unsubscribe { font-size:11px; color:#aaaaaa; margin-top:20px; padding:20px 0; border-top:solid 1px #e5e5e5; }
</style>
</head>
@ -260,9 +194,30 @@ $EMAIL_TEMPLATE['quickadduser']['footer'] = $EMAIL_TEMPLATE['default']['footer'
// ------- 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.
$EMAIL_TEMPLATE['notify']['header'] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns='http://www.w3.org/1999/xhtml' >
<head>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style type='text/css'>
body { padding:10px; background-color: #E1E1E1 }
div#body { padding:10px; width: 93%; max-width:800px; background-color: #FFFFFF; border-radius: 5px; font-family: helvetica,arial }
.video-thumbnail { max-width: 400px }
.media img { max-width:200px; }
td.body { padding:5px; vertical-align: top }
.unsubscribe { font-size:11px; color:#aaaaaa; margin-top:20px; padding:20px 0; border-top:solid 1px #e5e5e5; }
</style>
</head>
<body>
<div id='body'>
";
$EMAIL_TEMPLATE['notify']['body'] = "<table><tr><td>{MEDIA1}</td><td class='body'>{BODY}</td></tr></table>";
$EMAIL_TEMPLATE['notify']['footer'] = "<br /><br />
{SITENAME=link}
<div class='unsubscribe'>{UNSUBSCRIBE_MESSAGE}</div>
</div>
</body>
</html>";
// ------ User-Specific Templates

View File

@ -66,7 +66,9 @@ class e107_event
'admin_news_created' => NN_LAN_3,
'admin_news_updated' => NN_LAN_4,
'admin_news_deleted' => NN_LAN_5,
'admin_news_subscribers' => "Notification of News Subscribers", // TODO LAN
'user_news_submit' => NN_LAN_2,
),
'mail' => array(

View File

@ -527,6 +527,7 @@ class e107Email extends PHPMailer
*/
public function makeBody($message,$want_HTML = 1, $add_HTML_header = FALSE)
{
switch (varset($this->general_opts['textonly'],'off'))
{
case 'pref' : // Disable HTML as default
@ -541,6 +542,8 @@ class e107Email extends PHPMailer
if ($want_HTML !== FALSE)
{
$message = e107::getParser()->toHtml("[html]".$message."[/html]",true);
if ($this->debug) echo "Generating multipart email<br />";
if ($add_HTML_header)
{

View File

@ -154,6 +154,7 @@ class e107MailManager
'mail_content' => array(
'mail_source_id' => 'int',
'mail_content_status' => 'int',
'mail_total_count' => 'int',
'mail_togo_count' => 'int',
'mail_sent_count' => 'int',
'mail_fail_count' => 'int',
@ -170,7 +171,8 @@ class e107MailManager
'mail_subject' => 'todb',
'mail_body' => 'todb',
'mail_body_templated' => 'todb',
'mail_other' => 'string' // Don't want entities here!
'mail_other' => 'string', // Don't want entities here!
'mail_media' => 'string'
)
);
@ -276,6 +278,12 @@ class e107MailManager
}
$res['mail_other'] = e107::serialize($res1,false); // Ready to write to DB
if (!empty($res['mail_media']))
{
$res['mail_media'] = e107::serialize($res['mail_media']);
}
return $res;
}
@ -1808,7 +1816,10 @@ class e107MailManager
// To many recipients to send at once - add to the emailing queue
// @TODO - handle any other relevant $extra fields
$emailData['mail_total_count'] = count($recipientData);
$result = $this->saveEmail($emailData, TRUE);
if ($result === FALSE)
{
// TODO: Handle error

View File

@ -117,20 +117,23 @@ class notify
* @todo handle 'everyone except' clauses (email address filter done)
* @todo set up pref to not notify originator of event which caused notify (see $blockOriginator)
*/
function send($id, $subject, $message)
function send($id, $subject, $message, $media=array())
{
$tp = e107::getParser();
$sql = e107::getDb();
$subject = $tp->toEmail(SITENAME.': '.$subject);
$message = $tp->toEmail($message);
$message = $tp->replaceConstants($message, "full");
// $message = $tp->toEmail($message);
$emailFilter = '';
$notifyTarget = $this->notify_prefs['event'][$id]['class'];
if ($notifyTarget == '-email')
{
$emailFilter = $this->notify_prefs['event'][$id]['email'];
}
$blockOriginator = FALSE; // TODO: set this using a pref
$recipients = array();
@ -143,7 +146,7 @@ class notify
);
}
}
elseif (is_numeric($this->notify_prefs['event'][$id]['class']))
elseif (is_numeric($notifyTarget))
{
switch ($notifyTarget)
{
@ -157,14 +160,17 @@ class notify
$qry = "`user_ban` = 0";
break;
default :
$qry = "user_ban = 0 AND user_class REGEXP '(^|,)(".$this->notify_prefs['event'][$id]['class'].")(,|$)'";
$qry = "user_ban = 0 AND user_class REGEXP '(^|,)(".$notifyTarget.")(,|$)'";
break;
}
$qry = 'SELECT user_id,user_name,user_email FROM `#user` WHERE '.$qry;
$qry = 'SELECT user_id,user_name,user_email,user_join,user_lastvisit FROM `#user` WHERE '.$qry;
if ($blockOriginator)
{
$qry .= ' AND `user_id` != '.USERID;
}
if (false !== ($count = $sql->gen($qry)))
{
// Now add email addresses to the list
@ -172,9 +178,27 @@ class notify
{
if ($row['user_email'] != $emailFilter)
{
$recipients[] = array('mail_recipient_id' => $row['user_id'],
$unsubscribe = array('date'=>$row['user_join'],'email'=>$row['user_email'],'id'=>$row['user_id'], 'plugin'=>'user', 'userclass'=>$notifyTarget);
$urlQuery = http_build_query($unsubscribe,null,'&');
$exclude = array(e_UC_MEMBER,e_UC_ADMIN, e_UC_MAINADMIN); // no unsubscribe for these classes.
$unsubUrl = SITEURL."unsubscribe.php?id=".base64_encode($urlQuery);
$unsubMessage = "This message was sent to ".$row['user_email'].". If you don't want to receive these emails in the future, please <a href='".$unsubUrl."'>unsubscribe</a>.";
$recipients[] = array(
'mail_recipient_id' => $row['user_id'],
'mail_recipient_name' => $row['user_name'], // Should this use realname?
'mail_recipient_email' => $row['user_email']
'mail_recipient_email' => $row['user_email'],
'mail_target_info' => array(
'USERID' => $row['user_id'],
'DISPLAYNAME' => $row['user_name'],
// 'SIGNUP_LINK' => '',
'USERNAME' => $row['user_name'],
'USERLASTVISIT' => $row['user_lastvisit'],
'UNSUBSCRIBE' => (!in_array($notifyTarget, $exclude)) ? $unsubUrl : '',
'UNSUBSCRIBE_MESSAGE' => (!in_array($notifyTarget, $exclude)) ? $unsubMessage : ''
)
);
}
}
@ -199,6 +223,7 @@ class notify
// Create the mail body
$mailData = array(
'mail_total_count' => count($recipients),
'mail_content_status' => MAIL_STATUS_TEMP,
'mail_create_app' => 'notify',
'mail_title' => 'NOTIFY',
@ -207,10 +232,19 @@ class notify
'mail_sender_name' => e107::getPref('siteadmin'),
'mail_notify_complete' => 0, // NEVER notify when this email sent!!!!!
'mail_body' => $message,
'template' => 'notify'
'template' => 'notify',
'mail_send_style' => 'notify'
);
$result = $mailer->sendEmails('NOTIFY_TEMPLATE', $mailData, $recipients);
if(!empty($media) && is_array($media))
{
foreach($media as $k=>$v)
{
$mailData['mail_media'][$k] = array('path'=>$v);
}
}
$result = $mailer->sendEmails('notify', $mailData, $recipients);
e107::getLog()->e_log_event(10,-1,'NOTIFY',$subject,$message,FALSE,LOG_TO_ROLLING);
}
else
@ -336,6 +370,33 @@ class notify
function notify_admin_news_created($data)
{
$this->notify_newspost($data);
}
function notify_admin_news_subscribers($data)
{
$tp = e107::getParser();
$url = e107::getUrl()->create('news/view/item', $data,'full=1');
$message = "<b><a href='".$url."'>".$tp->toHtml($data['news_title'])."</a></b>";
$img = explode(",",$data['news_thumbnail']);
if (vartrue($data['news_summary'])){ $message .= '<br /><br />'.$tp->toEmail($data['news_summary']); }
$message .= "<a href='".$url."'>View now</a>";
$this->send('admin_news_updated', $data['news_title'], $message, $img);
print_a($message);
return $message;
}
}

View File

@ -0,0 +1,97 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Newsletter plugin - mailout function
*
*
*/
/**
* e107 Newsletter plugin
*
* @package e107_plugins
* @subpackage newsletter
* @version $Id$;
*/
if (!defined('e107_INIT')) { exit; }
/*
Class for newsletter mailout function
Allows admins to send mail to those subscribed to one or more newsletters
*/
// These variables determine the circumstances under which this class is loaded (only used during loading, and may be overwritten later)
$mailerIncludeWithDefault = TRUE; // Mandatory - if false, show only when mailout for this specific plugin is enabled
$mailerExcludeDefault = FALSE; // Mandatory - if TRUE, when this plugin's mailout is active, the default (core) isn't loaded
class user_mailout
{
protected $mailCount = 0;
protected $mailRead = 0;
//public $mailerSource = 'newsletter'; // Plugin name (core mailer is special case) Must be directory for this file
public $mailerName = LAN_PLUGIN_NEWSLETTER_NAME; // Text to identify the source of selector (displayed on left of admin page)
public $mailerEnabled = TRUE; // Mandatory - set to FALSE to disable this plugin (e.g. due to permissions restrictions)
private $selectorActive = FALSE; // Set TRUE if we've got a valid selector to start returning entries
private $targets = array(); // Used to store potential recipients
private $ourDB;
// Constructor
public function __construct()
{
// BAD FOR PERFORMANCE
//$this->e107 = e107::getInstance();
//$this->adminHandler = e107::getRegistry('_mailout_admin'); // Get the mailer admin object - we want to use some of its functions
}
/**
* Manage Bounces.
*/
public function bounce($data)
{
e107::getLog()->add('Newsletter Bounce', $data, E_LOG_INFORMATIVE, 'BOUNCE');
}
/**
* @param $mode - check || process
* @param array $data - usually email, date, id - but dependent on unsubscribe link above.
*/
function unsubscribe($mode, $data=null)
{
if($mode == 'check') // check that a matching email,id,creation-date exists.
{
return e107::getDb()->select('user','*', 'user_class!="" AND user_id='.intval($data['id'])." AND user_join=".intval($data['date'])." AND user_email=\"".$data['email']."\"", true);
}
print_a($data);
if($mode == 'process') // Update record. Return true on success, and false on error.
{
$update = array(
'cust_subscribed' => 0,
'cust_unsubscribed' => time(),
'WHERE' => "user_id=".intval($data['id'])." AND cust_datestamp=".intval($data['date'])." AND cust_email=\"".$data['email']."\""
);
// return e107::getDb()->update('user',$update);
}
}
}
?>

131
unsubscribe.php Normal file
View File

@ -0,0 +1,131 @@
<?php
if (!defined('e107_INIT'))
{
require_once("class2.php");
}
define('e_IFRAME', true);
require_once(HEADERF);
class unsubscribe
{
function __construct()
{
$mes = e107::getMessage();
$frm = e107::getForm();
// $this->simulation();
$mailoutPlugins = e107::getConfig()->get('e_mailout_list');
if(!vartrue($_GET['id']))
{
return;
}
$tmp = base64_decode($_GET['id']);
parse_str($tmp,$data);
e107::getMessage()->addDebug(print_a($data,true));
$plugin = vartrue($data['plugin'],false);
if(empty($data) || !e107::isInstalled($plugin) || !in_array($plugin, $mailoutPlugins))
{
$this->invalidURL();
return;
}
$ml = e107::getAddon($plugin,'e_mailout');
if(vartrue($_POST['remove']) && !empty($data))
{
if($ml->unsubscribe('process',$data)!=false)
{
$text = "<p><b>".$data['email']."</b> has been removed from ".$ml->mailerName.".</p>";
$mes->addSuccess($text);
}
else
{
$text = "<p>There was a problem when attempting to remove <b>".$data['email']."</b> from ".$ml->mailerName.".</p>";
$mes->addError($text);
}
echo "<div class='container'>".$mes->render()."</div>";
return;
}
if($ml->unsubscribe('check',$data) != false)
{
$text = "<p>We are very sorry for the inconvenience. <br />Please click the button below to remove <b>".$data['email']."</b> from the ".$ml->mailerName.".</p>";
$text .= $frm->open('unsub','post',e_REQUEST_URI);
$text .= $frm->button('remove','Remove ','submit');
$text .= $frm->close();
$mes->setTitle('Unsubscribe',E_MESSAGE_INFO)->addInfo($text);
echo "<div class='container'>".$mes->render()."</div>";
return;
}
else
{
$this->invalidURL();
return;
}
}
function simulation()
{
$row = array();
$row['datestamp'] = time();
$row['email'] = "test@test.com";
$row['id'] = 23;
$unsubscribe = array('date'=>$row['datestamp'],'email'=>$row['email'],'id'=>$row['id'],'plugin'=>'user');
$urlQuery = http_build_query($unsubscribe,null,'&');
$_GET['id'] = base64_encode($urlQuery);
e107::getMessage()->addDebug("urlQuery = ".$urlQuery);
//echo "urlQuery = ".$urlQuery."<br/>";
e107::getMessage()->addDebug(e_SELF."?id=".$_GET['id']);
}
function invalidURL()
{
$mes = e107::getMessage();
$mes->addWarning("Invalid URL");
echo "<div class='container'>".$mes->render()."</div>";
return;
}
}
new unsubscribe;
require_once(FOOTERF);
exit;
?>