联系表格为空;联系表格回复到错误的地址
我试图做一个无验证的垃圾邮件阻止联系表格。从用户的角度来看,它似乎正在工作,因为点击发送按钮后出现谢谢页面。联系表格为空;联系表格回复到错误的地址
问题#1:到达的电子邮件是空白的,不包含发送的消息的内容。在这里找到一个类似的帖子,但提供的建议不适用:Contact form problem - I do receive messages, but no contents (blank page)。
问题#2:回复消息也显示在同一个收件箱中,而不是发送到表单用户的地址 - 当测试时,它是我自己的。
的HTML:
<form method="post" action="submit.php">
<p>Name:<br>
<input type="text" name="Name" id="Name" /></p>
<p>Phone:<br>
<input type="text" name="Phone" id="Phone" /></p>
<p>Email:<br>
<input type="text" name="Email" id="Email" /></p>
<p class="antispam">Leave this empty:<br />
<input name="url" /></p>
<p style="color:#06C;">Forward to:<br>
<input type="text" name="Forwardto" id="Forwardto" /></p>
<p>Message:<br />
<textarea name="Message" rows="20" cols="20" id="Message"></textarea></p>
<p><input type="submit" value="Send" class="submit-button" /></p>
</form>
的PHP(我的实际地址删除):
<?php
if(isset($_POST['url']) && $_POST['url'] == ''){
$youremail = '[email protected]';
$body = "This is the form that was just submitted:
Name: $_POST[name]
Phone: $_POST[phone]
E-Mail: $_POST[email]
Forward to: $_POST[forwardto]
Message: $_POST[message]";
if($_POST['email'] && !preg_match("/[\r\n]/", $_POST['email'])) {
$headers = "From: $_POST[email]";
} else {
$headers = "From: $youremail";
}
mail($youremail, 'Contact Form', $body, $headers);
}
?>
相关的CSS:
<style type="text/css">
.antispam { display:none;}
</style>
是在上面的代码中的问题。 。 。或者可能会有其他事情发生?
您要访问$_POST['email']
而本场的名字是email
(小“E”) - 尝试使用$_POST['Email']
代替
问题二 - mail()
函数的第一个参数是到您希望它被发送的电子邮件,即$_POST['Email']
。现在你试图将它发送到硬编码的$youremail
。
这不只是电子邮件变量是错误的。他们都会不当地套上。 – j08691 2013-05-09 14:42:08
感谢大家的回复。这些更正已经考虑到了这两个问题。 – user2356283 2013-05-09 19:31:20
如果我帮助过你,请接受我的回答并提出上传。对于错误报告,请看[这里](http://*.com/questions/845021/how-to-get-useful-error-messages-in-php)。 – Mateusz 2013-05-09 19:34:26
首先你需要关闭报价$ body =“这是刚刚提交的表格:”; 我说要使用$ _REQUEST而不是$ _POST,因为此变量是一个超全局数组,用于收集使用GET和POST方法发送的数据。 我已经尝试这样做,它的工作原理 如果(isset($ _ REQUEST [ '电子邮件'])) 输入代码here` {
//Email information
$admin_email = "myemail.co.uk";
$subject = "This is the form that was just submitted";
$email = $_REQUEST['email'];
$comment = $_REQUEST['comment'];
$full_name = $_REQUEST['full_name'];
//send email
mail($admin_email, "$subject", "message:" . $comment, "From:" . $email, `enter code here`enter code here`$full_name);
//Email response if needed
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else
{
enter code here`enter code here`?>
enter code here`<p>Email us at <i>website name.com</i></p>
enter code here`<?php
enter code here`}
enter code here`die();
enter code here`?>
您是否尝试过使用'$ _ POST [ '电子邮件']'而不是' $ _POST ['email']' - 大写“E”? – Mateusz 2013-05-09 14:39:08
你也应该打开错误报告,你会被告知php你使用的$ _POST索引是无效的 – 2013-05-09 14:48:19
php数组键是区分大小写的。所有的$ _POST键都必须与表单中'name'的外壳匹配。你正在提交'电子邮件','电话'等,但正试图访问'电子邮件','电话'等... – 2013-05-09 14:51:34