From c5727ca89ac3d4952cac5af50c6b8c232c9b8c83 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 22 Jun 2022 08:15:30 +1200 Subject: [PATCH] dev/core#2866 ignore preferred_mail_format, send both --- CRM/Core/BAO/ActionSchedule.php | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 904120a64b..d56afbe689 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -585,22 +585,20 @@ FROM civicrm_action_schedule cas } /** + * Send the reminder email. + * * @param \Civi\Token\TokenRow $tokenRow * @param CRM_Core_DAO_ActionSchedule $schedule * @param int $toContactID + * * @return array * List of error messages. + * @throws \CRM_Core_Exception */ protected static function sendReminderEmail($tokenRow, $schedule, $toContactID): array { $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($toContactID, TRUE); if (!$toEmail) { - return ["email_missing" => "Couldn't find recipient's email address."]; - } - - $body_text = $tokenRow->render('body_text'); - $body_html = $tokenRow->render('body_html'); - if (!$schedule->body_text) { - $body_text = CRM_Utils_String::htmlToText($body_html); + return ['email_missing' => "Couldn't find recipient's email address."]; } // set up the parameters for CRM_Utils_Mail::send @@ -613,19 +611,16 @@ FROM civicrm_action_schedule cas 'entity' => 'action_schedule', 'entity_id' => $schedule->id, ]; - - $preferredMailFormat = $tokenRow->render('preferred_mail_format'); - if (!$body_html || $preferredMailFormat === 'Text' || $preferredMailFormat === 'Both' - ) { - // render the & entities in text mode, so that the links work - $mailParams['text'] = str_replace('&', '&', $body_text); - } - if ($body_html && ($tokenRow->context['contact']['preferred_mail_format'] === 'HTML' || - $tokenRow->context['contact']['preferred_mail_format'] === 'Both' - ) - ) { - $mailParams['html'] = $body_html; + $body_text = $tokenRow->render('body_text'); + $mailParams['html'] = $tokenRow->render('body_html'); + // todo - remove these lines for body_text as there is similar handling in + // CRM_Utils_Mail::send() + if (!$schedule->body_text) { + $body_text = CRM_Utils_String::htmlToText($mailParams['html']); } + // render the & entities in text mode, so that the links work + $mailParams['text'] = str_replace('&', '&', $body_text); + $result = CRM_Utils_Mail::send($mailParams); if (!$result) { return ['email_fail' => 'Failed to send message']; -- 2.25.1