2009-10-27 129 views
0

我正在使用AJAX的PHP郵件表單,它不發送任何郵件。我在這裏錯過了什麼?爲什麼我的AJAX表單不發送電子郵件?

send.php

<?php 
    error_reporting(E_NOTICE); 

    function valid_email($str) 
    { 
     return (! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE; 
    } 

    if($_POST['first_name']!='' && $_POST['last_name']!='' && $_POST['e_mail']!='' && valid_email($_POST['e_mail'])==TRUE && strlen($_POST['message'])>30) 
    { 
     $to = '[email protected]'; 
     $headers = 'From: '.$_POST['e_mail'].''. "\r\n" . 
       'Reply-To: '.$_POST['e_mail'].'' . "\r\n" . 
       'X-Mailer: PHP/' . phpversion(); 
     $subject = "Hello! I'm testing my new ajax email that I got from roscripts.com"; 
     $message = htmlspecialchars($_POST['message']); 

     if(mail($to, $subject, $message, $headers)) 
     {//we show the good guy only in one case and the bad one for the rest. 
      echo 'Thank you '.$_POST['first_name'].'. Your message was sent'; 
     } 
     else { 
      echo "Message not sent. Please make sure you're not 
       running this on localhost and also that you 
       are allowed to run mail() function from your webserver"; 
     } 
    } 
    else { 
     echo 'Please make sure you filled all the required fields, 
     that you entered a valid email and also that your message 
     contains more then 30 characters.'; 
    } 
?> 
+3

什麼得到迴應? – Greg 2009-10-27 12:23:35

+0

消息得到迴應。 – HollerTrain 2009-10-27 12:34:18

回答

0

在PHP您的電子郵件設置?首先檢查一下,否則在這裏我看不到任何問題。你應該從這個if/else塊獲得某種輸出。

我首先回顧一下PHP錯誤日誌,看看你的mail()fn是否工作。這可能是原因。

+0

這是消息錯誤。如果消息少於30則顯示錯誤! – HollerTrain 2009-10-27 13:26:12

相關問題