2011-01-06 132 views
0

我正在使用下面的表格。我正在使用頁面contact.php來顯示錶單並提交表單。該表格驗證並說,發送的電子郵件,但當我檢查它沒有顯示的電子郵件。PHP電子郵件表格不能正常工作

PHP:

  <?php 
      function spamcheck($field) 
      { 
     //filter_var() sanitizes the e-mail 
     //address using FILTER_SANITIZE_EMAIL 
     $field=filter_var($field, FILTER_SANITIZE_EMAIL); 

     //filter_var() validates the e-mail 
     //address using FILTER_VALIDATE_EMAIL 
     if(filter_var($field, FILTER_VALIDATE_EMAIL)) 
      { 
     return TRUE; 
      } 
     else 
     { 
     return FALSE; 
      } 
     } 

      if (isset($_REQUEST['email'])) 
      {//if "email" is filled out, proceed 

      //check if the email address is invalid 
      $mailcheck = spamcheck($_REQUEST['email']); 
      if ($mailcheck==FALSE) 
      { 
       echo "Invalid input"; 
       } 
      else 
      {//send email 
     $email = $_REQUEST['email'] ; 
      $subject = $_REQUEST['subject'] ; 
     $message = $_REQUEST['message'] ; 
     mail("[email protected]", "Subject: $subject", 
     $message, "From: $email"); 
     echo "Thank you for using our mail form"; 
      } 
     } 
     else 
     {//if "email" is not filled out, display the form 
     echo "<form method='post' action='contact.php'> 
     Email: <input name='email' type='text' /><br /> 
     Subject: <input name='subject' type='text' /><br /> 
     Message:<br /> 
     <textarea name='message' rows='15' cols='40'> 
     </textarea><br /> 
     <input type='submit' /> 
     </form>"; 
     } 
      ?> 

回答

2

檢查你的PHP日誌。也許它確實失敗,因爲它沒有在您的應用程序或PHP中配置的SMTP客戶端在嘗試發送郵件時使用。

+0

看起來像一個服務器的問題。檢查它。 – AAA 2011-01-06 22:29:27

3

在您的表單中顯示「謝謝」信息時,表示郵件功能已運行,而不是成功。 當PHP郵件函數成功並且錯誤時,它將返回true。 能否請您嘗試類似:

if(mail("[email protected]", "Subject: $subject",$message, "From: $email")){ 
echo "Thank you for using our mail form"; 
}else{ 
echo "hmm... seems the mail cannot be sent"; 
} 

也允許在php.ini郵件功能?

+0

看起來像服務器問題。檢查它。 – AAA 2011-01-06 22:30:12

0

嘗試從您的聯繫人地址發送郵件。你確定你的電子郵件帳戶接受這些欺騙電子郵件嗎? Gmail會將那些不在您聯繫人列表中的地址的php電子郵件發送到垃圾郵件。 嘗試在另一個電子郵件帳戶上進行測試。這是值得的拍攝。

可以運行其他測試使用警報來檢索郵件()的返回,以檢查它是否成真或假的..

alert(mail([email protected], subject, message, email));