/    Sign up×
Community /Pin to ProfileBookmark

Mail program question

I was wondering how you set up something that checks your mail for you, would it be using like a foreach statement like foreach mail u get display the subject and title and sender. Like in a PM system. Could someone possible give me a example of what this code would look like.

Thanks,
[B]~[/B][I]Travis[/I]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@LuboxMay 26.2006 — I'm using something like this to check for pop3 email. I hope I managed to get all necessary code from my function. I've taken this from the php manual for imap functions.

[code=php]
$ServerName = "{mail.example.com:110/pop3}INBOX";
$UserName = "username";
$PassWord = "secret";

$mbox = imap_open($ServerName, $UserName,$PassWord) or die("Could not open Mailbox - try again later!");

if ($hdr = imap_check($mbox)) {
$msgCount = $hdr->Nmsgs;
if ($msgCount == 0){
imap_close($mbox);
return "Failed, no new messages";
}
} else {
imap_close($mbox);
return "Failed, could not check email";
}

$overview=imap_fetch_overview($mbox,"1:$msgCount",0);
$size=sizeof($overview);

for($n=$size-1;$n>=0;$n--){

$val=$overview[$n];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;

$from = ereg_replace(""","",$from);

$elements = imap_mime_header_decode($subj);
$subj = "";
for ($i=0; $i<count($elements); $i++) {
$subj .= $elements[$i]->text;
}

$body = imap_body($mbox, $msg, FT_PEEK);

echo "<p>Subject: $subj<br/>From: $from<br/>Body: $body</p>";

//Delete this email message from server
imap_delete($mbox, $msg);
imap_expunge($mbox);
}

imap_close($mbox);
[/code]


I hope this was helpful....

Lubox
Copy linkTweet thisAlerts:
@bokehMay 26.2006 — It would be a lot easier to use a mailserver with webmail built in... or something like Squirel mail.

Lubox's examples use the IMAP functions which is an extension. You could do the same without the extension using [I]fsockopen()[/I].

My strategy would be completely different. If the mailserver and the webserver occupy the same machine I would access the email files directly using the file system rather than opening a socket type connection.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorMay 26.2006 — well, my server has neomail, horde mail, and squirel mail, but thats not what I want this script for, i have other reasons that i would prefer not to descuss
Copy linkTweet thisAlerts:
@bokehMay 26.2006 — Well your options are either use the IMAP extension recommended above or use a socket connection. The commands of POP3 are really basic so you should be able to figure things out just by reading [URL=http://www.faqs.org/rfcs/rfc1939.html]RFC 1939[/URL].
Copy linkTweet thisAlerts:
@Heavy_MetalauthorMay 26.2006 — ok, thanks.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorMay 27.2006 — odd, when i try to use this script, it throws a "call to undefined function imap_open()" error, why is this???
Copy linkTweet thisAlerts:
@bokehMay 27.2006 — it throws a "call to undefined function imap_open()" error, why is this???[/QUOTE]Well as I said above the IMAP functions are an extension. That means they are not built in to PHP's default build.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorMay 27.2006 — well, how in the crap do you call them then??? i dont really even know what this "extension" is in php
Copy linkTweet thisAlerts:
@bokehMay 27.2006 — An extension is a piece of software that is an extra, i.e. not built in.
×

Success!

Help @Heavy_Metal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...