Unify the various mail sending instance to enotify::send() and z_mail(). Both take the same arguments. z_mail() is text only, enotify::send() provides html and text. Both are pluggable using the enotfy_send hook.

This commit is contained in:
redmatrix 2016-10-01 03:06:01 -07:00
parent ad309f1036
commit fa94644bcf
6 changed files with 4886 additions and 4789 deletions

View File

@ -71,9 +71,21 @@ class Enotify {
// Do not translate 'noreply' as it must be a legal 7-bit email address
$sender_email = get_config('system','reply_address');
$reply_email = get_config('system','reply_address');
if(! $reply_email)
$reply_email = 'noreply' . '@' . $hostname;
$sender_email = get_config('system','from_email');
if(! $sender_email)
$sender_email = 'noreply' . '@' . $hostname;
$sender_email = 'Administrator' . '@' . App::get_hostname();
$sender_name = get_config('system','from_email_name');
if(! $sender_name)
$sender_name = Zotlabs\Lib\System::get_site_name();
$additional_mail_header = "";
@ -586,7 +598,7 @@ class Enotify {
self::send(array(
'fromName' => $sender_name,
'fromEmail' => $sender_email,
'replyTo' => $sender_email,
'replyTo' => $reply_email,
'toEmail' => $recip['account_email'],
'messageSubject' => $datarray['subject'],
'htmlVersion' => $email_html_body,

View File

@ -59,12 +59,15 @@ class Invite extends \Zotlabs\Web\Controller {
$account = \App::get_account();
$res = mail($recip, sprintf( t('Please join us on $Projectname'), \App::$config['sitename']),
$nmessage,
"From: " . $account['account_email'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
$res = z_mail(
[
'toEmail' => $recip,
'fromName' => ' ',
'fromEmail' => $account['account_email'],
'messageSubject' => t('Please join us on $Projectname'),
'textVersion' => $nmessage,
]
);
if($res) {
$total ++;

View File

@ -43,18 +43,19 @@ class Lostpass extends \Zotlabs\Web\Controller {
$subject = email_header_encode(sprintf( t('Password reset requested at %s'),get_config('system','sitename')), 'UTF-8');
$res = mail($email, $subject ,
$message,
'From: Administrator@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
$res = z_mail(
[
'toEmail' => $email,
'messageSubject' => sprintf( t('Password reset requested at %s'), get_config('system','sitename')),
'textVersion' => $message,
]
);
goaway(z_root());
}
function get() {
function get() {
if(x($_GET,'verify')) {
@ -102,19 +103,21 @@ class Lostpass extends \Zotlabs\Web\Controller {
$email_tpl = get_intltext_template("passchanged_eml.tpl");
$message = replace_macros($email_tpl, array(
'$sitename' => \App::$config['sitename'],
'$siteurl' => z_root(),
'$username' => sprintf( t('Site Member (%s)'), $email),
'$email' => $email,
'$new_password' => $new_password,
'$uid' => $newuid ));
'$sitename' => \App::$config['sitename'],
'$siteurl' => z_root(),
'$username' => sprintf( t('Site Member (%s)'), $email),
'$email' => $email,
'$new_password' => $new_password,
'$uid' => $newuid )
);
$subject = email_header_encode( sprintf( t('Your password has changed at %s'), get_config('system','sitename')), 'UTF-8');
$res = mail($email,$subject,$message,
'From: ' . 'Administrator@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
$res = z_mail(
[
'toEmail' => $email,
'messageSubject' => sprintf( t('Your password has changed at %s'), get_config('system','sitename')),
'textVersion' => $message,
]
);
return $o;
}

View File

@ -246,20 +246,23 @@ function verify_email_address($arr) {
dbesc($arr['account']['account_language'])
);
//@fixme - get correct language template
$email_msg = replace_macros(get_intltext_template('register_verify_member.tpl'), array(
'$sitename' => get_config('system','sitename'),
'$siteurl' => z_root(),
'$siteurl' => z_root(),
'$email' => $arr['email'],
'$uid' => $arr['account']['account_id'],
'$hash' => $hash,
'$details' => $details
));
$res = mail($arr['email'], email_header_encode(sprintf( t('Registration confirmation for %s'), get_config('system','sitename'))),
$email_msg,
'From: ' . 'Administrator' . '@' . App::get_hostname() . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit'
$res = z_mail(
[
'toEmail' => $arr['email'],
'messageSubject' => sprintf( t('Registration confirmation for %s'), get_config('system','sitename')),
'textVersion' => $email_msg,
]
);
if($res)
@ -321,11 +324,12 @@ function send_reg_approval_email($arr) {
'$details' => $details
));
$res = mail($admin['email'], sprintf( t('Registration request at %s'), get_config('system','sitename')),
$email_msg,
'From: ' . t('Administrator') . '@' . App::get_hostname() . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit'
$res = z_mail(
[
'toEmail' => $admin['email'],
'messageSubject' => sprintf( t('Registration request at %s'), get_config('system','sitename')),
'textVersion' => $email_msg,
]
);
if($res)
@ -348,12 +352,14 @@ function send_register_success_email($email,$password) {
'$password' => t('your registration password'),
));
$res = mail($email, sprintf( t('Registration details for %s'), get_config('system','sitename')),
$email_msg,
'From: ' . t('Administrator') . '@' . App::get_hostname() . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit'
$res = z_mail(
[
'toEmail' => $email,
'messageSubject' => sprintf( t('Registration details for %s'), get_config('system','sitename')),
'textVersion' => $email_msg,
]
);
return($res ? true : false);
}
@ -399,7 +405,7 @@ function account_allow($hash) {
push_lang($register[0]['lang']);
$email_tpl = get_intltext_template("register_open_eml.tpl");
$email_tpl = replace_macros($email_tpl, array(
$email_msg = replace_macros($email_tpl, array(
'$sitename' => get_config('system','sitename'),
'$siteurl' => z_root(),
'$username' => $account[0]['account_email'],
@ -408,11 +414,13 @@ function account_allow($hash) {
'$uid' => $account[0]['account_id']
));
$res = mail($account[0]['account_email'], sprintf( t('Registration details for %s'), get_config('system','sitename')),
$email_tpl,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
$res = z_mail(
[
'toEmail' => $account[0]['account_email'],
'messageSubject' => sprintf( t('Registration details for %s'), get_config('system','sitename')),
'textVersion' => $email_msg,
]
);
pop_lang();

View File

@ -2226,3 +2226,65 @@ function network_to_name($s) {
return str_replace($search,$replace,$s);
}
function z_mail($params) {
/**
* @brief Send a text email message
*
* @param array $params an assoziative array with:
* * \e string \b fromName name of the sender
* * \e string \b fromEmail email of the sender
* * \e string \b replyTo replyTo address to direct responses
* * \e string \b toEmail destination email address
* * \e string \b messageSubject subject of the message
* * \e string \b htmlVersion html version of the message
* * \e string \b textVersion text only version of the message
* * \e string \b additionalMailHeader additions to the smtp mail header
*/
if(! $params['fromEmail']) {
$params['fromEmail'] = get_config('system','from_email');
if(! $params['fromEmail'])
$params['fromEmail'] = 'Administrator' . '@' . App::get_hostname();
}
if(! $params['fromName']) {
$params['fromName'] = get_config('system','from_email_name');
if(! $params['fromName'])
$params['fromName'] = Zotlabs\Lib\System::get_site_name();
}
if(! $params['replyTo']) {
$params['replyTo'] = get_config('system','reply_address');
if(! $params['replyTo'])
$params['replyTo'] = 'noreply' . '@' . App::get_hostname();
}
$params['sent'] = false;
$params['result'] = false;
call_hooks('enotify_send', $params);
if($params['sent']) {
logger('notification: z_mail returns ' . $params['result'], LOGGER_DEBUG);
return $params['result'];
}
$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');
$messageHeader =
$params['additionalMailHeader'] .
"From: $fromName <{$params['fromEmail']}>\n" .
"Reply-To: $fromName <{$params['replyTo']}>";
// send the message
$res = mail(
$params['toEmail'], // send to address
$messageSubject, // subject
$params['textVersion'],
$messageHeader // message headers
);
logger('notification: z_mail returns ' . $res, LOGGER_DEBUG);
return $res;
}

File diff suppressed because it is too large Load Diff