open email by php using imap giving me this error Message: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX

末鹿安然 提交于 2019-12-13 05:25:34

问题


I am trying to open the email messages by php using imap method but it give me an error Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX and this is my code

$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);

回答1:


Try this:

$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());



回答2:


{imap.gmail.com:993/imap/ssl}INBOX

working for me but you have to enable 'Access for less secure apps' on account security or you can try live email account



来源:https://stackoverflow.com/questions/25723068/open-email-by-php-using-imap-giving-me-this-error-message-imap-open-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!