diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/account.php | 52 | ||||
-rw-r--r-- | include/network.php | 62 |
2 files changed, 92 insertions, 22 deletions
diff --git a/include/account.php b/include/account.php index bd4da6a52..b78c3e56d 100644 --- a/include/account.php +++ b/include/account.php @@ -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(); diff --git a/include/network.php b/include/network.php index d8e662083..15157fdf0 100644 --- a/include/network.php +++ b/include/network.php @@ -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; +} |