Email pipe to php script

4 replies
Hello all,

I have the forwarder set up properly in cpanel as well as the permissions to the script set properly. I even can pull out the from email address, and subject. The part that I am having an issue with is how to pull out the message without any other BS besides the actual message text/HTML. Below is the code I am using... If someone can guide me in the right direction that would be greatly appreciated.

Jay

PHP Code:
$fd fopen("php://stdin""r");
$email "";
while (!
feof($fd))
{
    
$email .= fread($fd1024);
}
fclose($fd);
$splittingheaders true;
$exploded explode("\n",$email); 
for(
$i 0$i count($exploded); $i++){
        if (
$splittingheaders) {
        if (
preg_match("/^Subject: (.*)/"$exploded[$i], $matches)) {
            
$subject $matches[1];
        }
        if (
preg_match("/[^From: ][\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i"$exploded[$i], $matches)) {
            
$from $matches[0];
        }
        if (
$exploded[$i]=="") {
        
// empty line, header section has ended
        
$splittingheaders false;
    }  
// trying to pull out the message to no avail  
    
if(preg_match("^Content-Transfer-Encoding: 7bit^",$exploded[$i],$msgs)){
        
$message "GOT IT!\n";
        
$message .= $msgs[$i];
        }
// end of trying to pull out message itself.     
        
}
    } 
#email #php #pipe #script
  • Profile picture of the author Bellasys
    hxxp://www.phpclasses.org/discuss/package/3169/thread/57/
    {{ DiscussionBoard.errors[2213477].message }}
  • Profile picture of the author Killswitch
    What Bellasys posted should help you out.

    Good luck, and I'll check back later and try to help more indepth.
    {{ DiscussionBoard.errors[2217224].message }}
  • Profile picture of the author Luke Graham
    Originally Posted by jaybaker View Post

    PHP Code:
     fopen("php://stdin""r"); 
    Jay,

    What version of PHP are you using?

    I havent had time to test your code locallly but your reference (above) is known to be buggy and a less desirable way of opening streams.

    It may not be your problem but the rest *looks* syntacticly correct. let me know if you have issues by using the direct stream intsead (STDIN)
    Signature
    Best Ways To Make Money Online

    Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
    “Yeah,” reply the bytes. “Make us a double.”
    {{ DiscussionBoard.errors[2218401].message }}

Trending Topics