我需要帮助来扩展我的 PHP 脚本。我需要必填字段和注册表单中电子邮件字段的验证。
这是我的代码,我尝试使用不同的 if 和 echo 代码,但在其中没有任何作用。
<?php
$email = $_POST['email'];
$from = $email;
$to = "xy@gmail.com";
$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\">";
}
?>
代码有效,电子邮件已送达,但如果未填写字段,则表单不应该成功。提前谢谢您。