我试图弄清楚为什么如果在输入字段中输入的电子邮件包含.edu域,我的php邮件表单为什么不发送电子邮件。我可以使用表格将其发送到同一封电子邮件,但如果包含收件人要回复的完整edu域地址,则不会发送任何邮件。如果我在邮件发送的输入字段中删除edu甚至仅输入“ u”,则我所指的格式是“ example@mail.universityname.edu”。我进行了搜索,但是在搜索中没有看到同样的问题。我的PHP代码如下。谢谢
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "something@gmail.com";
$email_subject = "Contact Form";
function died($error) {
// your error code can go here
echo "<br /> <br /> We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['date1']) ||
!isset($_POST['date2']) ||
!isset($_POST['charge']) ||
!isset($_POST['hours']) ||
!isset($_POST['subject'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$date1 = $_POST['date1']; // not required
$date2 = $_POST['date2']; //required
$charge = $_POST['charge']; //required
$hours = $_POST['hours']; //required
$subject = $_POST['subject']; // required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
$date_exp='/^(19[5-9][0-9]|20[0-4][0-9]|2050)[-](0?[1-9]|1[0-2])[-](0?[1-9]|[12][0-9]|3[01])$/';
if(!preg_match($date_exp,$date1)) {
$error_message .= 'The first date you entered does not appear to be valid.<br />';
}
if(!preg_match($date_exp,$date2)) {
$error_message .= 'The second date you entered does not appear to be valid.<br />';
}
if(strlen($subject) < 2) {
$error_message .= 'The reason you entered is not long enough.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Employee Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "From Date: ".clean_string($date1)."\n";
$email_message .= "To Date: ".clean_string($date2)."\n";
$email_message .= "Charge To: ".clean_string($charge)."\n";
$email_message .= "Hours: ".clean_string($hours)."\n";
$email_message .= "Reason: ".clean_string($subject)."\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);
?>
echo '<script type="text/javascript"> document.location = "http://xx/thanks.html";</script>'
<?php
}
?>