我正在尝试用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);
?>
尝试按如下方式更改$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);
?>