How to send HTML email with drupal_mail function in Drupal 6

Hello folks.

If you need to send html email with drupal_mail function in your module,  here is a sample to achieve this requirement.

1. Implement the hook_mail in YOURMODULE

<?
function YOURMODULE_mail($key, &$message, $params) {
    $message['subject'] = $params['subject'];
    $message['body'] = $params['body'];
    
    $headers = array(
        'MIME-Version' => '1.0',
        'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
        'Content-Transfer-Encoding' => '8Bit',
        'X-Mailer' => 'Drupal'
      );
    
    foreach ($headers as $key => $value) {
        $message['headers'][$key] = $value;
      }
}

?>

2. Call the drupal_mail

<?
    $mailto = "receiver@domain.com";    
    $mailfrom = 'sender@domain.com';
    $subject = "Test HTML email";
    $message = "<h2>Hello EMAIL</h2>";    
    drupal_mail('YOURMODULE', 'reply', $mailto, language_default(), 
                 array('body' => $message, 'subject' => $subject), $mailfrom, TRUE);
?>

Enjoy IT.

enzo