我正在尝试制作一个不受垃圾邮件影响的表单,并向注册的人发送一封简单的电子邮件。
我对 PHP 很陌生,我面临的问题是,当在电子邮件字段中使用虚假电子邮件地址提交表单时,它会显示错误消息,指出电子邮件无效,但仍然让注册通过将其添加到数据库。
这是代码
function spamcheck($field) {
// filter_var() sanitizes the e-mail
// address using FILTER_SANITIZE_EMAIL
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
// filter_var() validates the e-mail
// address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
return TRUE;
}
else {
return FALSE;
}
}
if(isset($_REQUEST['email'])) {
// if "email" is filled out, proceed
// check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE) {
die("<font color='red'>Your email address is invalid, please try again.</font><br/><br/><form><INPUT TYPE='button' VALUE='Back' onClick='history.go(-1);return true;'></form>");
}
else {//send email
$to = "$email";
$from = "name@mywebsite.com";
$message = "Just a message";
$subject = "Subject";
mail($to, $message, $subject, "From: $from", "-f$from");
}
}
任何帮助将不胜感激。