In essence, if you have "Send as HTML" unchecked, and "Send as BCC" unchecked, and you don't have any file attachments, mass_contact fails to properly initialize $headers, so drupal_mail doesn't work.

Drupal Version: 5.2, Linux.

To reproduce bug:

  1. Choose "Mass Contact" from the navigation menu.
  2. Specify any Subject.
  3. Specify any Category.
  4. Specify any Message. E.g., "delete me".
  5. Do *NOT* include an attachment.
  6. UNcheck "Send as HTML"
  7. UNcheck "Send as BCC"
  8. I added var_dump($headers);exit to includes/common.inc/~1941 so I could see what was going on inside of drupal_mail.

Findings
$headers is NULL in this situation.
By contrast, the expected contents of $headers is at a minimum array(0){}

The result of $headers being NULL is that the array_merge in drupal_mail at includes/common.inc/~1941 fails, and a warning message is generated. When you have NULL headers, no mail is sent.

Suggested Fixes
Either of these two fixes worked fine for me:
1. Initialize $headers = array() just after the "// create headers" comment at modules/mass_contact/~671. [Relies on drupal_mail's $defaults array to set the Content-Type to text/plain]

or

2. Ensure that $headers is at least initialized to text/plain (modules/mass_contact/~687):

  elseif ($form_values['html'] == 1) {
    $headers['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';  }
# add the following:  
elseif ($form_values['html'] == 0) {
    $headers['Content-Type'] = 'text/plain; charset=UTF-8; format=flowed';
  }

Either way, I get reasonable headers, and mail sends! Hooray!

NOTE: I realize there might be something about my php.ini file that might help, too. But it's a good idea to fix this for all those people who's php.ini file is like mine...

-Andy

Comments

oadaeh’s picture

Do you have the following code from line 871 to line 877?

    // Send the e-mail to the recipients:
    if ($headers) {
      $success = drupal_mail('mass-contact-page-mail', $to, $subject, $body, $from, $headers);
    }
    else {
      $success = drupal_mail('mass-contact-page-mail', $to, $subject, $body, $from);
    }
oadaeh’s picture

Assigned: Unassigned » oadaeh

I found two places where I do not check for a valid header, and they're both in the area where a limit on the number of recipients is placed. This will be corrected soon.

oadaeh’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.