2013-08-01 87 views
0

我有這段代碼。它打印「郵件發送成功」,但我的郵箱裏沒有來自我的測試的消息。php - 發送電子郵件不工作

下面是HTML代碼:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Basic Email Form</title> 
    <style> 
     * { 
      margin:0; 
      padding:0; 
     } 
     input, textarea { 
      margin:10px; 
      font-family:Arial, sans-serif; 
      padding:10px; 
     } 
     input { 
      width:280px; 
      height:40px; 
     } 
     textarea { 
      width:280px; 
      height:120px; 
     } 
    </style> 
</head> 
<body> 
    <form action="submit.php" method="post"> 
     <input type="text" name="name" placeholder="Name" /><br /> 
     <input type="text" name="from" placeholder="Email" /><br /> 
     <textarea placeholder="Message" name="message"></textarea><br /> 
     <input type="submit" value="Submit" /> 
    </form> 
<body> 
</html> 

PHP文件:

<?php 
    $to = "[email protected]"; 
    $subject = "This is subject"; 
    $message = "This is simple text message."; 
    $header = "From:".$_POST['from']." \r\n"; 
    $retval = mail ($to,$subject,$message,$header); 
    if($retval == true) 
    { 
     echo "Message sent successfully..."; 
    } 
    else 
    { 
     echo "Message could not be sent..."; 
    } 
?> 
+0

可能去了垃圾文件夾? – tonoslfx

+2

您最好檢查一下您的郵件服務器配置,因爲僅僅從mail()函數返回TRUE值並不能確保郵件已經到達目的地。 –

+0

@ kalpeshpatel你打敗了我,嘿! – Majo0od

回答

0

檢查垃圾郵件文件夾,它usualy使用PHP的mail()

我會在發送時到達那裏建議您爲初學者使用類似https://github.com/Synchro/PHPMailer的內容。

然後,您可以添加smtp驗證和服務器設置(例如您的gmail憑證),這是確保交付的最安全方式之一,並且可以避免垃圾郵件文件夾。

0

正如Kalpesh所說,檢查服務器配置,這可能會阻止該消息。另外檢查你的垃圾/批量文件夾總是一個好主意,以防萬一。

0

我已在我的網絡服務器中檢查此代碼。它工作正常。請檢查您的服務器配置。