The Easiest Way To Debug Email Messages In Drupal
Time from time, while developing websites with Drupal I encounter the problem of debugging email messages my site sends. The common solution is to send test messages to your own mailbox to see how messages look like, debugging them this way. But this is not the most comfortable solution, moreover, it can become a nightmare debugging email on a localhost, especially on Windows, when you have to install local mail server, route all the stuff to localhost mailboxes and hassle with Mercury or some other thing...well in overall, it is not the most pleasant thing to do. Recently, I came to this simple and hassleless solution. Frankly, since I came up to this, mail debugging for Drupal isn’t a nightmare to me anymore. So, enough words, it is time to act:
- Install a devel module (http://drupal.org/project/devel) for your version of Drupal and enable it. Chances, most of you have this already installed.
- Add hook_mail_alter to your custom module, like this:
1 2 3 4 5 6
Now, your module catches every email message Drupal sends and outputs it as $message array in a nice Krumo view. As you see, this is even better than receiving real messages, you see every aspect of your outgoing email message including subject, body, mail headers and stuff. And this is without all the hassle with installing mail servers or other server related mumbo jumbo. Cool! If you don’t want email messages to go out of your website at all, modify the hook like this:
1 2 3 4 5
No money, no honey No addressee - no delivery. That’s simple! Hope this tip is helpful, don’t be so shy and retweet it or facebook-like it to share with others. Have a nice day!