Email pipe to php script

by 4 replies
5
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($fd, 1024);
}
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.     
        
}
    } 
#programming #email #php #pipe #script
  • hxxp://www.phpclasses.org/discuss/package/3169/thread/57/
  • What Bellasys posted should help you out.

    Good luck, and I'll check back later and try to help more indepth.
  • 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)
    • [1] reply

Next Topics on Trending Feed

  • 5

    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.