Commit 7233d8f6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Don't pester the admins every time we try to send to an invalid email address (bug #731029)


Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 8e2c01f5
......@@ -466,7 +466,7 @@ abstract class ActivityType {
// go into the activity log as 'unread'
$changes->read = 0;
update_record('notification_internal_activity', $changes);
if (get_class($e) != 'EmailDisabledException') {
if (!($e instanceof EmailDisabledException || $e instanceof InvalidEmailException)) {
// Though, admins should probably know about the error
$message = (object) array(
'users' => get_column('usr', 'id', 'admin', 1),
......
......@@ -797,6 +797,11 @@ class CryptException extends SystemException {}
*/
class EmailException extends SystemException {}
/**
* Exception - Invalid address
*/
class InvalidEmailException extends EmailException {}
/**
* Exception - Email is disabled for this user
*/
......
......@@ -402,13 +402,15 @@ function email_user($userto, $userfrom, $subject, $messagetext, $messagehtml='',
}
else {
$usertoname = display_name($userto, $userto);
if (empty($userto->email)) {
throw new EmailException("Cannot send email to $usertoname with subject $subject. User has no primary email address set.");
}
$mail->AddAddress($userto->email, $usertoname );
$to = $userto->email;
}
if ($mail->IsError()) {
// If there's a phpmailer error already, assume it's an invalid address
throw new InvalidEmailException("Cannot send email to $usertoname with subject $subject. Error from phpmailer was: " . $mail->ErrorInfo);
}
$mail->WordWrap = 79;
if ($messagehtml) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment