From 38ca3dc582535bb918353a91ae345682546aa270 Mon Sep 17 00:00:00 2001 From: M Somerville Date: Mon, 18 Oct 2021 17:27:13 +0100 Subject: [PATCH] Add HTML email support to alert emails. --- scripts/alertmailer.php | 55 ++++-- .../templates/emails/alert_mailout.html | 162 ++++++++++++++++++ .../templates/emails/alert_mailout.txt | 2 +- .../emails/images/logo-mysociety.svg | 1 + .../emails/images/mySociety-logo.png | Bin 0 -> 14299 bytes .../emails/images/theyworkforyou-logo.png | Bin 0 -> 8387 bytes www/includes/utility.php | 53 ++++-- 7 files changed, 238 insertions(+), 35 deletions(-) create mode 100644 www/includes/easyparliament/templates/emails/alert_mailout.html create mode 100644 www/includes/easyparliament/templates/emails/images/logo-mysociety.svg create mode 100644 www/includes/easyparliament/templates/emails/images/mySociety-logo.png create mode 100644 www/includes/easyparliament/templates/emails/images/theyworkforyou-logo.png diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index a54d2b452f..6218e70a43 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -102,6 +102,7 @@ function mlog($message) { $current = array('email' => '', 'token' => ''); $email_text = ''; +$html_text = ''; $globalsuccess = 1; # Fetch all confirmed, non-deleted alerts @@ -178,11 +179,12 @@ function mlog($message) { if ($email != $current['email']) { if ($email_text) { - write_and_send_email($current, $email_text, $template); + write_and_send_email($current, $email_text, $html_text, $template); } $current['email'] = $email; $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; $email_text = ''; + $html_text = ''; $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( ':email' => $email ))->first(); @@ -253,7 +255,7 @@ function mlog($message) { } else { $text .= "$vote$teller"; } - $text .= " (division #$num; result was " . $row['yes_total'] . ' aye, ' . $row['no_total'] . ' no)'; + $text .= " (division #$num; result was " . $row['yes_total'] . ' aye, ' . $row['no_total'] . ' no)'; $data['rows'][] = [ 'parent' => [ 'body' => $row['division_title'], @@ -275,7 +277,7 @@ function mlog($message) { if ($major !== $row['major']) { $count[$major] = $total; $total = 0; $major = $row['major']; - $o[$major] = ''; + $o[$major] = ['text' => '', 'html' => '']; $k = 3; } #mlog($row['major'] . " " . $row['gid'] ."\n"); @@ -302,38 +304,52 @@ function mlog($message) { if ($major == 'V' || $k >= 0) { $any_content = true; $parentbody = text_html_to_email($row['parent']['body']); - $body = text_html_to_email($row['extract']); + $body_text = text_html_to_email($row['extract']); + $body_html = $row['extract']; if (isset($row['speaker']) && count($row['speaker'])) { - $body = $row['speaker']['name'] . ': ' . $body; + $body_text = $row['speaker']['name'] . ': ' . $body_text; + $body_html = '' . $row['speaker']['name'] . ': ' . $body_html; } + $body_html = '

' . $body_html . '

'; - $body = wordwrap($body, 72); - $o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n"; - $o[$major] .= $body . "\n\n"; + $body_text = wordwrap($body_text, 72); + $o[$major]['text'] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n"; + $o[$major]['text'] .= $body_text . "\n\n"; + $o[$major]['html'] .= '

' . $parentbody . '

' . format_date($row['hdate'], SHORTDATEFORMAT) . ''; + $o[$major]['html'] .= $body_html . "\n\n"; } $total++; } $count[$major] = $total; if ($any_content) { - # Add data to email_text + # Add data to email_text/html_text $desc = trim(html_entity_decode($data['searchdescription'])); $desc = trim(preg_replace(['#\(B\d+( OR B\d+)*\)#', '#B\d+( OR B\d+)*#'], '', $desc)); foreach ($o as $major => $body) { - if ($body) { - $heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major] != 1 ? 's' : ''); - $email_text .= "$heading\n" . str_repeat('=', strlen($heading)) . "\n\n"; + if ($body['text']) { + $heading_text = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major] != 1 ? 's' : ''); + $heading_html = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major] != 1 ? 's' : ''); + + $email_text .= "$heading_text\n" . str_repeat('=', strlen($heading_text)) . "\n\n"; if ($count[$major] > 3 && $major != 'V') { $email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=" . urlencode($criteria_raw) . "+section:" . $sects_search[$major] . "&o=d\n\n"; } - $email_text .= $body; + $email_text .= $body['text']; + + $html_text .= '
'; + $html_text .= '

' . $heading_html . '

'; + if ($count[$major] > 3 && $major != 'V') { + $html_text .= '

There are more results than we have shown here. See more

'; + } + $html_text .= $body['html']; } } } } } if ($email_text) { - write_and_send_email($current, $email_text, $template); + write_and_send_email($current, $email_text, $html_text, $template); } mlog("\n"); @@ -402,15 +418,16 @@ function sort_by_stuff($a, $b) { return ($a['hpos'] > $b['hpos']) ? 1 : -1; } -function write_and_send_email($current, $data, $template) { +function write_and_send_email($current, $text, $html, $template) { global $globalsuccess, $sentemails, $nomail, $start_time; - $data .= '===================='; + $text .= '===================='; $sentemails++; mlog("SEND $sentemails : Sending email to $current[email] ... "); $d = array('to' => $current['email'], 'template' => $template); $m = array( - 'DATA' => $data, + 'DATA' => $text, + '_HTML_' => $html, 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], ); if (!$nomail) { @@ -423,7 +440,7 @@ function write_and_send_email($current, $data, $template) { sleep(1); } } else { - mlog($data); + mlog($text); $success = 1; } mlog("done\n"); @@ -433,7 +450,7 @@ function write_and_send_email($current, $data, $template) { } function text_html_to_email($s) { - $s = preg_replace('##', '', $s); + $s = preg_replace('##', '', $s); $s = preg_replace('#]*>#', '*', $s); $s = str_replace( array('£', '–', '—', '’', '
'), diff --git a/www/includes/easyparliament/templates/emails/alert_mailout.html b/www/includes/easyparliament/templates/emails/alert_mailout.html new file mode 100644 index 0000000000..479ce32fa9 --- /dev/null +++ b/www/includes/easyparliament/templates/emails/alert_mailout.html @@ -0,0 +1,162 @@ + + + + Your TheyWorkForYou email alert + + + + + + + + + + +
+ +
+ + + +

Email alerts

+
+ +
+ + {_HTML_} + +
+ +

Best wishes,
TheyWorkForYou

+ +

+ mySociety,
+ 483 Green Lanes,
+ London,
+ N13 4BS,
+ United Kingdom +

+ +
+

Help keep TheyWorkForYou running

+

Please consider donating to mySociety to help us continue and expand:

+ +
+ Donate +
+
+ +
+ +
+ + + +
+ + + diff --git a/www/includes/easyparliament/templates/emails/alert_mailout.txt b/www/includes/easyparliament/templates/emails/alert_mailout.txt index b6325bf159..2c0ec7b071 100644 --- a/www/includes/easyparliament/templates/emails/alert_mailout.txt +++ b/www/includes/easyparliament/templates/emails/alert_mailout.txt @@ -22,5 +22,5 @@ continue and expand: https://www.mysociety.org/twfy-donate/ ------------------------------------------------------------------- -To manage, unsubscribe or add to your alerts, please visit the following link: +To unsubscribe, manage or add to your alerts, please visit the following link: {MANAGE} diff --git a/www/includes/easyparliament/templates/emails/images/logo-mysociety.svg b/www/includes/easyparliament/templates/emails/images/logo-mysociety.svg new file mode 100644 index 0000000000..eaa329c29e --- /dev/null +++ b/www/includes/easyparliament/templates/emails/images/logo-mysociety.svg @@ -0,0 +1 @@ +mysociety-logo-grey \ No newline at end of file diff --git a/www/includes/easyparliament/templates/emails/images/mySociety-logo.png b/www/includes/easyparliament/templates/emails/images/mySociety-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..4544be1b9138c9ec0dbf7743fc68223f8d8c0dfa GIT binary patch literal 14299 zcmbWeRZwM3ur-J@(ntf1yEP66cXx-z-QC^Y9h%17-QC^Y8;64)++Bz7&fIyJi2r3C zDt1=wtf+|Eu`_b5l^O9{P8<;q2M!Dj3{g@-L=g-O9Pnj3!$N;qGGv!mUlVXAMR6gp z>S?^=uZf6>x}>SBEEx5d4GRVyW&!r?KbNn8^EJT0AalXNAitjA|E=Xh{O?zwGt<08WfJ0Vh*@ z9|VA0G3>|oy6vl!;(_4HV*5`eEssr^CdB7ql>VS z#^q%BI%mpN=C43>L$Sb8GhOiH#3^{|()~CAtdKV7O#HQRV^M34nf@L& zrqoA*5<&l3M(dDI1uTv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gCHs82Gv7gcJZ_7%{YZnbj!C}^@U@8Q# zW^(K#v|4%pl==^Z3*oQw09Txaw$l&*UG*yxC6G`MyQT+|`$c;sBKZHXrSlmjMPu!F U(}(KAzaI#c0P1oTG8Uo#1?$`|+yDRo literal 0 HcmV?d00001 diff --git a/www/includes/utility.php b/www/includes/utility.php index 69a1c2642b..eba7d22043 100644 --- a/www/includes/utility.php +++ b/www/includes/utility.php @@ -7,6 +7,7 @@ include_once INCLUDESPATH . '../../commonlib/phplib/email.php'; include_once INCLUDESPATH . '../../commonlib/phplib/datetime.php'; +use PHPMailer\PHPMailer\PHPMailer; # Pass it a brief header word and some debug text and it'll be output. # If TEXT is an array, call the user function, assuming it's a class. @@ -701,6 +702,13 @@ function send_template_email($data, $merge, $bulk = false, $want_bounces = false $emailtext = fread($handle, filesize($filename)); fclose($handle); + $filename = INCLUDESPATH . "easyparliament/templates/emails/" . $data['template'] . ".html"; + if (file_exists($filename)) { + $htmltext = file_get_contents($filename); + } else { + $htmltext = ''; + } + // See if there's a default subject in the template. $firstline = substr($emailtext, 0, strpos($emailtext, "\n")); @@ -733,9 +741,10 @@ function send_template_email($data, $merge, $bulk = false, $want_bounces = false } $emailtext = preg_replace($search, $replace, $emailtext); + $htmltext = preg_replace($search, $replace, $htmltext); // Send it! - $success = send_email ($data['to'], $subject, $emailtext, $bulk, 'twfy-DO-NOT-REPLY@' . EMAILDOMAIN, $want_bounces); + $success = send_email ($data['to'], $subject, $emailtext, $bulk, 'twfy-DO-NOT-REPLY@' . EMAILDOMAIN, $want_bounces, $htmltext); return $success; @@ -750,30 +759,44 @@ function twfy_verp_envelope_sender($recipient) { return $envelope_sender; } -function send_email($to, $subject, $message, $bulk = false, $from = '', $want_bounces = false) { +function send_email($to, $subject, $message, $bulk = false, $from = '', $want_bounces = false, $html='') { // Use this rather than PHP's mail() direct, so we can make alterations // easily to all the emails we send out from the site. // eg, we might want to add a .sig to everything here... if (!$from) $from = CONTACTEMAIL; - $headers = - "From: TheyWorkForYou <$from>\r\n" . - "Content-Type: text/plain; charset=utf-8\r\n" . - "MIME-Version: 1.0\r\n" . - "Content-Transfer-Encoding: 8bit\r\n" . - ($bulk ? "Precedence: bulk\r\nAuto-Submitted: auto-generated\r\n" : "" ). - "X-Mailer: PHP/" . phpversion(); - twfy_debug('EMAIL', "Sending email to $to with subject of '$subject'"); + $mail = new PHPMailer(true); + $mail->isSMTP(); + $mail->SMTPAutoTLS = false; + $mail->setFrom($from, 'TheyWorkForYou'); + $mail->addAddress($to); + $mail->Subject = $subject; + $mail->CharSet = 'utf-8'; + + if ($html) { + $mail->msgHTML($html, INCLUDESPATH . 'easyparliament/templates/emails'); + $mail->AltBody = $message; + } else { + $mail->Body = $message; + } + + if ($bulk) { + $mail->addCustomHeader('Precedence', 'bulk'); + $mail->addCustomHeader('Auto-Submitted', 'auto-generated'); + } if ($want_bounces) { - $envelope_sender = twfy_verp_envelope_sender($to); - $success = mail ($to, $subject, $message, $headers, '-f ' . $envelope_sender); - } else { - $success = mail ($to, $subject, $message, $headers); + $mail->Sender = twfy_verp_envelope_sender($to); } - return $success; + twfy_debug('EMAIL', "Sending email to $to with subject of '$subject'"); + try { + $mail->send(); + return true; + } catch (Exception $e) { + return false; + } }