邮件功能不起作用....我无法理解

时间:2016-11-16 05:36:01

标签: php html email phpmailer

我制作了一个用于发送邮件的PHP脚本.....但我只收到一条“{ERROR”消息,该消息处于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";
}

2 个答案:

答案 0 :(得分:3)

似乎邮件功能返回false。 mail函数总是返回true或false。因此,如果邮件无法正常工作,您无法轻易找出问题所在。可能是SMTP错误,连接错误或其他任何问题。有可能的数量。  have a look at this link

答案 1 :(得分:2)

这是我假设的问题。

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();}
 }