I am trying to send the results of a non-Drupal form using Drupal's user_mail function in the user.module. The PHP form in question existed before we switched to Drupal, and I was hoping to get it working with a minimal amount of fuss. So far, so good except for one thing: whenever I evoke PHP's mail function, or Drupal's own user_mail function, I end up with *two* emails being sent rather than one.
I've been experimenting with various ways around this (I'm assuming that the second e-mail is being sent when Drupal pre-processes the PHP; this plays havoc with functions not declared in modules as well) and after reading through the PHP snippets documentation my current tack was to create a new helper module to handle the e-mail sending.
Here's what I'm doing right now. I have created a module called "its_library.module". The contents of the module are as follows:
<?php
function its_library_help($section='') {
$output = '';
switch ($section) {
case "admin/modules#description":
$output = t("ITS Library Functions.");
break;
}
return $output;
}
function _its_library_sender() {
$to = "[valid@email.com]";
$subject = "Test Subject";
$body = "Test Body";
$headers = "From: [valid@email.com]\nReply-to: [valid@email.com]\nX-Mailer: Drupal\nReturn-path: [valid@email.com]\nErrors-to: [valid@email.com]";
user_mail($to, $subject, $message, $header);