Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


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.