On 12 Nov 2011, at 11:49, Ron Piggott wrote:

> Ok.  It works.  I finally am able to display the contents of an e-mail!  Now 
> I am able to write my apps
> 
> I see your monster of all incoming e-mail processors ;)  Thanks for showing 
> me this.  I will look it over when I am more awake.  I kind of get it right 
> now, but I need to look more closely.

Good stuff. I've resurrected an article that used to be on my site that 
explains that example code in a bit more detail: 
http://stut.net/2011/11/12/handling-email-notifications/ - hopefully that will 
make it less of a monster :)

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/


> -----Original Message----- From: Stuart Dallas
> Sent: Saturday, November 12, 2011 6:21 AM
> To: Ron Piggott
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Pipe To A Program
> 
> On 12 Nov 2011, at 07:38, Ron Piggott wrote:
> 
>> I am looking at CPanel’s “E-Mail filtering” option “Pipe To A Program”
>> http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/FilterOptions
>> 
>> The goal I am working towards is saving the contents of an incoming e-mail 
>> address into a mySQL table.  I am thinking of trying to program a customer 
>> contact center application.
>> 
>> Does anyone know what variable the e-mail message is assigned within the 
>> context of “Pipe To A Program”?  Is there a way to find out?  I can’t figure 
>> this out.
>> 
>> What I have tried so far is below:
>> 
>> ===
>> #!/usr/local/bin/php -q
>> <?php
>> 
>> 
>> foreach($_REQUEST as $key => $val) {
>>    $$key = $val;
>> 
>> $email_body .= "KEY: " . $key . "\r\n";
>> $email_body .= "VAL: " . $val . "\r\n";
>> $email_body .= "\r\n";
>> 
>> }
>> 
>> mail( user@domain , "Test Pipe To Program" , $email_body );
>> ===
>> 
>> The mail command works, but the e-mail message body is empty.   I am at a 
>> loss of how to proceed.
> 
> 
> When you pipe email to a program the mail server literally does that - it 
> pipes the contents of the email to the stdin of your program.
> 
> In PHP you would then read the email contents like so...
> 
>   $email = file_get_contents('php://stdin');
> 
> Note that what you get is the raw email, complete with headers. When I do 
> this in PHP I use the Mailparse extension: http://php.net/book.mailparse
> 
> Here's a (somewhat over-complicated) example from an old version of TwitApps 
> when I processed Twitter email notifications: https://gist.github.com/1360403
> 
> -Stuart
> 
> -- 
> Stuart Dallas
> 3ft9 Ltd
> http://3ft9.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to