邮件功能不工作了,我不知道原因


Mail function doesn't work....I can't get the reason

我制作了一个PHP脚本用于发送邮件.....但我只得到一个"错误"消息,这是在else条件下…我收不到邮件.....这意味着我的邮件功能不起作用了…

有什么问题吗?

$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$comments=$_POST['comments'];
$verify=$_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(!isset($verify) || trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}

$to="contact@yoursite.com";
$subject='Inquiry';
$message='Name : '.$name."<br />".'Email : '.$email."<br />".'Mobile : '.$phone."<br />".'Message : '.$comments;
$headers  = "MIME-Version: 1.0'r'n";
$headers .= "Content-type: text/html; charset=utf-8'r'n";
$headers .= "From: ".$email."'r'n";
$headers .= "Reply-To: ".$email."'r'n";
$headers .= "X-Mailer: PHP/".phpversion();
$mail=mail($to, $subject, $message, $headers);
if($mail) {
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h4>Email Sent Successfully</h4>";
echo "<p>Thank you $name, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
}
else {
echo "ERROR";
}

似乎邮件函数返回false。邮件函数总是返回真或假。因此,如果邮件无法正常工作,你就无法轻易找出问题所在。它可能是SMTP错误,连接错误或任何东西。有很多可能性。看看这个链接

我想这就是问题所在。

if(!isEmail($email)) {}

IsEmail不是一个功能,除非你的意思是is_email,我认为是wordpress?或者我知道的一个但是你可以使用filter_var和filter_email

这个也可以

if (filter_var($email, FILTER_VALIDATE_EMAIL)) { //Return True Is Valid
echo "HEY IM VALID";
}

我也会像这样重做if语句

foreach ($_POST as $item => $value){
    if($value === ""){ echo $item." must be a valid input"; exit();}
 }