我想製作一個表格,從垃圾郵件安全,併發送一個簡單的電子郵件給註冊人。PHP安全電子郵件阻止虛假的電子郵件,但讓註冊通過
我對PHP相當陌生,im面臨的問題是,當表單在電子郵件字段中提交了一個錯誤的電子郵件地址時,它會顯示錯誤消息,指出電子郵件無效,但仍允許註冊通過將其添加到數據庫。
這裏是代碼
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 = "[email protected]";
$message = "Just a message";
$subject = "Subject";
mail($to, $message, $subject, "From: $from", "-f$from");
}
}
任何幫助將不勝感激。
將其添加到數據庫的代碼未顯示,但它不會發送郵件 - 在這種情況下,請確保將註冊保存到數據庫的調用位於您發送郵件的部分。 – BugFinder
嗨,感謝,電子郵件正在通過,代碼正好在它下面將它添加到數據庫中,我移動它(只是低於值)和相同的問題。 –
它不能顯示「你的電子郵件地址是無效的」消息,併發送郵件 - 不遵循發佈的代碼 - 如果數據庫插入的代碼與郵件命令不同,那麼它會這樣做與垃圾郵件狀態無關。 – BugFinder