2016-11-16 46 views
1

我做了一個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="[email protected]"; 

$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"; 
} 
+0

好 - 你檢查了你的PHP配置是否正確,並有一個SMTP服務器用於發送郵件? –

回答

2

這是我假設的問題。

if(!isEmail($email)) {} 

IsEmail是不是一個fundstion,除非你的意思是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();} 
} 
+0

好的... bt其驗證問題...我想解決郵件問題.... plz幫助我.. – Siddhu

+0

你的郵件結構很好,並且確實發送郵件,可能想檢查你的主機,他們是否允許郵件功能最免費託管塊它但味精我起來虐待給我在我的託管服務器上的免費帳戶 –

+0

否則如果(trim($ verify)!='4'){ echo'

Attention! The verification number you entered is incorrect.
'; exit(); } 確保$ _POST ['verify'] = 4 –

3

似乎郵件函數返回false。郵件功能總是返回true或false。所以你不能很容易地發現,如果郵件沒有工作,很容易出錯。它可能是SMTP錯誤,連接錯誤或任何東西。有可能性的數量在那裏。 have a look at this link

+0

沒有SMTP錯誤....它的東西不同...可能是腳本問題... PLZ解決這個問題....網站是現場.. – Siddhu

+0

$ checkmail = mail('[email protected]','我的主題',$ message); if($ check){echo'sent!';} else {print_r(error_get_last())}; –

+0

您的腳本是正確的。我認爲問題在於您的服務器配置。請交叉檢查一次。相同的代碼在我的機器上工作。 –