2014-02-17 97 views
2

我的郵件功能在在線服務器上。它工作正常。但是不是現在。我很困惑它爲什麼停止發送郵件。它顯示發送電子郵件的消息,但收件箱中未收到電子郵件。PHP郵件功能在我的服務器上不工作?

這裏是我的PHP代碼:

<?php 
if (isset($_POST['submit'])) { 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $phone = $_POST['phone']; 
    $message = $_POST['message']; 

    $headers = "From: " . $email . "\n"; //from address 
    $to = ""; //my mail id 
    $headers .= "MIME-Version: 1.0\n"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; 
    $subject = "Test mail"; 

    $body = '<html> 
     <head> 
      <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
      <title>"."<h3>"."Hello Test,."</h3>". 
    </title> 
     </head> 
     <body><p></p> 
      <p style="color: #00CC66; font-weight:600; font-style:italic; font-size:14px; float:left; margin-left:7px;">You have received an inquiry from your website. Please review the contact information below. 

    :</p>'; 
    if (mail($to, $subject, $body, $headers)) { 
     ?> 
     <h3 style="color:#d96922; font-weight:bold; height:0px; margin-top:1px;">Thank You For Contacting us!!</h3> 

     <?php 
    } else { 

     print_r(error_get_last()); 
    } 
} 

這有什麼錯呢?請幫我找出解決方案。還幫我回應錯誤?

+3

無法在任何地方找到您的「郵件()」代碼.... –

+0

您的郵件功能在哪裏? – Jenz

+0

我更新的代碼,請幫我解決這個問題..這是非常迫切的.. –

回答

6

我想這給一個嘗試,結束每一行\r\n並且還加入了頭(多餘的,因爲它看起來)。另外,在頭文件中聲明charset=utf-8應該足夠了。如果不是,請確保它匹配(現在有一個不匹配)。

<?php 
    $subject = "Test mail"; 
    $to_email = "[email protected]"; 
    $to_fullname = "John Doe"; 
    $from_email = "[email protected]"; 
    $from_fullname = "Jane Doe"; 
    $headers = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html; charset=utf-8\r\n"; 
    // Additional headers 
    // This might look redundant but some services REALLY favor it being there. 
    $headers .= "To: $to_fullname <$to_email>\r\n"; 
    $headers .= "From: $from_fullname <$from_email>\r\n"; 
    $message = "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\r\n 
    <head>\r\n 
    <title>Hello Test</title>\r\n 
    </head>\r\n 
    <body>\r\n 
    <p></p>\r\n 
    <p style=\"color: #00CC66; font-weight:600; font-style: italic; font-size:14px; float:left; margin-left:7px;\">You have received an inquiry from your website. Please review the contact information below.</p>\r\n 
    </body>\r\n 
    </html>"; 
    if (!mail($to_email, $subject, $message, $headers)) { 
    print_r(error_get_last()); 
    } 
    else { ?> 
    <h3 style="color:#d96922; font-weight:bold; height:0px; margin-top:1px;">Thank You For Contacting us!!</h3> 
    <?php 
    } 
    ?> 

我也想替換像這樣的第一行,以避免告示/錯誤:

if ($_POST && isset($_POST['submit']) && isset($_POST['name']) && isset($_POST['email']) && !empty($_POST['name']) && !empty($_POST['email'])) { 
+0

感謝您的幫助......現在工作正常.. :) –

相關問題