Reading gmail with the Zend Framework

I am trying to read letters from a gmail application account using Zend Framework. I just passed the Zend Framework directory to my server (path: / Zend / library /).

How to download Zend Framework and Mail module? And how will I read the mail?

I tried the following without any results:

$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

I believe the syntax for reading the inbox looks something like this:

$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com', 'user' => "name@domain.com", 'password' => "mypassword", 'ssl' => 'SSL'));

EDIT

The following code works:

$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

$mail = new Zend_Mail_Storage_Imap(array('host'     => 'imap.gmail.com',
                                         'user'     => 'mail@domain.com',
                                         'password' => 'password',
                                         'ssl'      => 'SSL'));
echo $mail->countMessages();`

... but when I try to track unread emails:

echo "Unread mails:\n";
foreach ($mail as $message) {
    if ($message->hasFlag(Zend_Mail_Storage::FLAG_SEEN)) {
        continue;
    }
    // mark recent/new mails
    if ($message->hasFlag(Zend_Mail_Storage::FLAG_RECENT)) {
        echo '! ';
    } else {
        echo '  ';
    }
    echo $message->subject . "\n";
}

I get the following message:

Fatal error: Uncaught exception 'Zend_Mail_Storage_Exception' with message 'cannot login, user or password wrong' in /var/www/zvinx.dk/test/Zend/library/Zend/Mail/Storage/Imap.php:279 Stack trace: #0 /var/www/zvinx.dk/test/gmail.php(11): Zend_Mail_Storage_Imap->__construct(Array) #1 {main} thrown in /var/www/zvinx.dk/test/Zend/library/Zend/Mail/Storage/Imap.php on line 279

It indicates that the username or password is incorrect, which is strange because I have not changed it since it was created ... How does this error happen?

+3
source share
4 answers

, Zend Framework / ? , quickstart , , Zend_Mail, , : "

+1

gmail . :

$mail = new Zend_Mail_Storage_Imap(array('host'     => 'imap.gmail.com',
                                         'user'     => 'mail@domain.com',
                                         'port'     => '993',
                                         'password' => 'password',
                                         'ssl'      => 'tls',
                                         'auth'     => 'login'
                                          ));

. gmail SSL/TLS, , -, SSL.

+1

, IMAP

public function imapAction()
{
    $config = array('host'=> 'imap.gmail.com', 
        'user' => 'xx',
        'password' => 'xx',
        'ssl' => 'SSL',
        'port' => 993);//995 pop, imap 993

    $mail = new Zend_Mail_Storage_Imap($config);
    $maxMessage = $mail->countMessages();
    $this->logger->info($maxMessage);

    for ($i = $maxMessage; $i <= $maxMessage; $i++)
    {
        $message = $mail->getMessage($i);
        $this->logger->info($i.'Mail from '.$message->from.':'.$message->subject);

        if($message->isMultipart())
        {
            $this->logger->info("has attachments");
            $part = $message->getPart(2);

            $cnt_typ = explode(";" , $part->contentType);
            $name    = explode("=",$cnt_typ[1]);
            $filename   = $name[1];//It is the file name of the attachement in browser
            //This for avoiding " from the file name when sent from yahoomail
            $filename   = str_replace('"'," ",$filename);
            $this->logger->info($filename);

            $attachment = base64_decode($part->getContent());
            $fhandle = fopen($filename, 'w');
            fwrite($fhandle, $attachment);
            fclose($fhandle);
        }
    }
}
+1

, .

  • , Gmail. , Mail iPhone , Gmail, , .

  • Open a browser and go to this page: http://www.google.com/accounts/DisplayUnlockCaptcha

  • Enter your full Gmail address, password, and enter the characters you see in the picture. Press the unlock button to confirm your account.

  • Try reading emails from your gmail application account using the Zend Framework. Your Gmail access must be restored.

+1
source

All Articles