我试图通过php使用imap方法打开电子邮件但它给我一个错误无法打开流{imap.gmail.com:993/imap/ssl}INBOX这是我的代码
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'nohamedtemraz92@gmail.com';
$password = '0129799169mohamed';
/* 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);
$output.= 'Name: '.$overview[0]->from.'</br>';
$output.= 'Email: '.$overview[0]->message_id.'</br>';
}
echo $output;
}
/* close the connection */
imap_close($inbox);
答案 0 :(得分:0)
试试这个:
$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$inbox = imap_open($hostname,$username ,$password) or die('Cannot connect to Gmail: ' imap_last_error());
答案 1 :(得分:0)
{imap.gmail.com:993/imap/ssl}INBOX
为我工作,但你必须启用“访问不太安全的应用程序”#39;关于帐户安全或您可以尝试实时电子邮件帐户