2014-07-02 120 views
10

我在Ubuntu 14.02上使用Apache並運行php。我已連接到遠程mssql服務器,因此不需要mysql。使用imap訪問電子郵件

我想知道如何連接到用gmail註冊的電子郵件ID以讀取傳入的電子郵件。

我曾嘗試以下,但它顯示了一個空白的屏幕,而從我的本地主機上運行它:

<?php 

error_reporting('E_ALL'); 
$mailboxPath = "{imap.gmail.com:993/imap/ssl}INBOX"; 
$username = "[email protected]"; 
$password = "mypassword"; 
$imap = imap_open($mailboxPath, $username, $password); 
print_r($imap); 

?> 

我將我的實際Gmail用戶名和密碼,運行程序時。我想知道我是否錯過了一些東西。

非常感謝

+0

什麼'imap_last_error()'的輸出? –

+0

1)你的用戶名和密碼是否正確? 2)將'$ imap = imap_open($ mailboxPath,$ username,$ password);'轉換爲'$ imap = imap_open($ mailboxPath,$ username,$ password)或死('無法連接到Gmail:')imap_last_error ));'。現在您會注意到,爲什麼您無法連接到Gmail。 – pes502

+0

嗨,感謝您的回覆,以下是我的錯誤: 無法連接到Gmail:無法驗證IMAP服務器:[警告]請通過您的網絡瀏覽器登錄:http://support.google.com/郵件/賬號 – user3790233

回答

0

有您激活您的php.ini文件imap.so擴展? extension=imap.so這是問題的本地主機服務器上的basical原因

+0

是的,我已經添加了它.YET不起作用。 – user3790233

+0

所以你可能沒有在你的本地主機 – DanIdle

+0

上激活openSSL,如果它不是一個ssl的麻煩,請使用錯誤信息中的鏈接登錄到你的gmail帳戶,如果你有關於可疑連接的消息並通過輸入您的登錄名和密碼驗證新客戶端 – DanIdle

0

試試這個(你需要打開你的出站中繼):

  1. Log into your account at google.com/a/yourdomain.com
  2. Click the Settings tab and then select Email in the left column.
  3. In the Outbound relay section, select Allow users to send mail through an external SMTP when configuring a "from" address hosted outside your domain.
  4. Click Save changes.
+0

我不確定您的意思是由google.com/a/yourdomain.com。我想要訪問個性化的Gmail收件箱。我沒有看到任何設置或任何選項卡與外撥relay.Thank你。 – user3790233

31

這裏是解決方案:

  1. 登錄到Gmail帳戶,啓用imap。

  2. 讓訪問這裏第一:https://www.google.com/settings/security/lesssecureapps

  3. 轉到:https://accounts.google.com/b/0/DisplayUnlockCaptcha 並啓用訪問。

就是這樣。

當我嘗試使用php上的imap獲取電子郵件時,我遇到了完全相同的問題。 我正在運行完全相同的腳本,我知道它與我的其他Gmail一起工作。

的解決方案是上方和錯誤信息是:

ERROR: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser

+0

當您在帳戶設置中啓用IMAP時,默認的IMAP設置就可以。如果您在移動信息時遇到問題,請確保您的個人資料語言設置中選擇了英語 - 美國。 – Tarik

+2

這個答案應該是接受的標記 –

+0

完美..順利工作... –