Im trying to send an HTML mail through SMTP, Im currently using the modules:

  • MIME mail
  • PHPMailer
  • Mail System

On a Drupal 7 site.

The problem is that when I check the mail header that I have recivied it does not say Amazon SES which I have configured PHPmailer to do so but my hosts information

Following is my code.

function mail_subscribers($email_body, $email_subject, $subscribed_users) {
  $module = 'my_module';
  //$key = microtime();
  $key = 'mymodule_mailer';
  //$subscribed_users = get_subscribed_users($feed_nid, $users_type);
  $params['headers'] = array(
    'Bcc' => $subscribed_users,
  $to = 'welcome@mysite.com';
  $subject = $email_subject;
  //$params ='';
  $body[] = $email_body;
  $send = FALSE;
  $mail_message = drupal_mail($module, $key, $to, language_default(), $params, $send);
  $mail_message['subject'] = $subject;
  $mail_message['body'] = $body;

$mail_system = drupal_mail_system($module, $key); $mail_message = $mail_system->format($mail_message); $mail_message['result'] = $mail_system->mail($mail_message); }

and my hook_mail

function mymodule_mail ($key, &$message, $params) {
  switch ($key) {
    case 'mymodule_mailer':
      // Set headers etc

      $message['send'] = FALSE;

  • 1
    you've set $send to FALSE in 1st and again $message['send'] to FALSE in second function. Ideally it should not send any mail ;-) – AjitS Jan 22 '13 at 13:13
  • But it does, Thats actually what Im worried about the most. when I set $send to false nothing happens and two mails actually get sent, But when I add the hook_mail $message to false only one is sent. – saadlulu Jan 22 '13 at 13:20
  • @indrock Could it be my $params variable? – saadlulu Jan 22 '13 at 13:21
  • A single mail will be sent evertime to code is executed because you use object returned drupal_mail_system to send mail on the very last line of the first function. And if you set $send to TRUE then it should send 2. – AjitS Jan 22 '13 at 13:25
  • 1
    If you set the $send to be false, drupal_mail function will not send the mail, instead only compose and keep it in the memory. This composed mail is sent when you call $mail_system->mail($mail_message) at the last line of the first function. So, your code should send one mail (on last line) everytime; using code at the last line. If you set $send as TRUE, then a mail will be sent using drupal_mail function and also from the last line (hence two mails when $send is set to TRUE. – AjitS Jan 22 '13 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.