2012-02-29 116 views
2

我正在使用PHPMailer發送HTML電子郵件。它發送的電子郵件很好,但HTML不會在電子郵件客戶端中呈現。我已經通過基於網絡的GMail和OSX mail.app IMAP測試了相同的GMail帳戶。既不能正確渲染。PHPMailer HTML不呈現

我拉我的頭髮來解決這個問題。有任何想法嗎???

PHP代碼格式化電子郵件發送(該郵件被髮送,以便在工作):

// mail format settings 
// $mail->WordWrap = 50;  // set word wrap to 50 characters 
$mail->IsHTML(true);   // set email format to HTML 
$mail->CharSet="UTF-8";   // set the charset to UTF-8 
$mail->Encoding = '7bit'; 
$body = ''; 
$body .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; 
$body .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"; 
$body .= "<head>"; 
$body .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"; 
$body .= "<meta http-equiv=\"Content-Language\" content=\"en-us\" />"; 
$body .= "<style>"; 
$body .= "body {font-family:\"trebuchet ms\", arial, \"san serif\";font-size:14px;}"; 
$body .= ".email-header{ margin:5px;padding:20px;background:#dddddd;border-radius:10px;color:#000000;font-size:24px;font-weight:bold;}"; 
$body .= ".email-body{margin:10px 20px;}"; 
$body .= "</style>"; 
$body .= "</head>"; 
$body .= "<body>"; 
if ($_POST["type"]=='confirmation') { 

    // set the email body 
    $body .= "<div class=\"email-header\">Sky Lodge HOA Reservation Confirmation</div>"; 
    $body .= "<div class=\"email-body\">"; 
    $body .= "Dear ". $_POST["name"] . ",<br/><br/>"; 
    $body .= "This email is confirming your reservation for unit nnn x:<br/>"; 
    $body .= "<strong>Arriving:</strong> date<br/>"; 
    $body .= "<strong>Departing:</strong> date<br/><br/>"; 
    $body .= "Please click here to view your existing reservation(s):<br/>"; 
    $body .= "http://www.somesite.com/index.php?token=" . $_POST["token"] . "<br/><br/>"; 

    // set the email subject 
    $mail->Subject = "Sky Lodge HOA: Reservation Confirmation"; 

} else if ($_POST["type"]=='notify') { 

    // set the email body 
    $body .= "<div class=\"email-header\">Sky Lodge HOA Attention Required</div>"; 
    $body .= "<div class\"email-body\">"; 
    $body .= "Dear ". $_POST["name"] . ",<br/><br/>"; 
    $body .= "It is your turn to make a reservation for unit nnn x.<br/><br/>"; 
    $body .= "Please click here to make your reservation:<br/>"; 
    $body .= "http://www.somesite.com/index.php?token=" . $_POST["token"] . "<br/><br/>"; 

    // set the email subject 
    $mail->Subject = "Sky Lodge HOA: Attention Required"; 

} 
$body .= "Thank You,<br/>Patti Rea"; 
$body .= "</div>"; 
$body .= "</body>"; 
$body .= "</html>"; 
echo('$body: ' . $body); 
$mail->Body = $body; 
$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; 

後的郵件:

Return-Path: <[email protected]> 
Received: from skylodge (c-174-52-123-157.hsd1.ut.comcast.net. [174.52.123.157]) 
     by mx.google.com with ESMTPS id ko12sm7817099pbb.52.2012.02.29.11.02.07 
     (version=SSLv3 cipher=OTHER); 
     Wed, 29 Feb 2012 11:02:07 -0800 (PST) 
Date: Wed, 29 Feb 2012 12:02:05 -0700 
Return-Path: [email protected] 
To: Sky Lodge <[email protected]> 
From: Darren Ehlers <[email protected]> 
Cc: [email protected] 
Reply-To: Darren Ehlers <[email protected]> 
Subject: Sky Lodge HOA: Reservation Confirmation 
Message-ID: <[email protected]> 
X-Priority: 3 
X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/) 
MIME-Version: 1.0 
Content-Type: multipart/alternative; 
    boundary="b1_9941ff8576a1763200e134b5b313b1b1" 


--b1_9941ff8576a1763200e134b5b313b1b1 
Content-Type: text/plain; charset="UTF-8" 
Content-Transfer-Encoding: 7bit 

This is the body in plain text for non-HTML mail clients 


--b1_9941ff8576a1763200e134b5b313b1b1 
Content-Type: text/html; charset="UTF-8" 
Content-Transfer-Encoding: 7bit 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<meta http-equiv="Content-Language" content="en-us" /> 
<style> 
body {font-family:"trebuchet ms", arial, "san serif";font-size:14px;} 
.email-header{ margin:5px;padding:20px;background:#dddddd;border-radius:10px;color:#000000;font-size:24px;font-weight:bold;} 
.email-body{margin:10px 20px;}</style> 
</head> 
<body> 
<div class="email-header">Sky Lodge HOA Reservation Confirmation</div> 
<div class="email-body"> 
Dear Sky Lodge,<br/><br/> 
This email is confirming your reservation for unit nnn x:<br/> 
<strong>Arriving:</strong> date<br/> 
<strong>Departing:</strong> date<br/><br/> 
Please click here to view your existing reservation(s):<br/> 
http://www.somesite.com/index.php?token=WQ85o7OiT9<br/><br/> 
Thank You,<br/> 
Patti Rea 
</div> 
</body> 
</html> 

--b1_9941ff8576a1763200e134b5b313b1b1-- 

回答

0

您已經測試通過刪除文檔類型和標題標籤......在我看來,他們不需要......其餘的看起來很好。