From 6a8030fd76f154097b4aa4acbfcec5465fb1aece Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Nov 2021 09:19:12 +0300 Subject: mailer: don't crash if php mail() fails with no reported errors --- classes/mailer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/mailer.php b/classes/mailer.php index 339b2895a..60b1ce4fd 100644 --- a/classes/mailer.php +++ b/classes/mailer.php @@ -31,6 +31,8 @@ class Mailer { // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function // 4. set error message if needed via passed Mailer instance function set_error() + $hooks_tried = 0; + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { $rc = $p->hook_send_mail($this, $params); @@ -39,6 +41,8 @@ class Mailer { if ($rc == -1) return 0; + + ++$hooks_tried; } $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; @@ -46,7 +50,7 @@ class Mailer { $rc = mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); if (!$rc) { - $this->set_error(error_get_last()['message']); + $this->set_error(error_get_last()['message'] ?? T_sprintf("Unknown error while sending mail. Hooks tried: %d.", $hooks_tried)); } return $rc; -- cgit v1.2.3