2014-09-02 37 views
0

我使用PHPMailer製作了一個使用Mandrill發送郵件的腳本。我試圖發送一個使用bootstrap製作的html模板,但是當郵件到來時,CSS不起作用。 我試圖用file_get_contents()函數獲取html內容,但它沒有得到引導樣式表。有任何想法嗎?使用PHPMailer和Mandrill發送模板

這裏是腳本

<?php 
     include "../phpmailer/PHPMailerAutoload.php"; 

     include "../phpmailer/class.phpmailer.php"; 

     error_reporting(E_ALL^E_NOTICE); 


     if (!isset($_POST['Submit']) |$_POST['Submit'] != 'Trimite') { 

       $adress = ''; 

     } else { 

     $adress = $_POST['adress']; 

     $mail = new PHPMailer; 

     $mail->isSMTP(); 

     $mail->Host  = 'smtp.mandrillapp.com'; 

     $mail->Port  = 587; 

     $mail->SMTPAuth = true; 

     $mail->Username = 'username'; 

     $mail->Password = 'key'; 

     $mail->SMTPSecure  = 'tsl'; 

//  $mail->SMTPDebug  = 1; 

     $mail->From  = '[email protected]'; 

     $mail->FromName = 'Name'; 

     $mail->AddAddress($adress); 

     $mail->IsHTML(true); 

     $mail->Subject = 'Subject'; 
     $mail->Body = file_get_contents('process_completed.html'); 
     $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

    } 
?> 
+0

是你的路徑是否正確? [檢查此](http://php.net/manual/en/function.file-get-contents.php)它會幫助你 – 2014-09-02 11:17:32

+0

路徑是正確的。該腳本發送HTML模板,但沒有CSS(包括靴子庫) – Graver 2014-09-02 11:24:18

+0

你把整個引導CSS放入電子郵件?!你知道電子郵件客戶端不會獲取外部樣式表嗎?爲了做到這一點,你必須在CSS中加入'process_completed.html' - 你沒有展示你的代碼來生成正文,這似乎是這個問題的關鍵。順便說一句,如果你加載自動加載器(就像你一樣),你也不需要加載PHPMailer類 - 自動加載器會爲你做。 – Synchro 2014-09-02 12:29:40

回答

2
$mail->SMTPSecure  = 'tsl'; 

大概應該是:

$mail->SMTPSecure  = 'tls'; 
0

如果您正在使用的電子郵件模板中的任何外部CSS文件將無法正常工作。

在電子郵件模板中只使用內嵌css。

0

許多電子郵件客戶端不會渲染位於電子郵件HTML頭部的CSS。在將電子郵件提交給Mandrill之前,您需要先嵌入CSS,或者使用Mandrill的CSS inlining option

0

我做了一個模板,內嵌的CSS它的工作原理。謝謝。