From 4535687b48692ab70e91a5a4540769f87853c662 Mon Sep 17 00:00:00 2001 From: slawkens1 Date: Tue, 26 Dec 2017 22:30:52 +0100 Subject: [PATCH] * automatically generate plain mail from html --- config.php | 2 +- system/functions.php | 9 ++++++--- system/pages/createaccount.php | 9 +-------- system/templates/mail.account.verify.plain.html.twig | 11 ----------- 4 files changed, 8 insertions(+), 23 deletions(-) delete mode 100644 system/templates/mail.account.verify.plain.html.twig diff --git a/config.php b/config.php index cf00ef97..d49e743c 100644 --- a/config.php +++ b/config.php @@ -98,7 +98,7 @@ $config = array( 'mail_address' => 'no-reply@your-server.org', // server e-mail address (from:) 'mail_admin' => 'your-address@your-server.org', // admin email address, where mails from contact form will be sent 'mail_signature' => array( // signature that will be included at the end of every message sent using _mail function - 'plain' => ''/*'--\nMy Server,\nhttp://www.myserver.com'*/, + 'plain' => ""/*"--\nMy Server,\nhttp://www.myserver.com"*/, 'html' => ''/*'
My Server,\nmyserver.com'*/ ), 'smtp_enabled' => false, // send by smtp or mail function (set false if use mail function) diff --git a/system/functions.php b/system/functions.php index 8cb6f2b0..3111d314 100644 --- a/system/functions.php +++ b/system/functions.php @@ -816,9 +816,9 @@ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true) $signature_html = $config['mail_signature']['html']; if($add_html_tags && isset($body[0])) - $body = '' . $body . '

' . $signature_html . ''; + $tmp_body = '' . $body . '

' . $signature_html . ''; else - $body .= '

' . $signature_html; + $tmp_body .= '

' . $signature_html; if($config['smtp_enabled']) { @@ -839,7 +839,7 @@ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true) $mailer->FromName = $config['lua']['serverName']; $mailer->Subject = $subject; $mailer->AddAddress($to); - $mailer->Body = $body; + $mailer->Body = $tmp_body; $signature_plain = ''; if(isset($config['mail_signature']['plain'])) @@ -847,6 +847,9 @@ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true) if(isset($altBody[0])) $mailer->AltBody = $altBody . $signature_plain; + else { // automatically generate plain html + $mailer->AltBody = strip_tags(preg_replace('//','$2', $body)) . "\n" . $signature_plain; + } return $mailer->Send(); } diff --git a/system/pages/createaccount.php b/system/pages/createaccount.php index 1a45cc7d..883d017c 100644 --- a/system/pages/createaccount.php +++ b/system/pages/createaccount.php @@ -159,19 +159,12 @@ if($save) $new_account->setCustomField('email_hash', $hash); $verify_url = getLink('account/confirm_email/' . $hash); - $server_name = $config['lua']['serverName']; - - $body_plain = $twig->render('mail.account.verify.plain.html.twig', array( - 'account' => $tmp_account, - 'verify_url' => $verify_url - )); - $body_html = $twig->render('mail.account.verify.html.twig', array( 'account' => $tmp_account, 'verify_url' => generateLink($verify_url, $verify_url, true) )); - if(_mail($email, 'New account on ' . $config['lua']['serverName'], $body_html, $body_plain)) + if(_mail($email, 'New account on ' . $config['lua']['serverName'], $body_html)) { echo $twig->render('account.created.verify.html.twig', array( 'account' => $tmp_account diff --git a/system/templates/mail.account.verify.plain.html.twig b/system/templates/mail.account.verify.plain.html.twig deleted file mode 100644 index 2605ccde..00000000 --- a/system/templates/mail.account.verify.plain.html.twig +++ /dev/null @@ -1,11 +0,0 @@ -Hello! - -Thank you for registering on {{ config.lua.serverName }}! - -Here are the details of your account: -Account {% if constant('USE_ACCOUNT_NAME') %}Name{% else %}Number{% endif %}: {{ account }} -Password: ************ (hidden for security reasons) - -To verify your email address please click the link below: -{{ verify_url }} -If you haven't registered on {{ config.lua.serverName }} please ignore this email. \ No newline at end of file