php邮件主题不发送
我试图用php发送电子邮件,效果很好,但只有我收到的邮件有问题,主题不起作用。有人能找到问题吗php邮件主题不发送,php,Php,我试图用php发送电子邮件,效果很好,但只有我收到的邮件有问题,主题不起作用。有人能找到问题吗 <?php $to = "me@email.com"; $name = $_REQUEST['name']; $headers = "From: $from"; $subject = "You have a message from $name."; $fields = array(); $fie
<?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);
?>
此外,变量$from从未设置,但用于第4行。@David Nice catch!刚刚在答案中添加了这一点。您仍然需要修复“更新”部分中的mail
功能。@David刚刚修复了它!谢谢这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。虽然类似的问题可能在这里的主题,这是一个解决的方式不太可能帮助未来的读者。