So as the title explains, when sending an HTML email with drupal_mail(), email comes with no HTML tags.
$module = 'module';
$key = 'contact_message';
$language = language_default();
$params = array();
$email = '[email protected]';
$from = variable_get('site_mail', '[email protected]');
$send = TRUE;
$message = drupal_mail($module, $key, $email, $language, $params, $from, $send);
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8';
$message['subject'] = 'Test';
$message['body'] = array();
$message['body'][] = '<a href="#">Testing anchor in mail</a>';
$system = drupal_mail_system($module, $key);
$message = $system->format($message);
$message['result'] = $system->mail($message);
And when recieving the email, and viewing the source:
Message-Id: <[email protected]>
X-Authentication-Warning: testserver : www-data set sender to [email protected] using -f
To: [email protected]
Subject: Test
X-PHP-Originating-Script: 1000:system.mail.inc
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8Bit
X-Mailer: Drupal
Sender: [email protected]
From: [email protected]
Testing anchor in mail [1]
[1] #
So you can see that any HTML tags were stripped. And it doesn't matter what HTML tags I put in body.
I thought it might be related to Text Fomats, but I have "Filtered HTML" and "Full HTML" active filters with any permissions.
The thing confused me were the Ubercart invoices. At first they were sent with HTML, and then at some point it stopped. They were received plain text. After digging a bit @develkar answer, I've found this in one of ubercart updates:
/**
* Installs HTML Mail System for Ubercart.
*/
function uc_store_update_7004() {
// Set mail handler for all Ubercart modules
variable_set('mail_system',
array_merge(
variable_get('mail_system', array('default-system' => 'DefaultMailSystem')),
array(
'uc_cart' => 'UbercartMailSystem',
'uc_order' => 'UbercartMailSystem',
'uc_file' => 'UbercartMailSystem',
'uc_roles' => 'UbercartMailSystem',
'uc_stock' => 'UbercartMailSystem',
'uc_store' => 'UbercartMailSystem',
)
)
);
}
I guess that at some point, one of installed modules (I suspect SMTP module) overridden this variable, and that's why emails were coming plain text. After running this update manually again, Ubercat invoices are HTML again.
For the rest of emails, I'll have to install some modules as suggested in other answers.
Thanx.