0

Problem

I'm trying to style an email sent with drupal_mail. Sometimes it works, other times it doesn't and I can't work out why.

I'm running mail system, SMTP and mimemail:

Mail system sets up: SMTP for sending and mimemail for styling.

In the mimemail options include stylesheets is disabled because it's found mail.css in my theme. Mime mail CSS compressor is enabled because people use hotmail and gmail.

Condition 1

User uses form to send email, this works as expected I receive a styled email in gmail.

$message = drupal_mail('module_1', 'notify', $email, language_default(), $params);

function module_1_mail($key, &$message, $params) {
    $title = check_plain($_SESSION['title']);
    $message['headers']['MIME-Version'] = '1.0';
    $message['headers']['Content-Type'] = 'multipart/mixed; text/html; charset=UTF-8; format=flowed;';
    $message['subject'] = t('Email subject plus ').$title;

    $message['body'][] = "Body text goes here";
    $message['params']['attachments'] = $params;    
  }

Condition 2

The user uses another form which schedules a rule action which sends an email some time later. This doesn't receive any styling despite seeming identical for all intents and purposes.

$message = drupal_mail('rules_module', 'notify', $user->mail, language_default(), $params);

function rules_module_mail($key, &$message, $params) {      
    $message['headers']['MIME-Version'] = '1.0';
    $message['headers']['Content-Type'] = 'multipart/mixed; text/html; charset=UTF-8; format=flowed;';

    $message['subject'] = t('Here is a (@location)', array('@location' => $params['location']));
    $message['body'][] = 'This is some body text';
  }

Could rules somehow affect the calling of a stylesheet? Am I missing something obvious?

1 Answer 1

0

The problem in my case was that the email being sent wasn't using the drupal_mail function but php send mail.

I run msmtp on my server to route mail and so rather than passing through drupal, the email was being sent directly through my server with none of the styling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.