2012-08-29 68 views
5

我有一個自定義模塊,我試圖使用drupal_mail函數(D7)生成HTML電子郵件。郵件即將通過,甚至顯示文本/ HTML,但某些地方似乎在收到郵箱之前剝離了HTMl。Drupal 7 drupal_mail剝離HTML?

首先,在功能我建立我的標題/體/其他增值經銷商和發送自定義函數:

$body = "We thought you'd like to know that ".$fullname." has marked your project as completed. 
    <br /><br /> 
    Please visit the link at <a href='http://".$_SERVER['HTTP_HOST']."/survey/customer/".$customer[0]->unique_id."'>http://".$_SERVER['HTTP_HOST']."/survey/customer/".$customer[0]->unique_id."</a> to take the survey."; 
    $returnMail = latch_send_mail('pro_realized',$customer[0]->customer_email,$user->mail,$title,$body); 

然後我有latch_mail latch_send_email功能:

function latch_mail($key, &$message, $params) { 
    $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; 
} 

$message['body'][] = $params['body']; 
$message['subject'] = $params['subject']; 
} 

function latch_send_mail($key,$to,$from,$title,$body,$headers='') { 
    $params['body']=$body; 
    $params['subject'] = t($title); 
    return drupal_mail('latch', $key, $to, language_default(), $params, $from,TRUE); 
} 

我希望電子郵件通過我的一個標籤和br標籤,但它來thro呃像這樣:

We thought you'd like to know that John Doe has marked your project as completed. Please visit the link at http://latch.local/survey/customer/34c91b8883cd70b32c65feb7adf9c393 [1] to take the survey. [1] http://latch.local/survey/customer/34c91b8883cd70b32c65feb7adf9c393 

不知何故,它採取我的鏈接,並把它們變成腳註,同時完全刪除br標籤。

任何幫助,您可以提供將不勝感激。謝謝!

回答

4

開箱即用,Drupal無法發送HTML電子郵件。爲了使Drupal支持HTML電子郵件,您需要HTML郵件模塊。 http://drupal.org/project/htmlmail一旦你有這樣的所有HTML應該發送。

0

下面是一個完整補充的替代方法。首先,安裝並啓用Mime Mail模塊。您可以閱讀README.txt以瞭解如何使用它的完整說明。我會給你簡短的版本。

您需要爲您的模塊啓用Mime Mail。您可以在example.install做到這一點使用hook_enablehook_update_N

function example_enable() { 
    mailsystem_set(array(
    'example_examplekey' => 'MimeMailSystem', 
)); 
} 

當你去admin/config/system/mailsystem,你會看到一個新條目已被添加爲你的模塊:

例模塊(examplekey鍵)類

MimeMailSystem

現在你不需要SPE cificy任何text/html標題了,Mime Mail照顧這個。如果你想

$headers['Content-Type'] = ... 

,您可以添加$message['plaintext']到您的郵件對於非HTML的選擇,但不是必需的:所以你不需要這個。

就是這樣!