summaryrefslogtreecommitdiff
path: root/classes/mailer.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-11-16 09:19:12 +0300
committerAndrew Dolgov <[email protected]>2021-11-16 09:19:12 +0300
commit6a8030fd76f154097b4aa4acbfcec5465fb1aece (patch)
tree6ecb58b4545df785d5dcdbf8de144f1e124e5b76 /classes/mailer.php
parentb2952843f50c7b5d2e8aafd62fadb4674acc59b1 (diff)
mailer: don't crash if php mail() fails with no reported errors
Diffstat (limited to 'classes/mailer.php')
-rw-r--r--classes/mailer.php6
1 files changed, 5 insertions, 1 deletions
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;