Okay, so "you don't." But, can you with a bit of tweaking? My client has some compliance requirements that require the Membership emails to include some legal comments and a logo of the organization they belong to. So basically, I want to change the system emails that are sent from plain text to HTML so I can stick this image in the header/footer of each email sent. Has anyone worked this out? Any tips on where to begin?
No need to get into the plain-text versus HTML email debate, I'm looking to discuss the technical aspects of altering the existing mail-generation functions in Drupal, please let me know if you have tried this/got it working.
/**
* Implementation of hook_mail_alter
*
* Changes any mail into a HTML mail
*/
function CUSTOM-MODULE-NAME_mail_alter(&$message) {
$message['headers']['Content-Type'] = "text/html; charset=iso-8859-1";
$message['headers']['Mime-Version'] = "1.0";
}
CUSTOM-MODULE-NAME = the name of your module
this turn every mail sent by Drupal into a HTML mail
You can more customize this function for any specific email.
Like if you want HTML type email only for contact us, then use below code.
<?php
drupal_mail('contactus', 'mail_id', $to, language_default(), $values, $from);
function CUSTOM-MODULE-NAME_mail_alter(&$message) {
// Check message id for contact us email
if ($message['id']=='contactus_mail_id') {
$message['headers']['Content-Type'] = "text/html; charset=iso-8859-1";
$message['headers']['Mime-Version'] = "1.0";
// You can even add Cc or Bcc here
$message['headers']['Cc'] = 'cc@example.com';
$message['headers']['Bcc'] = 'bcc@example.com';
}
}
?>
You can send HTML e-mail through user_mail() by using the Swift Mailer module. What you need to to is to first install the module, and then do the following:
The key is to specify which format you'd like to send the e-mail in.
Once you've done this, you can simply go to the admin pages and add markup to the applicable e-mails. If you do not want to add any new code, you can always set up the Swift Mailer module to always send e-mails as either HTML or plain text. However, this is a "catch all" rule, and it will not let you differentiate e-mails and their formats.
As an note to this, you could select the Swift Mailer module option which triggers an automatic generation of plain text versions based on HTML versions. Thus, you'd be sending out e-mails with both HTML and plain text versions.
Comments
You don't
user_mail() only sends plain text. You can use one of the mail modules to send other types of mail, e.g., Mail module, http://drupal.org/node/10227.
thanks! I appreciate your response.
Thanks, I installed this module and it is working great for me. I appreciate your response.
Hmmm...
Okay, so "you don't." But, can you with a bit of tweaking? My client has some compliance requirements that require the Membership emails to include some legal comments and a logo of the organization they belong to. So basically, I want to change the system emails that are sent from plain text to HTML so I can stick this image in the header/footer of each email sent. Has anyone worked this out? Any tips on where to begin?
No need to get into the plain-text versus HTML email debate, I'm looking to discuss the technical aspects of altering the existing mail-generation functions in Drupal, please let me know if you have tried this/got it working.
Thanks.
You can hack
You can always hack the
user_mail()function to send HTML. See "Example 4. Sending HTML email" on this page: http://www.php.net/manual/en/function.mail.php.Content-Type: html/text
This is actually very easy and requires no code modification.
In your module_mail hook, you can modify the message headers like this:
This sends an HTML message!
thanks
fallen
create a custom module ...
... and add this:
CUSTOM-MODULE-NAME = the name of your module
this turn every mail sent by Drupal into a HTML mail
You can more customize it
You can more customize this function for any specific email.
Like if you want HTML type email only for contact us, then use below code.
The Swift Mailer module?
You can send HTML e-mail through user_mail() by using the Swift Mailer module. What you need to to is to first install the module, and then do the following:
The key is to specify which format you'd like to send the e-mail in.
Once you've done this, you can simply go to the admin pages and add markup to the applicable e-mails. If you do not want to add any new code, you can always set up the Swift Mailer module to always send e-mails as either HTML or plain text. However, this is a "catch all" rule, and it will not let you differentiate e-mails and their formats.
As an note to this, you could select the Swift Mailer module option which triggers an automatic generation of plain text versions based on HTML versions. Thus, you'd be sending out e-mails with both HTML and plain text versions.
You can have a closer look at it on http://www.drupal.org/project/swiftmailer