我正在创建一个简单的模块,它将向我们的网站中的交易发送HTML电子邮件给用户。
我已经搜索了很多,但是找不到适合Drupal的解决方案。现在我可以发送邮件,但只能发送纯文本。
在Drupal 7中发送HTML电子邮件的分步过程是什么?
function example_form_submit( $form,&$form_state) {
$friend_email=$form_state['values']['friend_email'];
$mailto =$friend_email; //gift to a friend
$mailfrom ='no-reply@example.com';
$subject = "another message for HTML email from example.com";
$body="<h2 style='font-size:28px;color:red;'>Hello EMAIL, i here i want to be <b>bolded</b></h2>";
if (drupal_mail('example', 'send_gift', $mailto, language_default(),$params,$mailfrom,TRUE)) {
drupal_set_message(t('Your gift was sent successfully!!!'));
}
else {
drupal_set_message(t('<font color="red">Error occured while sending your mail!!!</font>'));
}
/****hook_mail*/
function example_mail($key,&$message,$params) {
$language = $message['language'];
switch ($key) {
case 'send_gift':
$message['subject']=t($params['subject'], $var, $language->language);
$message['body'][]=$params['body'];
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
break;
}
}