mailer: don't crash if php mail() fails with no reported errors

This commit is contained in:
Andrew Dolgov 2021-11-16 09:19:12 +03:00
parent b2952843f5
commit 6a8030fd76
1 changed files with 5 additions and 1 deletions

View File

@ -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;