我试图使验证码自由,垃圾邮件阻止联系形式。从用户的角度来看,它似乎是有效的,因为在发送按钮被点击后,感谢页面出现了。
问题#1:到达的电子邮件是空白的,不包含发送的消息的任何内容。在这里发现了一个听起来类似的帖子,但提供的建议并不适用:联系表单问题-我确实收到消息,但没有内容(空白页)。
问题#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 = '----@----.com';
$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
.
首先你需要关闭引号$body ="这是刚刚提交的表单:";我说使用$_REQUEST而不是$_POST,因为这个变量是一个超全局数组,用于收集用GET和POST方法发送的数据。我已经试过了,它很有效如果收取($ _REQUEST['邮件']))在这里输入代码' {
//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`?>