From: Matthew Wire Date: Wed, 18 Aug 2021 13:46:38 +0000 (+0100) Subject: Log details of mailing error and don't display details to end user X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=867052dcd145fe470ef936b65d38e0a6a382fe70;p=civicrm-core.git Log details of mailing error and don't display details to end user --- diff --git a/CRM/Utils/Mail.php b/CRM/Utils/Mail.php index 9a21b4b9de..060ff42c9f 100644 --- a/CRM/Utils/Mail.php +++ b/CRM/Utils/Mail.php @@ -305,14 +305,16 @@ class CRM_Utils_Mail { $result = $mailer->send($to, $headers, $message); } catch (Exception $e) { - CRM_Core_Session::setStatus($e->getMessage(), ts('Mailing Error'), 'error'); + \Civi::log()->error('Mailing error: ' . $e->getMessage()); + CRM_Core_Session::setStatus(ts('Unable to send email. Please report this message to the site administrator'), ts('Mailing Error'), 'error'); return FALSE; } if (is_a($result, 'PEAR_Error')) { $message = self::errorMessage($mailer, $result); // append error message in case multiple calls are being made to // this method in the course of sending a batch of messages. - CRM_Core_Session::setStatus($message, ts('Mailing Error'), 'error'); + \Civi::log()->error('Mailing error: ' . $message); + CRM_Core_Session::setStatus(ts('Unable to send email. Please report this message to the site administrator'), ts('Mailing Error'), 'error'); return FALSE; } // CRM-10699 diff --git a/tests/phpunit/CRM/Utils/MailTest.php b/tests/phpunit/CRM/Utils/MailTest.php index a70cfc5436..d1c6200703 100644 --- a/tests/phpunit/CRM/Utils/MailTest.php +++ b/tests/phpunit/CRM/Utils/MailTest.php @@ -69,7 +69,7 @@ class CRM_Utils_MailTest extends CiviUnitTestCase { ]); $this->assertFalse(CRM_Utils_Mail::send($params)); - $this->assertEquals('You shall not pass', CRM_Core_Session::singleton()->getStatus()[0]['text']); + $this->assertEquals('Unable to send email. Please report this message to the site administrator', CRM_Core_Session::singleton()->getStatus()[0]['text']); } /**