使用imap访问电子邮件 [英] Access emails using imap
问题描述
我在Ubuntu 14.02上使用Apache,并在同一版本上运行php.我已连接到远程mssql服务器,因此不需要mysql.
I am using Apache on Ubuntu 14.02 and running php on the same.I have connected to a remote mssql server hence no need of mysql .
我想知道如何连接到用gmail注册的电子邮件ID,以便阅读传入的电子邮件.
I want to know how to connect to an email id registered with gmail in order to read the incoming emails .
我尝试了以下操作,但是从本地主机运行它时显示空白屏幕:
I have tried the below , but it shows a blank screen while running it from my localhost :
<?php
error_reporting('E_ALL');
$mailboxPath = "{imap.gmail.com:993/imap/ssl}INBOX";
$username = "my_email@gmail.com";
$password = "mypassword";
$imap = imap_open($mailboxPath, $username, $password);
print_r($imap);
?>
我正在运行程序时插入实际的Gmail用户名和密码.我想知道我是否想念一些东西.
I am inserting my actual gmail username and password while running the program . I want to know if i am missing something .
非常感谢
推荐答案
以下是解决方案:
-
登录到您的Gmail帐户,启用imap.
Login to your gmail account, enable imap.
首先在此处进行访问: https://www.google.com/settings/security/lesssecureapps
Let the access here first: https://www.google.com/settings/security/lesssecureapps
转到: https://accounts.google.com/b/0/DisplayUnlockCaptcha 并启用访问权限.
Go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha and enable access.
就是这样.
当我尝试在php上使用imap接收电子邮件时,我遇到了完全相同的问题. 我运行的脚本完全相同,我知道它可以与其他gmail一起使用.
I had the exact same problem when I try to get emails with imap on php. I was running the exact same script that I know it works with my other gmail.
解决方案在上方,错误消息为:
The solution is above and the error message was:
错误:无法通过IMAP服务器进行身份验证:[ALERT]请通过网络浏览器登录
ERROR: Can not authenticate to IMAP server: [ALERT] Please log in via your web browser
这篇关于使用imap访问电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!