2013-04-17 36 views
0

如果滿足所有條件並回顯「成功」,那麼以下腳本應該發送電子郵件。這裏的問題是它返回「成功」,但電子郵件沒有被髮送。我盡力找出問題所在,但無法弄清楚,因爲我是PHP新手。所以我正在尋找任何可能的幫助。任何幫助將不勝感激。預先感謝您PHP消息發送腳本不起作用

$sql = "SELECT id, username FROM user WHERE email='$e' AND activated='1' LIMIT 1"; 
    $query = mysqli_query($db_conx, $sql); 
    $numrows = mysqli_num_rows($query); 
    if($numrows > 0){ 
     while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
      $id = $row["id"]; 
      $u = $row["username"]; 

     $emailcut = substr($e, 0, 4); 
     $randNum = rand(10000,99999); 
     $tempPass = "$emailcut$randNum"; 
     $hashTempPass = md5($tempPass); 
     $sql = "UPDATE useroptions SET temp_pass='$hashTempPass' WHERE username='$u' LIMIT 1"; 
     $query = mysqli_query($db_conx, $sql); 
     $to = "$e"; 
     $from = "[email protected]"; 
     $headers ="From: $from\n"; 
     $headers .= "MIME-Version: 1.0\n"; 
     $headers .= "Content-type: text/html; charset=iso-8859-1 \n"; 
     $subject ="GeniusFree Password Reset"; 
     $msg = '<h2>Hello '.$u.'</h2><p>This is an automated message from GeniusFree. If you did not recently initiate the Forgot Password process, please disregard this email.</p><p>You indicated that you forgot your login password. We can generate a temporary password for you to log in with, then once logged in you can change your password to anything you like.</p><br /><p><a href="http://www.geniusfree.net/passwordreset.php?u='.$u.'&p='.$hashTempPass.'">Click here now to apply the temporary password shown below to your account</a></p><p>If you do not click the link in this email, no changes will be made to your account. In order to set your login password to the temporary password you must click the link above.</p>'; 
     if(mail($to,$subject,$msg,$headers)) { 
      echo "success"; 
      exit(); 
     } else { 
      echo "email_send_failed"; 
      exit(); 
     }} 
+0

我可能需要調試的步驟。首先,回顯你發送給郵件功能的所有變量。他們看起來正確嗎?也許你正在發送一個不同於你想象的電子郵件地址。第二:你運行的服務器是否允許php Mail?一些服務器對您可以使用和不能使用的內容有限制。 – jeremysawesome

+0

檢查垃圾郵件。可能你的郵件會在那裏。 –

+1

如果電子郵件是發送的,則mail()函數返回true,但它不能告訴你它是否成功發送。 –

回答

1

檢查MX條目設置。最高優先級爲0.如果您在主機中使用郵件服務器。第一項應該是這樣的優先級號碼0 ---> mail.yoursite.com。

另一種調試方法是使用電子郵件跟蹤路由。你可以在cpanel中做到這一點。

希望這會有所幫助。

-1

您是否在本地主機上運行它?如果是這樣,它可能不會在那裏工作,請在Web主機上測試它並讓我知道結果。

+0

這必須是評論,而不是答案。 – sectus

+0

@sectus他沒有必要的代表評論。 – asprin

+0

在Web主機以及本地服務器上測試... –

0

首先,您需要配置php以從您的服務器發送電子郵件,如果您在本地主機上運行代碼,那麼您必須配置您的php.ini文件以發送電子郵件,並且如果代碼在虛擬主機服務器上運行,與他們聯繫,針對此問題, 詳細的配置信息可以參考send mail using xampp in php

,如果你使用的是像WAMP另一個本地服務器,那麼你有你的服務器上單獨(下載)安裝sendmail的效用。

希望這適用於你