Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:00:26+00:00 2026-06-17T20:00:26+00:00

i’m trying to make an script that logs into my Gmail account and fetches

  • 0

i’m trying to make an script that logs into my Gmail account and fetches all emails from SPAM folder. This is what i have so far:

<?php
// Ensure Zend folder is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    'C:\xampp\htdocs\zend\library',
     get_include_path(),
)));

// require the ZF autoloader file if you have it in your include path
require_once 'Zend/Loader/Autoloader.php';
// if ZF is not in your path you can specify the full path
// otherwise if it's in a subdir (most likely if you're on a web hosting)
// you can do something like this
//require_once dirname(__FILE__) . '/Zend/Loader/AutoLoader.php';

// laod the autoloader so you don't need to require any ZF file
Zend_Loader_Autoloader::getInstance();

// connecting with Imap to gmail
$mail = new Zend_Mail_Storage_Imap(
    array(
        'host'     => 'imap.gmail.com',
        'port'     => '993',
        'ssl'      => true,
        'user'     => 'myemail@gmail.com',
        'password' => 'password',
    )
);

/*
// get the message object
$message = $mail->getMessage(1);
// output subject of message
echo $message->subject . "\n";
// dump message headers
Zend_Debug::dump($message->getHeaders());

echo $mail->countMessages() . " messages found<br/>";
foreach ($mail as $message) 
{
    echo "Mail from '{$message->from}': {$message->subject}<br/>";
}
*/

/*
var_dump($mail->getCurrentFolder());
echo "<hr>";
*/

echo "<pre>";

foreach($mail->getFolders() as $mailfolder)
{
    foreach($mailfolder as $mailfolder2)
    {
        echo "<b>Folder ".$mailfolder2." ... fetching ... </b><br>";

            var_dump($mailfolder2);



    }

}

die;
var_dump($mail->getFolders());
var_dump($mail->selectFolder("Gmail/Drafts"));

/*
// mbox with folders
$mail = new Zend_Mail_Storage_Folder_Mbox(array('dirname' =>
                                                    '/'));

$folders = new RecursiveIteratorIterator($this->mail->getFolders(),
                                         RecursiveIteratorIterator::SELF_FIRST);
echo '<select name="folder">';
foreach ($folders as $localName => $folder) {
    $localName = str_pad('', $folders->getDepth(), '-', STR_PAD_LEFT) .
                 $localName;
    echo '<option';
    if (!$folder->isSelectable()) {
        echo ' disabled="disabled"';
    }
    echo ' value="' . htmlspecialchars($folder) . '">'
        . htmlspecialchars($localName) . '</option>';
}
echo '</select>';
*/

?>

and i have managed to fetch each folder (as an Zend_Mail_Storage_Folder object) and i cannot figure it out how to get the subject/message from it …

A basic script that fetches all emails from inbox would look like this:

    // get the message object
$message = $mail->getMessage(1);
// output subject of message
echo $message->subject . "\n";
// dump message headers
Zend_Debug::dump($message->getHeaders());

echo $mail->countMessages() . " messages found<br/>";
foreach ($mail as $message) 
{
    echo "Mail from '{$message->from}': {$message->subject}<br/>";
}

This is basically a OOP problem. Any help?

this is the output that i’m getting

http://s17.postimage.org/er2v6yjcf/ceva.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:00:28+00:00Added an answer on June 17, 2026 at 8:00 pm

    try this:

    <?php
    header("Content-Type: text/plain; charset=UTF-8");
    mb_internal_encoding("UTF-8");
    function __autoload($sClassName) {
        $sLibFilePath = __DIR__.'/'.str_replace('_', '/', $sClassName) . '.php';
        if (is_file($sLibFilePath)) {
            include_once($sLibFilePath);
        } else {
            return;
        }
    }
    $oImap = new Zend_Mail_Storage_Imap(
        array(
            'host'     => 'imap.gmail.com',
            'port'     => '993',
            'ssl'      => true,
            'user'     => 'myemail@gmail.com',
            'password' => '***',
        )
    );
    $oImap->selectFolder('[Gmail]/Spam');
    echo $oImap->countMessages() . " messages found\n";
    foreach ($oImap as $iTempId => $oMessage) {
      $iUniqueId = $oImap->getUniqueId($iTempId);
      echo "[{$iTempId}/{$iUniqueId}] Mail from ".mb_decode_mimeheader($oMessage->from).": ".mb_decode_mimeheader($oMessage->subject)."\n";
      if (rand(0,5) == 0) break; //for testing
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.