mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
committed by
Neil Lathwood
parent
0f0ae34d77
commit
9311c75a49
@@ -1042,45 +1042,52 @@ 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->Hostname = php_uname('n');
|
||||
$mail = new PHPMailer(true);
|
||||
try {
|
||||
$mail->Hostname = php_uname('n');
|
||||
|
||||
foreach (parse_email($config['email_from']) as $from => $from_name) {
|
||||
$mail->setFrom($from, $from_name);
|
||||
foreach (parse_email($config['email_from']) as $from => $from_name) {
|
||||
$mail->setFrom($from, $from_name);
|
||||
}
|
||||
foreach ($emails as $email => $email_name) {
|
||||
$mail->addAddress($email, $email_name);
|
||||
}
|
||||
$mail->Subject = $subject;
|
||||
$mail->XMailer = $config['project_name_version'];
|
||||
$mail->CharSet = 'utf-8';
|
||||
$mail->WordWrap = 76;
|
||||
$mail->Body = $message;
|
||||
if ($html) {
|
||||
$mail->isHTML(true);
|
||||
}
|
||||
switch (strtolower(trim($config['email_backend']))) {
|
||||
case 'sendmail':
|
||||
$mail->Mailer = 'sendmail';
|
||||
$mail->Sendmail = $config['email_sendmail_path'];
|
||||
break;
|
||||
case 'smtp':
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $config['email_smtp_host'];
|
||||
$mail->Timeout = $config['email_smtp_timeout'];
|
||||
$mail->SMTPAuth = $config['email_smtp_auth'];
|
||||
$mail->SMTPSecure = $config['email_smtp_secure'];
|
||||
$mail->Port = $config['email_smtp_port'];
|
||||
$mail->Username = $config['email_smtp_username'];
|
||||
$mail->Password = $config['email_smtp_password'];
|
||||
$mail->SMTPAutoTLS= $config['email_auto_tls'];
|
||||
$mail->SMTPDebug = false;
|
||||
break;
|
||||
default:
|
||||
$mail->Mailer = 'mail';
|
||||
break;
|
||||
}
|
||||
$mail->send();
|
||||
return true;
|
||||
} catch (phpmailerException $e) {
|
||||
return $e->errorMessage();
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
foreach ($emails as $email => $email_name) {
|
||||
$mail->addAddress($email, $email_name);
|
||||
}
|
||||
$mail->Subject = $subject;
|
||||
$mail->XMailer = $config['project_name_version'];
|
||||
$mail->CharSet = 'utf-8';
|
||||
$mail->WordWrap = 76;
|
||||
$mail->Body = $message;
|
||||
if ($html) {
|
||||
$mail->isHTML(true);
|
||||
}
|
||||
switch (strtolower(trim($config['email_backend']))) {
|
||||
case 'sendmail':
|
||||
$mail->Mailer = 'sendmail';
|
||||
$mail->Sendmail = $config['email_sendmail_path'];
|
||||
break;
|
||||
case 'smtp':
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $config['email_smtp_host'];
|
||||
$mail->Timeout = $config['email_smtp_timeout'];
|
||||
$mail->SMTPAuth = $config['email_smtp_auth'];
|
||||
$mail->SMTPSecure = $config['email_smtp_secure'];
|
||||
$mail->Port = $config['email_smtp_port'];
|
||||
$mail->Username = $config['email_smtp_username'];
|
||||
$mail->Password = $config['email_smtp_password'];
|
||||
$mail->SMTPAutoTLS= $config['email_auto_tls'];
|
||||
$mail->SMTPDebug = false;
|
||||
break;
|
||||
default:
|
||||
$mail->Mailer = 'mail';
|
||||
break;
|
||||
}
|
||||
return $mail->send() ? true : $mail->ErrorInfo;
|
||||
}
|
||||
|
||||
return "No contacts found";
|
||||
|
Reference in New Issue
Block a user