2010-12-15 121 views
0

我正在嘗試使用phpMailer和GMail SMTP發送電子郵件。它很好地發送電子郵件到其他Gmail帳戶,但發送到雅虎的郵件永遠不會到達那裏。我讀過關於使用IP地址等進行調試,但我不擅長這方面的技術?PHPMailer Lite&GMAIL SMTP:電子郵件未發送至Yahoo Mail,如何調試?

這裏是代碼:

$mail->Mailer='smtp'; 

    try { 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->SMTPSecure = "tls";     // sets the prefix to the servier 
    $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
    $mail->Port  = 587;     // set the SMTP port for the GMAIL server 
    $mail->Username = "__email__"; // GMAIL username 
    $mail->Password = "__pass__";   // GMAIL password 
    $mail->SMTPDebug = 2; 

    $a = md5(uniqid(rand(), true)); //create a unique validation code 

    //These are the variables for the email 

    $mail->AddAddress (trim($_POST['email']),trim($_POST['username'])); // this is the email address collected form the form 
    $mail->Subject = "Registration"; // Subject 
    $mail->Body = "Thank you for registering\n your security code is ".$a; 
    $mail->Send(); 


    echo "check your email to complete registration"; 
    } catch (phpmailerException $e) { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
    } catch (Exception $e) { 
    echo $e->getMessage(); //Boring error messages from anything else! 
    } 

    $mail->ClearAddresses(); 

更新:發現了問題:我們的服務器已經被雅虎(不是我的錯) 列入黑名單,所以這是一個浪費一天和半。

+0

你確定郵件不被逮住的垃圾郵件過濾器,你可以檢查 – 2010-12-15 02:33:39

+0

我查耶第一件事情沒有任何地方的郵件沒有 – JIStone 2010-12-15 02:34:35

回答

0

由於它與Gmail用戶合作,我的客人是某些phpMailer沒有正確發送您的用戶名和密碼。如果您未通過身份驗證,gmail服務器將不會接受中繼電子郵件。

一個問題,爲什麼你不使用自己的電子郵件服務器,這將有助於調試,並知道爲什麼不發送電子郵件。

+0

原因,除了Gmail的一個是第一件事情我得到了一半的工作......我知道我會改變$ mail->主機到本地主機,但我不知道其他什麼。 – JIStone 2010-12-15 02:44:50

+0

@Jones:我認爲你應該使用你自己的服務器。 Gmail的限制,但我認爲你的使用是邊界線,再加上在這種情況下,你無法檢查任何日誌或進行任何深入的調試。 – RageZ 2010-12-15 02:46:19

+0

是的好的我會找一些教程 – JIStone 2010-12-15 02:47:28

0

而不是gmail我建議你使用Google App Engine's email service。它爲你做了一切繁重的工作。另外,因爲gmail有一個發送限制,而應用程序引擎的要高得多。它還有一個慷慨的免費配額(每天1000個收件人)

下面是一個從當前登錄用戶發送消息的示例,使用login_required註釋將用戶重定向到登錄頁面(如果它們不是在簽署:??。

from google.appengine.api import mail 
from google.appengine.api import users 
from google.appengine.ext import webapp 
from google.appengine.ext.webapp.util import login_required 

class InviteFriendHandler(webapp.RequestHandler): 
    @login_required 
    def post(self): 
     to_addr = self.request.get("friend_email") 
     if not mail.is_email_valid(to_addr): 
      # Return an error message... 
      pass 

     message = mail.EmailMessage() 
     message.sender = users.get_current_user().email() 
     message.to = to_addr 
     message.body = """ 
I've invited you to Example.com! 

To accept this invitation, click the following link, 
or copy and paste the URL into your browser's address 
bar: 

%s 
     """ % generate_invite_link(to_addr) 

     message.send()