2012-12-15 92 views
1

可能重複:
Mail not being received by hotmail.com沒有收到PHP郵件?

我有我的網站上這個簡單的形式,當它送入我的Hotmail帳戶,甚至沒有垃圾郵件文件夾,我不接收電子郵件。

這裏是表單代碼:

<form action="mail.php" method="POST"> 
    <p><label title="Name">Name:</label><br /> 
     <input type="text" name="name" autocomplete="on" required="required"></p> 
    <p><label title="Email">Email:</label><br /> 
     <input type="text" name="email" autocomplete="on" required="required"></p> 
    <p><label title="About">My message is about...</label><br /> 
     <select name="about"> 
      <option value="general">General Query</option> 
      <option value="wedding">Wedding</option> 
      <option value="corporate">Corporate Event or Trade Show</option> 
      <option value="other">Other Event</option> 
     </select> 
    <p><label title="Message">Message:</label><br /> 
     <textarea name="message" rows="6" cols="25" required="required"></textarea></p> 
    <input type="submit" value="Send"> 
</form> 

而且mail.php文件: 「謝謝!」

<?php 
     $name = $_POST['name']; 
     $email = $_POST['email']; 
     $message = $_POST['message']; 
     $about = $_POST['about']; 
     $formcontent="From: $name \n About: $about \n Message: $message"; 
     $recipient = "[email protected]"; 
     $subject = "Contact Form"; 
     $mailheader = "Reply-To: $email \r\n"; 
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
    echo "Thank You!"; 
?> 

我最終看到一個頁面顯示但沒有收到電子郵件。

+1

檢查您的日誌。只要檢查你的日誌。然後告訴我們郵件是否發送。不,你永遠不會知道郵件是否已收到。很容易從現有的問答資料中瞭解這個網站的信息。另外:http://php.net/mail有一個*返回值*,檢查它。很容易進行故障排除。 – hakre

+0

爲什麼不使用SMTP服務 –

回答

3

郵件投遞是一項棘手的業務......僅僅因爲您發送郵件並不意味着任何人都會收到郵件。許多接收服務器如果不符合某些標準,會簡單地忽略傳入的消息(根據我的經驗,Gmail和Hotmail特別傾向於默默拒絕傳送,因此甚至不會在SPAM中結束)。有幾件事情,以確保你已經做了:

1)你已經設置了PTR/SPF(反向查找)項在您的DNS記錄

2)確保你不上任何黑名單(http://www.mxtoolbox.com/blacklists.aspx

3)擴大你的頭

$headers = "MIME-Version: 1.0\r\n" 
      ."Content-Type: $contentType; charset=utf-8\r\n" 
      ."Content-Transfer-Encoding: 8bit\r\n" 
      ."From: =?UTF-8?B?". base64_encode("Your sending display name") ."?= <$from>\r\n" 
      ."Reply-To: $replyTo\r\n" 
      ."X-Mailer: PHP/". phpversion(); 

但是,如果你真的想確保郵件獲得通過,發送郵件via SMTP。你永遠不能保證郵件傳遞,但它會更可靠。如果您沒有發送大量郵件,則可以嘗試使用Mandrill或類似服務爲您轉發電子郵件。

0

您可以使用以下方法。成功返回true。

function sendMail($email, $subject, $message) 
{ 
    $supportEmail = '[email protected]'; 
    $from = 'Abc'; 
    $msg = $message; 
    $from = str_replace(' ', '-', $from); 
    $frm = $from.' <'.$supportEmail.'>'; 
    preg_match("<(.*)@(.*\..*)>", $frm, $match); 

    ///////////////////Headers///////////////// 
    $hdr=''; 
    $hdr.='MIME-Version: 1.0'."\n"; 
    $hdr.='content-type: text/html; charset=iso-8859-1'."\n"; 
    $hdr.="From: {$frm}\n"; 
    $hdr.="Reply-To: {$frm}\n"; 
    $hdr.="Message-ID: <".time()."@{$match[2]}>\n"; 
    $hdr.='X-Mailer: PHP v'.phpversion(); 
    [email protected]($email, $subject, $msg, $hdr); 
    if($x==0) 
    { 
     $email=str_replace('@','\@', $email); 
     $hdr=str_replace('@','\@',$hdr); 
     [email protected]($email, $subject, $msg, $hdr); 
    } 
    return $x; 
}