好的,所以我在谷歌搜索了一段时间后找不到这个,我试图在 php 的错误页面上有一个后退按钮,现在它会说“电子邮件错误”“名字错误”请回去再试一次,但我希望能够在那里有一个按钮,因为我在这些表单的页面上有多个 iFrame,我尝试的所有内容都给我 php 错误,我不知道还有什么做!
<?php
if(isset($_POST['email'])) {
function died($error) {
echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name'];
$email_to = $_POST['email'];
$comments = $_POST['comments'];
$email_from = $_POST['emailf'];
$email_subject = $_POST['emailt'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Dear ".clean_string($first_name);
$email_message .= ",\n\n".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Your Email has been sent, please verify!
<form><input type="button" value="Back" onClick="history.back();return true;"></form>
<?php
}
die();
?>