Merge pull request #1266 from fabrixxm/feature-hook-emailer_send

Adds 'emailer_send_prepare' and 'emailer_send' hooks
This commit is contained in:
Tobias Diekershoff 2014-12-29 16:22:56 +01:00
commit 384e5f15ff
3 changed files with 33 additions and 4 deletions

View file

@ -196,6 +196,24 @@ Current hooks:
'email' => email to look up the avatar for 'email' => email to look up the avatar for
'url' => the (string) generated URL of the avatar 'url' => the (string) generated URL of the avatar
**'emailer_send_prepare'** - called from Emailer::send() before building the mime message
$b is (array) , params to Emailer::send()
'fromName' => name of the sender
'fromEmail' => email fo the sender
'replyTo' => replyTo address to direct responses
'toEmail' => destination email address
'messageSubject' => subject of the message
'htmlVersion' => html version of the message
'textVersion' => text only version of the message
'additionalMailHeader' => additions to the smtp mail header
**'emailer_send'** - called before calling PHP's mail()
$b is (array) , params to mail()
'to'
'subject'
'body'
'headers'
A complete list of all hook callbacks with file locations (generated 14-Feb-2012): Please see the source for details of any hooks not documented above. A complete list of all hook callbacks with file locations (generated 14-Feb-2012): Please see the source for details of any hooks not documented above.

View file

@ -14,9 +14,12 @@ class Emailer {
* @param htmlVersion html version of the message * @param htmlVersion html version of the message
* @param textVersion text only version of the message * @param textVersion text only version of the message
* @param additionalMailHeader additions to the smtp mail header * @param additionalMailHeader additions to the smtp mail header
* @param optional uid user id of the destination user
*/ */
static public function send($params) { static public function send($params) {
call_hooks('emailer_send_prepare', $params);
$fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8'); $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
$messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8'); $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
@ -49,11 +52,18 @@ class Emailer {
"--" . $mimeBoundary . "--\n"; // message ending "--" . $mimeBoundary . "--\n"; // message ending
// send the message // send the message
$hookdata = array(
'to' => $params['toEmail'],
'subject' => $messageSubject,
'body' => $multipartMessageBody,
'headers' => $messageHeader
);
call_hooks("emailer_send", $hookdata);
$res = mail( $res = mail(
$params['toEmail'], // send to address $hookdata['to'], // send to address
$messageSubject, // subject $hookdata['subject'], // subject
$multipartMessageBody, // message body $hookdata['body'], // message body
$messageHeader // message headers $hookdata['headers'], // message headers
); );
logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG); logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG); logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);

View file

@ -598,6 +598,7 @@ function notification($params) {
// use the Emailer class to send the message // use the Emailer class to send the message
return Emailer::send(array( return Emailer::send(array(
'uid' => $params['uid'],
'fromName' => $sender_name, 'fromName' => $sender_name,
'fromEmail' => $sender_email, 'fromEmail' => $sender_email,
'replyTo' => $sender_email, 'replyTo' => $sender_email,