我需要幫助來擴展我的PHP腳本。我需要填寫表格中的必填字段和驗證電子郵件字段。使用必填字段和驗證擴展PHP表格
這是我的代碼,我試過使用不同的if和echo代碼,但是沒有任何工作在這個範圍內。
<?php
$email = $_POST['email'];
$from = $email;
$to = "[email protected]";
$subject = "SIGN UP";
$emailbody = "";
$emailbody .= "Email: " . $email . "\n";
$header = "";
$header .= "From:" . $from . " \n";
$header .= "Content-Type:text/plain;charset=utf-8";
// Sending message
$success = mail($to, $subject, $emailbody, $header);
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=confirmation_signup.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
該代碼工作,電子郵件獲得交付,但如果字段未填寫,表單應該是不成功的。
我的答案對您有幫助嗎? – Hassaan