2013-02-05 57 views
1

我已將兩個文件都升級到服務器,但是當我提交表單時,感謝消息出現,但我的收件箱中沒有郵件。 PLZ幫助我。我的聯繫人表單不發送郵件

我的HTML頁面

<form name="htmlform" method="post" action="html_form_send.php"> 
<table width="450px"> 

</tr> 





<tr> 
<td valign="top"> 
<label for="first_name">First Name *</label> 
</td> 
<td valign="top"> 
<input type="text" name="first_name" maxlength="50" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top""> 
<label for="last_name">Last Name *</label> 
</td> 
<td valign="top"> 
<input type="text" name="last_name" maxlength="50" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
<label for="email">Email Address *</label> 
</td> 
<td valign="top"> 
<input type="text" name="email" maxlength="80" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
<label for="telephone">Telephone Number</label> 
</td> 
<td valign="top"> 
<input type="text" name="telephone" maxlength="30" size="30"> 
</td> 
</tr> 
<tr> 
<td valign="top"> 
<label for="comments">Comments *</label> 
</td> 
<td valign="top"> 
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea> 
</td> 
</tr> 
<tr> 
<td colspan="2" style="text-align:center"> 
</td> 
</tr> 
</table> 
</form> 

我有兩個文件uploded到服務器,但是當我提交表單的感謝消息傳出,但有沒有郵件在我的收件箱。 PLZ幫助我。

我的PHP編碼

<?php 
if(isset($_POST['email'])) { 

    // CHANGE THE TWO LINES BELOW 
    $email_to = "[email protected]"; 

    $email_subject = "website form submissions"; 


    function died($error) { 
     // your error code can go here 
     echo "We're sorry, but there's errors found with the form you submitted.<br /><br />"; 
     echo $error."<br /><br />"; 
     echo "Please go back and fix these errors.<br /><br />"; 
     die(); 
    } 

    // validation expected data exists 
    if(!isset($_POST['first_name']) || 
     !isset($_POST['last_name']) || 
     !isset($_POST['email']) || 
     !isset($_POST['telephone']) || 
     !isset($_POST['comments'])) { 
     died('We are sorry, but there appears to be a problem with the form you submitted.');  
    } 

    $first_name = $_POST['first_name']; // required 
    $last_name = $_POST['last_name']; // required 
    $email_from = $_POST['email']; // required 
    $telephone = $_POST['telephone']; // not required 
    $comments = $_POST['comments']; // required 

    $error_message = ""; 
    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 
    if(!preg_match($email_exp,$email_from)) { 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 
    } 
    $string_exp = "/^[A-Za-z .'-]+$/"; 
    if(!preg_match($string_exp,$first_name)) { 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 
    } 
    if(!preg_match($string_exp,$last_name)) { 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 
    } 
    if(strlen($comments) < 2) { 
    $error_message .= 'The Comments you entered do not appear to be valid.<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 .= "First Name: ".clean_string($first_name)."\n"; 
    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 
    $email_message .= "Email: ".clean_string($email_from)."\n"; 
    $email_message .= "Telephone: ".clean_string($telephone)."\n"; 
    $email_message .= "Comments: ".clean_string($comments)."\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); 
?> 

<!-- place your own success html below --> 

Thank you for contacting us. We will be in touch with you very soon. 

<?php 
} 
die(); 
?> 
+1

你是如何提交表單的? –

回答

0

這可能是該郵件被阻塞由接收服務器,因爲它看起來像發送者是無效的,這似乎類似於垃圾郵件。

如果您有權訪問它,請檢查服務器上的過濾器日誌。這應該在cPanel中作爲「跟蹤電子郵件」提供。如果您的郵件被阻止,您會在列表中看到它,並在其上標記指示問題的標記,將鼠標懸停在上面,您將看到原因。

如果是這種情況,原因是像「發件人驗證失敗」,Y歐可能會喜歡「從地址信封」附加參數嘗試-f

mail($email_to, $email_subject, $email_message, $headers, "-f $email_from"); 

郵件功能的參考,其中包括注意關於 「附加參數」,明確-f sendmail的:

http://php.net/manual/en/function.mail.php

的additiona可以使用l_parameters參數將附加 標誌作爲命令行選項傳遞給發送郵件時配置爲使用 的程序,如sendmail_path配置 設置所定義。例如,當使用帶有-f sendmail選項的sendmail時,可以使用它來設置信封發件人 地址。

,所述網絡服務器運行作爲應添加作爲受信任的用戶 到sendmail配置,以防止被添加到所述消息從一個 「X-警告」報頭當包絡發送者(-f),使用設定的用戶 這種方法。對於sendmail用戶,這個文件是/ etc/mail/trusted-users。

+0

它不起作用 –

0

$ email_to ='[email protected]';

$ email_subject ='subject';

$ email_message ='hello';

$ headers ='From:[email protected]'。 「\ r \ n」。

'Reply-To: [email protected]' . "\r\n" . 

'X-Mailer: PHP/' . phpversion(); 

mail($ email_to,$ email_subject,$ email_message,$ headers);

試試這個,讓我知道

+0

它不起作用 –

相關問題