How can I debug an email function?
You could write an automated test with SimpleTest.

Takes quite a bit of initial effort but once you have it, it is a matter of a few seconds to re-run your test.

Simpletest also automatically intercepts sent mails and you can then get them directly in the test with $this-&gt;drupalGetMails().

See for example How do I write automated tests for a Drupal site?