PHP电子邮件无法正常工作

时间:2011-12-30 16:20:20

标签: php email

当我编辑我的PHP代码以发送消息和from字段时,from字段工作,然后消息没有。我怎么能拥有它,所以当使用from字段时,消息将在电子邮件的正文中?这是我的代码。

<?php    
$headers  = "Contact: ".$_POST['contact']."\r\n";
$headers .= "BCC: ".$_POST['email']."\r\n";
$headers .= "From: Your Company <your_company@example.com>\r\n";

mail("Your Memory", $thank_you,$headers, $message);
?> 

3 个答案:

答案 0 :(得分:1)

你的参数搞砸了。您拥有$mesage的第五个参数应该是传递给SMTP服务器的额外选项。看起来您可能希望$message拥有$thank_you

mail($to_visitor, "Your Memory", $message, $headers);

答案 1 :(得分:0)

您的参数顺序错误......来自PHP.net

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

所以你想要:

mail($to_visitor, "Your Memory", $message ,$headers);

不确定$ thank_you是什么,但你需要相应调整。

答案 2 :(得分:0)

mail()的消息参数是第三个参数。如果您想使用$message作为消息,则需要将mail()来电更改为:

mail($to_visitor, "Your Memory", $message, $headers);