Php accessing the email inbox for email address
Asked Answered
H

1

5

I needed to get the Email address from which Im getting/receiving emails in my Inbox! what should I do for this, I at this time have the following code

<?php
    $mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "[email protected]", "passw0rd")
      or die("can't connect: " . imap_last_error());

    $status = imap_status($mbox, "{imap.gmail.com:993/imap/ssl}INBOX", SA_MESSAGES);
    if ($status) {
      echo $status->messages;
    }
?>
Hodgkins answered 17/4, 2013 at 9:3 Comment(0)
B
16
<?php
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '[email protected]';
$password = 'davidwalsh';

/* 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);
?>

link :Update code from

EDIT

subject - the messages subject
from - who sent it
to - recipient
date - when was it sent
message_id - Message-ID
references - is a reference to this message id
in_reply_to - is a reply to this message id
size - size in bytes
uid - UID the message has in the mailbox
msgno - message sequence number in the mailbox
recent - this message is flagged as recent
flagged - this message is flagged
answered - this message is flagged as answered
deleted - this message is flagged for deletion
seen - this message is flagged as already read
draft - this message is flagged as being a draft
Bricole answered 17/4, 2013 at 9:28 Comment(9)
Email Address is wanted! Is it returned in from? if im correctHodgkins
I have updated anser with all the data you can get using this result with descriptions.Bricole
im getting this error while I execute this Php script>> PHP Error Message Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/a6194138/public_html/email_dante.php on line 8 Free Web Hosting Cannot connect to Gmail: Can't connect to gmail-imap.l.google.com,993: Connection timed outHodgkins
email_dante.php is the php file on which you are running your code ??Bricole
Do you have OpenSSL installed correctly on your check PHPifo? values in it: OpenSSL support: enabled OpenSSL Version: OpenSSL 0.9.8gBricole
I dont know i havent used OpenSSL with PHP ever, I used openssl lastly with Android , and also Im using my online Apache server with PHP how to install openssl on it?Hodgkins
yeah that may be the problem.Thats why it was working fine on your system and not on server.Just check phpinfo and let me know the configuration of openssl whether its enabled or notBricole
let us continue this discussion in chatBricole
It never worked on my system because I was testing all over my apache server online hosting system and I emailed them to know that whether they have openSSL installed and they told me yes they had already installed openSSL on server and its working activated properlyHodgkins

© 2022 - 2024 — McMap. All rights reserved.