Software engineer, data guy, Open Source enthusiast, New Hampshire resident, husband, father. Fan of guitars, hiking, photography, homebrewing, sarcasm.
Sending an email when a form is submitted using form_alter and drupal_mail
For my blog I thought it would be great if I was notified when a comment was submitted. Like most of my articles, I try to explain how to accomplish something by implementing your own module hooks. In this article I’ll explain how I modified the comment form using a form_alter hook, and added an additional submit handler to send an email using drupal_mail.
First I defined a form_alter hook to modify the comment form submit handlers
Next I created the submit handler function:
Last I defined the mail hook:
Now when a comment is posted, my submit handler is called which notifies me of the new comment.