From dcbf2f6871de7cd26815334b6977792e2b2f31df Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 15 Sep 2011 16:52:23 -0700 Subject: [PATCH] Better error handling when the email subsystem isn't working. The installer was dying trying to send a confirmation email to the initial user. --- lib/mail.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/mail.php b/lib/mail.php index 3f8a08f3ca..c93464a586 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -71,18 +71,25 @@ function mail_backend() */ function mail_send($recipients, $headers, $body) { - // XXX: use Mail_Queue... maybe - $backend = mail_backend(); - if (!isset($headers['Content-Type'])) { - $headers['Content-Type'] = 'text/plain; charset=UTF-8'; - } - assert($backend); // throws an error if it's bad - $sent = $backend->send($recipients, $headers, $body); - if (PEAR::isError($sent)) { - common_log(LOG_ERR, 'Email error: ' . $sent->getMessage()); + try { + // XXX: use Mail_Queue... maybe + $backend = mail_backend(); + + if (!isset($headers['Content-Type'])) { + $headers['Content-Type'] = 'text/plain; charset=UTF-8'; + } + + assert($backend); // throws an error if it's bad + $sent = $backend->send($recipients, $headers, $body); + return true; + } catch (PEAR_Exception $e) { + common_log( + LOG_ERR, + "Unable to send email - '{$e->getMessage()}'. " + . 'Is your mail subsystem set up correctly?' + ); return false; } - return true; } /** -- 2.39.5