简体   繁体   中英

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

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

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());
{imap.gmail.com:993/imap/ssl}INBOX

为我工作,但您必须在帐户安全性上启用“访问不太安全的应用程序”,或者可以尝试使用实时电子邮件帐户

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM