我试图用php发送电子邮件,但它运行良好,但只有我收到的邮件有问题,但不能正常工作。有人能找到问题吗?
<?php
$to = "me@email.com";
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message from $name.";
$fields = array();
$fields{"email"} = "email";
$fields{"message"} = "message";
$body = "Message:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$send = mail($to, $body, $headers, $subject);
?>
答案 0 :(得分:2)
尝试更改$send
订单,如下所示;
$send = mail($to, $subject, $body, $headers);
<强>更新强>:
感谢David指出,将变量$from
添加到您的php,以便发件人的电子邮件也将包含在$headers
中:
<?php
$to = "me@email.com";
$from = $_REQUEST['from'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message from $name.";
$fields = array();
$fields{"email"} = "email";
$fields{"message"} = "message";
$body = "Message:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$send = mail($to, $subject, $body, $headers);
?>