You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “Add an email address that forwards to a script”.
You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “Add an email address that forwards to a script”.
Pingback: Recieve E-mail and Save Attachments with a PHP script | Stuporglue.org
Hi Stuporglue. I was thrilled to see your script on saving emails to mysql and attachments to a local folder. But i cant use any of the Cpanel, Exim etc. I am trying to work solutions that work on all servers. So i was wondering if we cant use this script to show the list of email (MBOX) in then redirect them to your script:
First I have a connect to mailserver file: mbox_connect.php:
And then this line of code to echo a table with my emails.
Nmsgs ."\n\n";
$msgCount = $hdr->Nmsgs;
} else {
echo "failed";
}
$MN=$msgCount;
$overview=imap_fetch_overview($connection,"1:$MN",0);
$size=sizeof($overview);
echo "";
for($i=$size-1;$i>=0;$i--){
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;
$from = ereg_replace("\"","",$from);
// MAKE DANISH DATE DISPLAY
list($dayName,$day,$month,$year,$time) = split(" ",$date);
$time = substr($time,0,5);
$date = $day ." ". $month ." ". $year . " ". $time;
if ($bgColor == "#F0F0F0") {
$bgColor = "#FFFFFF";
} else {
$bgColor = "#F0F0F0";
}
if (strlen($subj) > 60) {
$subj = substr($subj,0,59) ."...";
}
echo "$from$subj
$date\n";
}
echo "";
imap_close($connection);
?>
Can you see some how that the two scripts could go together. With a final cronjob or similar script to execute inserting the email to the db and saving the file to a folder.
Like your blog! It covers a lot.
Kind Regards Sofus
Thanks for stopping by!
I’m afraid I’m not familiar enough with how MBOX files store the data internally to give you a solid answer, but here’s my guesses on a good approach:
1) If MBOX stores the raw email message, an MBOX to database script could connect to the MBOX and for each message just pipe the message to my email handling script (or one similar). The email handling script takes the data in from STDIN, so this should work.
2) Based on the code you pasted, it looks like the MBOX is storing a pre-parsed email message. If this is the case, their parsing is probably much more robust than the code I wrote. I would recommend writing new code to handle those pre-parsed fields since you’re less likely to get an email you can’t handle that way.
Best of luck!
And if you do end up implementing it, post the code somewhere and I’d be happy to link to it.