2013-12-16 55 views
0

我正在一個包含表單的初始頁面上工作。當表單被提交時,我的add.php將表單輸入字段寫入SQL服務器,然後它應該發送一封html電子郵件給填寫表單的人。來自PHP的HTML電子郵件不能正確解析

問題#1:收到電子郵件,但它顯示html標記;而不是電子郵件的格式化版本。 enter image description here 問題#2:「From」字段正在填充「text/html」並顯示網絡服務器:tribeca.websitewelcome.com。它沒有顯示指定的電子郵件。

下面是add.php

<?php 

$name=$_POST['Name']; 
$email=$_POST['Email']; 

$to = $_POST['Email']; 
$subject = 'Company Name Webinar Contact'; 
$message = '<!DOCTYPE html> 
<html> 
<head> 
<title>Email</title> 
</head> 
<body style="background-color: #e9e9e9;"> 
<table cellpadding="0" cellspacing="0" border="0" width="100%"> 
<tr> <td style="width:600px;"> </td> </tr> 
<tr> <td> <table cellspacing="0" cellpadding="0" width="600px" border="0" style="background-color: #fff;margin:0 auto;border:solid 10px #fff;font-family: lucida grande, sans-serif;"> 
<tr> <td style="height:100px;"> <center> <img src="eq-logo.jpg" /> </center> </td> </tr> 
<tr style="height:1px; background-color:#dcdcdc"> <td > </td> </tr> 
<tr style="height:1px; background-color:#f1f5ee"> <td > </td> </tr> 
<tr style="height:100px;"> <td > <h1 style="color:#e10621;">Thank you for your enquiry&#33;</h1> <h3>Someone from our team will contact you shortly&#46;</h3> <p style="line-height:28px;">We&#39;ve helped hundreds achieve their financial dreams and look forward to showing YOU how to turn YOUR common &#34;cents&#34; into dollars&#46; Please take a few moments to check out the other areas of our <a href="http://equanimityconcepts.com.au/">website</a>&#46; </p> <p><b>The Company Name Team</b></p> </td> </tr> 
</table> </td> </tr> 
<tr> <td> <center> <img src="bottom-shadow.png" /> </center> </td> </tr> 
</table> 
</body> </html> 
'; 

$headers = 'MIME-Version: 1.0' . '\r\n'; 
$headers .= 'Content-type:text/html;charset=iso-8859-1' . '\r\n'; 
$headers .= 'From: <[email protected]>' . "\r\n"; 

// Connect 
mysql_connect("localhost", "db_user", "user_password") or die(mysql_error()) ; 
mysql_select_db("db_name") or die(mysql_error()) ; 

// Write 
mysql_query("INSERT INTO `table_name` VALUES ('$name', '$email')") ; 

// Email 
mail($to,$subject,$message,$headers); 

header('Location: http://companyname.com.au'); 

exit(); 

?> 

附加註釋的內容: 我試圖通過行HTML分離「消息」伸到線克里斯coyiers沒有運氣HTML電子郵件嘖嘖。在這裏,您可以在消息區域中看到完整的html。

+0

嘗試使用所有雙引號'$ headers =「MIME-Version:1.0」。爲 「\ r \ n」 個; $ headers。=「Content-type:text/html; charset = iso-8859-1」。爲 「\ r \ n」 個; $ headers。=「發件人:<[email protected]>」。 「\ r \ n」;' –

+0

謝謝弗雷德!你也是對的。 \ r \ n必須包含在雙引號中。 –

+0

不客氣。 –

回答

1

這是你的報價! \ r \ n行使用雙引號:

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type:text/html;charset=iso-8859-1' . "\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n"; 
+1

只需點擊白色複選標記(答案旁邊),直至它變成綠色表示接受並關閉問題。 @ Jared.DAGI Plus是''\ r \ n「'而不是'」/ r/n「'如果你使用'/' –

+0

,這肯定會給你帶來麻煩。」\ r \ n「抱歉,同樣的問題! –

相關問題