To handle PHPMailer errors by Exceptions, PHPMailer object must be instantiated with parameter. I found it on http://stackoverflow.com/questions/2386544/error-handling-with-phpmailer
smtp.mail.inc dont use it in mail() function, so errors are handled by 'echo' so i get nasty message before page html is created
// Create a new PHPMailer object - autoloaded from registry.
$mailer = new PHPMailer();
it should be:
// Create a new PHPMailer object - autoloaded from registry.
$mailer = new PHPMailer(true);
this is how drupal page source looks like without proper error handling:
Message body empty
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" version="XHTML+RDFa 1.0" dir="ltr">
I want my code to look like this:
try {
$MailSystem = drupal_mail_system('smtp', 'xxx');
$message2 = $MailSystem->format($message);
$result = $MailSystem->mail($message2);
if($result) {
return array('status'=>TRUE, 'message'=>$message);
} else {
return array('status'=>FALSE, 'message'=>"My custom error message");
}
}
catch(Exception $e) {
return array('status'=>FALSE, 'message'=>"My custom error message");
}
Closed: outdated
1.2
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
No activities found.