我正在尝试为网站构建一个简单的联系表单,但电子邮件的$ headers部分未正确发送。电子邮件本身正在发送,但电子邮件中缺少$ headers选择器下的所有内容。我已经包含了php代码和下面的表单,我也知道我还没有清理代码。我想在添加其他内容之前确保表单正常工作。
<?php
$to = "example@gmail.com";
$subject = "Reply From Your Website: ".$_POST["subject"];
$message = $_POST["message"];
$headers = "From: ".$_POST["name"]."" . "\r\n" . "Reply To: ".$_POST["email"]."";
mail($to,$subject,$message,$headers);
?>
<table class="contact-form">
<form method="post">
<tr>
<td class="label">Name:</td>
<td class="input"><input type="text" maxlength="40" name="name" required></td>
</tr>
<tr>
<td class="label">Email:</td>
<td class="input"><input type="email" maxlength="24" name="email" required></td>
</tr>
<tr>
<td class="label">Subject:</td>
<td class="input"><input type="text" maxlength="24" name="subject" required></td>
</tr>
<tr>
<td class="label">Message:</td>
<td class="input"><textarea rows="9" maxlength="1000" name="message" required></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"></td>
</tr>
</form>
</table>
答案 0 :(得分:0)
我不太确定这是否会有所帮助,但无论如何我们都要尝试一下。
<?php
$to = "kouen922@gmail.com";
$subject = "Reply From Your Website: ".$_POST["subject"];
$message = $_POST["message"];
$headers = "From: ".$_POST["name"]."" . "\r\n";
$headers .= "Reply To: ".$_POST["email"]."";
mail($to,$subject,$message,$headers);
?>
答案 1 :(得分:0)
可能有两个原因:
在$_POST['name']
中,您没有电子邮件地址(变量名称显示的是发件人姓名,而不是电子邮件)
邮件服务器配置不允许从不同于服务器域的域发送电子邮件
试试这个:
$subject = "Reply From Your Website: ".$_POST["subject"];
$message = $_POST["message"];
$headers = "From: ".$_POST["name"]." <email@serverdomain.com>" . "\r\n" . "Reply To: ".$_POST["email"]."";
mail($to,$subject,$message,$headers);
但请将email@serverdomain.com更改为与您的服务器位于同一域中的某些电子邮件。