Thank-you, thank-you for this module.

However, I had mime-mail turned on, and the attachment came out as junk on the end of the mail. Turned it off.... all is well.
It is more important to have attachments than MIME-mail, but I'd love both....

Thanks again!

kent

Comments

oadaeh’s picture

Assigned: Unassigned » oadaeh
Category: bug » feature

I'm not particularly fond of Mime Mail as it's not flexible some areas and is presumptuous in other areas. However, I will look to see if there is something I can do to work with the module, though it may be a while before I can get to this issue.

oadaeh’s picture

Version: 5.x-1.1 » 5.x-1.x-dev

I spent some time looking at integrating Mime Mail with Mass Contact. As soon as I have a few free minutes, I'll take what I learned there and apply it here.

NewZeal’s picture

I've integrated contact_attach with mimemail by adding the following function to contact_attach.module:

/*
  *   Mimemail exception routine:  mimemail interferes with sending of attachments via contact_attach
  *   Mimemail can be suppressed by using the code from drupal_mail_send() for contact_attach forms
  *  The code in the else condition is taken directly from mimemail's drupal_mail_wrapper()
  *   In order for this to work the weight for the contact_attach module has to be lower than the weight for mimemail
  */
if (!function_exists('drupal_mail_wrapper')) {

  function drupal_mail_wrapper(&$message) {
    if(substr($message['id'],0,14) == "contact_attach") {
      $mimeheaders = array();
      foreach ($message['headers'] as $name => $value) {
        $mimeheaders[] = $name .': '. mime_header_encode($value);
      }
      return mail(
        $message['to'],
        mime_header_encode($message['subject']),
        // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
        // They will appear correctly in the actual e-mail that is sent.
        str_replace("\r", '', $message['body']),
        // For headers, PHP's API suggests that we use CRLF normally,
        // but some MTAs incorrecly replace LF with CRLF. See #234403.
        join("\n", $mimeheaders)
      );
    }
    else {
      $from = $message['from'];
      $to = $message['to'];
      $subject = $message['subject'];
      if ($format = variable_get('mimemail_format', FILTER_FORMAT_DEFAULT)) {
      $body = check_markup($message['body'], $format);
    }
    else {
      $body = $message['body'];
    }
    $headers = isset($message['headers']) ? $message['headers'] : array();
    $mailkey = isset($message['mailkey']) ? $message['mailkey'] : '';
    return mimemail($from, $to, $subject, $body, NULL, $headers, NULL, array(), $mailkey);
 
    }
  }
}

For this to work you need to set the weight of the contact_attach module to a value less than the weight for the mimemail module in the system table, so that this version of drupal_mail_wrapper gets loaded and not the mimemail one.

Note that this function works by overriding the mail send function before mimemail gets to.

kchown’s picture

Thanks!!!!

Tor Arne Thune’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev

Can you confirm this is still a problem in D6 and D7? The 5.x version is no longer supported.

GemQueen’s picture

Issue summary: View changes

I can confirm that this is still a problem on D7.

cebab54’s picture

How do I set the weights that you refer to enable your patch to the contact_attach.module to work ahead of MIME please?

oadaeh’s picture

Status: Active » Closed (outdated)

I'm closing this as it is for a branch that is no longer supported.