Sudden PHP Error “Warning: imap_open() [function.imap-open]: Couldn't open stream”

前端 未结 5 1900
忘掉有多难
忘掉有多难 2021-01-20 11:54

Okay, this code \'was\' working perfectly and then I started playing around with it in order to let others connect to their e-mails and as you do ran into a few open stream

相关标签:
5条回答
  • 2021-01-20 12:15
    resource imap_open(
        string $mailbox , 
        string $username , 
        string $password [, 
        int $options = 0 [, 
        int $n_retries = 0 [,  
        array $params = NULL ]]] 
    )
    
    0 讨论(0)
  • 2021-01-20 12:23

    Please use the below code to connect successfully,

    $hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}";
    
    $mailbox = imap_open($hostname, 'admin@artisancodesmith.com', 'PASSWORD');
    
    if ($mailbox) 
    {
        // do work....
    }
    
    0 讨论(0)
  • 2021-01-20 12:30

    I have tried this an works perfectly fine for me

    $inbox = imap_open("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", 'username', 'password')
                 or die('Cannot connect to Gmail: ' . imap_last_error());
    
    $emails = imap_search($inbox,'All');
    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);
            $header =  imap_header($inbox, $email_number); 
            echo "<h1>data</h1>";
            echo "<pre>";print_r($message);
            echo "<h1>Message</h1>";
            echo "<pre>";print_r($message);
            echo "<h1>header</h1>";
            echo "<pre>";print_r($message);
            $overview[0]->seen;
            $overview[0]->subject;
            $overview[0]->from;
            $overview[0]->date;
    
        }
    } 
    /* close the connection */
    imap_close($inbox);
    
    0 讨论(0)
  • 2021-01-20 12:38

    I ran into this problem and here is how I solved it;

    • Login to your gmail account, Under Settings -> Forwarding and POP/IMAP -> Enable Imap.
    • Go to https://www.google.com/settings/security/lesssecureapps and select "Turn On"
    • Go to: https://accounts.google.com/b/0/DisplayUnlockCaptcha and enable access.

    after this, above code works for me....

    0 讨论(0)
  • 2021-01-20 12:41

    maybe are you behind a proxy? if so, I guess you need to auth against it...

    0 讨论(0)
提交回复
热议问题