Enable and catch exceptions for PHPMailer to gather error messages. (#9132)

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
Mark Nagel
2018-09-02 15:45:39 -07:00
committed by Neil Lathwood
parent 0f0ae34d77
commit 9311c75a49

View File

@@ -1042,7 +1042,8 @@ function send_mail($emails, $subject, $message, $html = false)
global $config;
if (is_array($emails) || ($emails = parse_email($emails))) {
d_echo("Attempting to email $subject to: " . implode('; ', array_keys($emails)) . PHP_EOL);
$mail = new PHPMailer();
$mail = new PHPMailer(true);
try {
$mail->Hostname = php_uname('n');
foreach (parse_email($config['email_from']) as $from => $from_name) {
@@ -1080,7 +1081,13 @@ function send_mail($emails, $subject, $message, $html = false)
$mail->Mailer = 'mail';
break;
}
return $mail->send() ? true : $mail->ErrorInfo;
$mail->send();
return true;
} catch (phpmailerException $e) {
return $e->errorMessage();
} catch (Exception $e) {
return $e->getMessage();
}
}
return "No contacts found";