【发布时间】:2016-03-30 16:47:40
【问题描述】:
我的 PHP 代码:
<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'my gmail id';
$password = 'my gmail password';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
/* output the email header information */
$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
?>
问题是,首先我收到类似的错误 无法连接到 Gmail:登录失败次数过多,在我从 $hostname 中删除 /SSL 之后,我会收到类似 无法连接到的错误Gmail:[关闭] IMAP 连接中断(服务器响应)。
我做了所有与连接相关的事情,例如启用 pop3 和 Imap、解锁 Google 帐户 以及 打开不太安全应用程序。
但是,我找不到实际的问题?
【问题讨论】:
-
分享一下javascript、jQuery、php相关的代码?尝试一些东西然后来这里寻求帮助。恐怕这个问题很可能会被关闭。
-
@Jai 感谢鼓励我,我会尝试从 gmail 获取电子邮件,但是,我每次都会出错。如果您知道请帮助我,我会更改我的问题以便更好地了解。