Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

How can I get the success/failure response of drupal_mail() generated by another modules?

hook_mail_alter() doesn't return success/fail and drupal_mail() is only helpful if the message is coming from my module.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

The only way I can see is implementing hook_watchdog(), and look for a error message that matches "Error sending e-mail (from %from to %to)."

function mymodule_watchdog(array $log_entry) {
  if ($log_entry['message'] == 'Error sending e-mail (from %from to %to)') {
    // ...  
  }
}

The alternative would be implementing a class that replaces DefaultMailSystem, which is a class implementing MailSystemInterface. To achieve this, it is enough to change the value of the mail_system Drupal variable.

share|improve this answer
    
For a nice example of how to implement a MailSystemInterface. Take a look at the maillog module. –  thepearson Mar 5 '13 at 22:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.