Hi

I wonder if somebody got the time and will to help with a problem that bugs many people. When I send mail to registered users from the Drupal Contact form to someone with a hotmail address, the umlaut characters get all "#¤% up.

I've searched the internet and the forums for a solution, but I'm no programmer.

Any hints would be much appreciated. How can I, let's say check if the recipients mail is a hotmail or yahoo account, and change the charset for the mail from utf-8 to iso-8859-1?

Assorted reading:

Hotmail and UTF-8, what a headache!

http://drupal.org/node/78876

Hotmail, IE and UTF-8 encoding

http://drupal.org/node/73576

Found this code in a post:
http://drupal.org/node/106837
-----------
Here is the code which I think deals with sending e-mails from drupal in modules/user.module :

<?php
function user_mail($mail, $subject, $message, $header) {
  if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
   include_once './' . variable_get('smtp_library', '');
    return user_mail_wrapper($mail, $subject, $message, $header);
  }
  else {
    /*
    ** Note: if you are having problems with sending mail, or mails look wrong
    ** when they are received you may have to modify the str_replace to suit
    ** your systems.
    **  - \r\n will work under dos and windows.
    **  - \n will work for linux, unix and BSDs.
    **  - \r will work for macs.
    **
    ** According to RFC 2646, it's quite rude to not wrap your e-mails:
    **
    ** "The Text/Plain media type is the lowest common denominator of
    ** Internet e-mail, with lines of no more than 997 characters (by
    ** convention usually no more than 80), and where the CRLF sequence
    ** represents a line break [MIME-IMT]."
    **
    ** CRLF === \r\n
    **
    ** http://www.rfc-editor.org/rfc/rfc2646.txt
    **
    */
    return mail(
      $mail,
      mime_header_encode($subject),
      str_replace("\r", '', $message),
      "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header
    );
  }
}
?>

-----------

And I found a tip to use utf8_decode() to recode from utf-8 to iso-8859-1.

Comments

mkalkbrenner’s picture

If you're able to implement your own module you could implement hook_mail_alter to do the conversion for all or some mails. This is the code for all mails in iso-8859-1:


function YOUR_MODULE_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers) {
  // Convert Mail encoding to iso-8859-1
  $headers["Content-Type"] = str_replace("utf-8", "iso-8859-1", $headers["Content-Type"]);
  $subject = utf8_decode($subject);
  $body = utf8_decode($body);
}

if you want to use some different encoding you have to use php's iconv() function.

Markus

jackdaw’s picture

Even if the problem lies with Hotmail and other ISO-8859-1 or whatever based services, it looks bad when Drupal sends out unreadable e-mails.