Forum Moderators: coopster

Message Too Old, No Replies

Possible to recieve email data

         

makoinater

11:41 am on Apr 8, 2008 (gmt 0)

10+ Year Member



Is it possible to recieve any data from an email account with php? I'v heard of people sending email with php.
does any one have any code that can say get the number of unread messages in your inbox ?, I have a database which contains all email details ina table with fields pop3 sever, username password etc

jatar_k

1:52 pm on Apr 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld makoinater,

try these
[php.net...]

makoinater

10:40 pm on Apr 8, 2008 (gmt 0)

10+ Year Member



Cheers man glad to be here, just startin to get into the php..
That looks pretty intense is that the actual php code thats been listed,
It isn't really explained .

cameraman

12:31 am on Apr 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not so bad; ignore the top page for now and start investigating the functions.
This should get you started - replace the email address & password with valid ones:
$mbox = imap_open('{localhost:143}','email@example.com','password',0,1);
if(!$mbox)
echo "<p>Failed to open.</p>\n";
else {
$props = imap_check($mbox);
echo "<div>Result of imap_check()</div>\n<pre>";
print_r($props);
echo "</pre>\n";
if($props) {
if($props->Nmsgs) {
$overview = imap_fetch_overview($mbox,"1:{$props->Nmsgs}",0);
echo "<hr><div>These are the message objects:</div>\n";
echo "<pre>";
foreach($overview as $message)
print_r($message);
echo "</pre>";
}// EndIf have message(s)
else echo "<p>No messages</p>";
}// EndIf got properties
else
echo "<p>Check didn't.</p>";
imap_close($mbox);
}// EndElse opened mailbox

makoinater

1:05 am on Apr 9, 2008 (gmt 0)

10+ Year Member



cool looks good , I assume that you change the localhost to whichever IMAP server and port or can you only use this for email addresses on your server? , Iv looked up for gmail and got,


$mbox = imap_open('{imap.gmail.com:993}','example@gmail.com','***',0,1);



you can see it in action here-

<snip>

its my main email account, I do know that gmail needs ssl on which might be causing trouble , what parameters do the 0 and 1 control

[edited by: eelixduppy at 2:34 am (utc) on April 9, 2008]
[edit reason] removed link [/edit]

cameraman

1:25 am on Apr 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can see the parameters on the page:
imap_open [php.net]