2011-03-12 45 views
-2

我有一段代碼,經批准發送郵件到電子郵件地址的郵件。電子郵件未被髮送。我需要在我的Web服務器上配置什麼?發送使用PHP

function mailpassword($email, $password){ 
    //notify that the password has been changed 
    mysqli_select_db($connect,"members"); 

    $query = "select email from users where email = '".$email."'"; 
    $mailquery = mysqli_query($connect,$query); 
    if(!$mailquery) 
    { 
     throw new Exception ('The entered email address could not be found'); 
    } 
    else if($mailquery->num_rows==0) 
    { 
     throw new Exception ('The entered email address could not be found'); 

     //username not in database 
    } 
    //if no errors, send mail 
    else 
    { 
     $row = $mailquery->fetch_object(); 
     $email = $row->email; 
     $from = "From : [email protected] \r\n"; 
     $mesg = "Hey,\n\n You requested for a new password. We have generated a completely random password for you, use it to login.\n\n 
     New Password - ".$password."\r\n 
     Please change this random password to a password of your choice once you log in. To change your password, click on the Accounts tab present in your dashboard.\r\n 

     Cheers\r\n 
     Hap"; 

     if(mail($email, 'Password Change Account Details', $mesg, $from)) 
     { 
      return true; 
      echo "great"; 
     } 
     else 
     { 
      echo "Something went wrong"; 
     } 
    } 

    $mails = mailpassword(); 
} 
+1

你可以測試但不帶'$ from'場。它在':'和'\ r \ n'之前包含無關的空格(如果它是最後一個/唯一的標題,它也應該省略)。 – mario 2011-03-12 14:56:03

+0

@mario - 好點,注意。我將來會這樣做 – 2011-03-12 15:08:02

回答

0

有一個簡單的解決方案以電子郵件的問題:使用託管的解決方案,可確保您的應用程序發送的所有電子郵件獲得通過。有一些替代品,如AmazonPostmark。我們用郵戳取得了巨大成功(不隸屬於雖然外置熱交換器;)

有這個PHP class for Postmark說我還挺自豪的... :-)

這不是直接回答你的問題,但我無論如何希望它有幫助!