cache emails via php

Started on the old forum in October 2009 · view the original in the archive · old links redirect here

4 replies · 576 views · started 17 years ago · 1 min read

4 participants
Quintin Junior · 20 posts #1

HI GUYS

I just want to find out, i never did this before, but going to do it now. Has someone maybe got an example for me?

I'm going to start coding on a new script soon, and want to add E-Mail adress for all of my members.

Example, you register as john, your email adress will then be john@domain.com

I know that it has got something to do with your default email address that your surver uses when you send mail to an email account that doesn't exist.

Now, i only want an example of a php code that will take info from that default email address, then identifies the email it was sent to, example john@domain.com hope you understand what I'm getting to.

Thanks in advance.

Quintin / SpiderWap

header("location: hell.php");
WhiteWarrior Principal · 1,419 posts #2

here you go, edit this to your site and add mailattach folder, create a email name as catchall and set it up via phpmail to allow catchall.. and then add cron job in cpanel to link to this file.. name it mail_catch.php and it should work fine for you..

....

<?php // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); // handle email $lines = explode("\n", $email); // empty vars $from = ""; $to = ""; $subject = ""; $headers = ""; $message = ""; $splittingheaders = true; for ($i=0; $i < count($lines); $i++) { if ($splittingheaders) { // this is a header $headers .= $lines[$i]."\n"; // look out for special headers if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { $subject = $matches[1]; } if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { $from = $matches[1]; } if (preg_match("/^To: (.*)/", $lines[$i], $matches)) { $to = $matches[1]; } } else { // not a header, but message $message .= $lines[$i]."\n"; } if (trim($lines[$i])=="") { // empty line, header section has ended $splittingheaders = false; } } include("config.php"); include("core.php"); connectdb(); $froma=explode("<",$from); $fromb=explode(">",$froma[0]); $fromname=$fromb[0]; $fromc=explode("<",$from); $fromd=explode(">",$fromc[1]); $fromaddress=$fromd[0]; $spamcheck="select * from mail where from2='$fromaddress' and spam='yes'"; $result=mysql_query($spamcheck); $numrows=mysql_num_rows($result); $error123=mysql_error(); if($numrows<1) { $to1=explode("@",$to); $to2=explode("<",$to1[0]); $to3=$to2[1]; $usercheck="select * from members where name='$to3'"; $result=mysql_query($usercheck); $numrows=mysql_num_rows($result); $mimecheck=explode(".",$message); if($mimecheck[0]=="This is a multipart message in MIME format") { $message=''; $list=''; $input=$email; include("news/mimedecode.php"); foreach ($structure->parts as $part) { $ctypemerged = $part->ctype_primary."/".$part->ctype_secondary; if($ctypemerged=="text/plain") { $message.=$part->body; $message.="\n\n"; }else if($ctypemerged=="multipart/alternative") { foreach ($part->parts as $part2) { $ctypemerged2 = $part2->ctype_primary."/".$part2->ctype_secondary; if($ctypemerged2=="text/plain") { $message.=$part2->body; $message.="\n\n"; } } }else if (isset($part->disposition) and ($part->disposition=='attachment')) { // open file $extcheck=explode(".",$part->d_parameters['filename']); if($extcheck[1]!="php") { $attachlink="/home/htdocs/mailattachs/".$part->d_parameters['filename']; $fp = fopen($attachlink, 'w'); // write body fwrite($fp, $part->body); // close file fclose($fp); chmod($attachlink,0755); $attachlink="mailattachs/".$part->d_parameters['filename']; $attachname=$part->d_parameters["filename"]; $message .="Attachment: <a href=\"$attachlink\">$attachname</a> "; } } } }else{ $message=$message; } if($numrows<1) { $me=$fromaddress; $subject="SITENAME: Delivery Failure"; $msg="The email you sent to $to3\nwas not delivered because the username does not exist on the SITENAME System.\nTo make sure you have the right email address\nyou can login to SITENAME Community (<http://www.SITENAME.com%29\n> and find the user in the userlist\n\nRegards,\n\nSITENAME."; mail($me,$subject,$msg); } else { $time=date(U); $status='unread'; $inbox='yes'; $outbox='no'; $archive='no'; $spam='no'; $trash='no'; function cuttext($text, $maxChars = 1, $tail = "") { $arrWords = explode("\n\n\n", $text); $temp = ""; for ($i=0; $i<count($arrWords); $i++) { $temp .= ($i == 0 ? $arrWords[$i] : " " . $arrWords[$i]); if (strlen($temp) < $maxChars) { $returnStr = $temp; } else { if (strlen($text) > $maxChars) return $returnStr.$tail; else return $returnStr; } } return $returnStr; } $length=strlen($message); $cut=1; $length2=$length-$cut; $messagex=cuttext($message, $length2, ""); $writemail=mysql_query("insert into mail set from1='$fromname', from2='$fromaddress', touser='$to3', subject='$subject', message='$messagex', time='$time', status='$status', inbox='$inbox', outbox='$outbox', archive='$archive', spam='$spam', trash='$trash'"); $mse=mysql_error(); } } ?>
Quintin Junior · 20 posts #3

thanx Garry, will really have a look at that 🙂

header("location: hell.php");
Leviathan73 Senior · 260 posts #5

Such a script where you can find?😊

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close