2011-11-23 128 views
6

我會讓它變得非常簡單。我想通過php發送電子郵件。現在這裏是代碼。如何格式化PHP電子郵件

$line = '\n'; 
$a = "Customer Phone: "; 
$b = "Customer Last Name: "; 
$message = $a.$number.$line.$b.$LastName;  

$to = "[email protected]"; 
$subject = "Umrah Booking"; 
$from = $mailer; 
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers); 

這裏是輸出:

Customer Phone: 0712345678\nCustomer Last Name: Showkot 

和電子郵件顯示發送者沒有。它說nobody

我希望電子郵件將看起來像:

Customer Phone: 0712345678 
Customer Last Name: Showkot 

,我也想表明,電子郵件是從[email protected]

回答

6

1)改變'\n'"\n"。特殊字符(例如\n)僅在double-quoted strings中解釋。

2)嘗試將"From:"更改爲"From: "。或者,也許變量$from沒有價值。

+2

+1解釋_why_並不僅僅是_what_做。我正要評論_why_不同的引號是必要的,但你剛剛添加了這個。 – Wiseguy

+0

謝謝你......我剛剛登錄說問題解決了!無論如何非常感謝:-) – forgotten

2
$line = "\n"; 
$a = "Customer Phone: "; 
$b = "Customer Last Name: "; 
$message = $a.$number.$line.$b.$LastName; 

$to = "[email protected]"; 
$subject = "Umrah Booking"; 
$from = $mailer; 
$headers = "From: " . $from. "\r\n". 
'Reply-To: '. $from . "\r\n" . 
'X-Mailer: PHP/' . phpversion(); 
mail($to,$subject,$message,$headers); 
5

您可以使用HTML郵件也,在您就可以將使用HTML格式的實際郵件..這是非常簡單,幾乎鬱可使用的玉使用格式的內容中的HTML所有標籤甚至可以添加CSS .. !!你需要添加標題來發送HTML郵件。

這裏是一個例子..!

$to = "[email protected]"; 
$subject = "Test mail"; 
$a = "Customer Phone: "; 
$b = "Customer Last Name: "; 
$message = $a.$number.$line.$b.$LastName; 
$message=" 
<html> 
<body> 
    <h1>$a</h1>: $number <br> <h1>$b</h1>: $LastName<br> 
</body> 
</html>"; 

$from = "[email protected]"; 
$headers = "From: $from\r\n"; 
$headers .= "Content-type: text/html\r\n"; 

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

試試這個吧,它會工作..! :)

+0

謝謝它已經工作了!我已處理它:-)但無論如何謝謝你的關注! – forgotten

0

您可以在郵件標籤,例如輸入html:

$message = '<html><body>'; 
$message .= '<h1>Hello, World!</h1>'; 
$message .= '</body></html>';