2014-06-21 58 views
-2

這是我的郵件功能php,但它不能正常工作。 請幫我解決我的問題。php郵件功能在if條件下不工作

<?php 

if($_POST && array_key_exists('submit_contact',$_POST)){ 
$to = "[email protected]"; 
$subject="Contact Form"; 
$fname =$_POST['fname']; 
$email=$_POST['email']; 
$telno=$_POST['telno']; 
$mess=$_POST['your-message']; 
$body = "<html><body><div>"; 
$body .= "<h1><b><u>Contact Form Details</u></b></h1>"; 
$body .= "<h3>Full Name:\t". $fname."</h3>"; 
$body .= "<h3>E-mail:\t". $email."</h3>"; 
$body .= "<h3>Telephone:\t". $telno."</h3>"; 
$body .= "<h3>Message:</h3>\t<p>". $mess."</p>"; 
$body .= "</div></body></html>"; 
$headers = "From:". $email. "\r\n"; 
$headers .= "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
    $headers .= "Reply-To:".$email."\r\n"."Return-Path:". $email . "\r\n". "X-Mailer: PHP/" . phpversion(); 
    $subjectr="Confirmation Notice"; 
    $messages="<html><body>"; 
     $messages .="<div style=''><a href='index.html'><img src='http://example.com/images/logo.png' alt='logo'/></a></div>"; 
    $messages .="<table style=''width='600px'><tr><td bgcolor='black'height='30px'><font style='padding-left:10px;color:#d8b53e;font-size:20px;'>Reference # 786733</font></td> </tr>"; 
    $messages .="<td><br/>Dear Concerned,<br/>Thank you for considering</td></tr>"; 
    $messages .="<tr><td>&#169; 2014</td></tr></table>"; 
$messages .="</body></html>"; 
    $headerss = "From:".$to. "\r\n"; 
    $headerss .= "MIME-Version: 1.0" . "\r\n"; 
    $headerss .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
    $headerss .= "Reply-To:".$to."\r\n"."Return-Path:".$to. "\r\n". "X-Mailer: PHP/" . phpversion(); 
if(mail($to,$subject,$body,$headers)){ 
    mail($email,$subjectr,$messages,$headerss); 
     echo "<script> window.alert('E-mail successfully Sent!');</script>"; 
} 
else{ 
echo "<script> window.alert('Error Try Again Please');</script>"; 
} 
} 
?> 
+0

http://stackoverflow.com/questions/how-to-ask – Rufinus

+0

plz提供你的完整代碼 –

+0

是因爲你有兩個'$ headerss'嗎?也許打開error_reporting,應該很容易排除故障..或在'$ subjectr' – Ben

回答

1

首先,如果您將函數放入if條件中,它將自動調用。 所以,如果你寫

if(mail($to, $subject, $body, $headers) { 
    echo "Send!"; 
} else { 
    echo "Error"; 
} 

電子郵件將得到發送和成功則返回True。

+0

是的,你是對的,但如果我發送另一封確認郵件給發件人郵件($ email,$ subjectr,$ messages,$ headerss); // NOt工作 – user3757908

+0

你確定你做的一切都對嗎?官方文檔:http://www.php.net/manual/de/function.mail.php – obsilp

+0

是的,並且剩下的所有代碼都沒有錯誤並且工作正確 – user3757908