2011-11-23 136 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>';