Go Back   HostGator Peer Support Forums > Public Forums > Pre-Sales Questions

Notices

Reply
 
Thread Tools
  #1  
Old 06-11-2009, 01:22 PM
schweickism schweickism is offline
Hatchling Croc
 
Join Date: Apr 2009
Posts: 17
Default cPanel mail filer: pip to program

Hi,

Sorry this isn't the right board, but I'm waiting for access to the customer-only sections.

I'm trying to use the cPanel mail filter to pipe e-mails to a program, but I can't find any documentation on how to actually get that input.

I'm piping it to a php file and trying to use fread(STDIN) and it's not picking up anything, so IDK what else to try.
Reply With Quote
  #2  
Old 06-11-2009, 01:46 PM
regentronique's Avatar
regentronique regentronique is offline
King Croc
 
Join Date: Aug 2007
Location: Quebec,Canada
Posts: 969
Default Re: cPanel mail filer: pip to program

You should pipe this way :

Code:
| php -q /home/YourAccountName/public_html/cgi-bin/YourScriptName.php
Inside the YourScriptName.php :

PHP Code:
#!/usr/bin/php 
<?php 

// read the piped email
$fd fopen("php://stdin""r");
$email "";
while (!
feof($fd)) {
  
$email .= fread($fd1024);
}
fclose($fd);

//email processing

?>
Reply With Quote
  #3  
Old 06-11-2009, 02:15 PM
schweickism schweickism is offline
Hatchling Croc
 
Join Date: Apr 2009
Posts: 17
Default Re: cPanel mail filer: pip to program

Thanks, but I'm still not getting anything.

It looks like the file never gets executed. This is the exact value for the program to pipe to:
Code:
| php -q /home/frampton/public_html/cgi-bin/testpipe.php
Then the contents of testpipe.php are the following:
PHP Code:
<?php
$msg 
'';
$input fopen("php://stdin""r");
while(!
feof($input)) {
$msg .= fread($input1024);
}
fclose($input);
$output fopen('testfile.txt''w');
fwrite($output"TEST RESULT:\n");
fwrite($output$msg);
fclose($output);
?>
testfile.txt has permissions set to 777. But after I send an e-mail to the proper address, that file doesn't even contain "TEST RESULT" it's still just blank.
Reply With Quote
  #4  
Old 06-11-2009, 02:51 PM
GvilleRick's Avatar
GvilleRick GvilleRick is offline
Emperor Croc
 
Join Date: Jan 2007
Location: Greenville, SC
Posts: 3,130
Default Re: cPanel mail filer: pip to program

Try setting permissions to 755. The php file should have permissions set to 644.
Reply With Quote
  #5  
Old 06-11-2009, 03:03 PM
schweickism schweickism is offline
Hatchling Croc
 
Join Date: Apr 2009
Posts: 17
Default Re: cPanel mail filer: pip to program

Quote:
Originally Posted by GvilleRick View Post
Try setting permissions to 755. The php file should have permissions set to 644.
That doesn't seem to work either...

Code:
-rwxr-xr-x  1 frampton frampton    0 Jun 11 14:03 testfile.txt*
-rw-r--r--  1 frampton frampton  421 Jun 11 14:15 testpipe.php
Reply With Quote
  #6  
Old 06-11-2009, 03:30 PM
GvilleRick's Avatar
GvilleRick GvilleRick is offline
Emperor Croc
 
Join Date: Jan 2007
Location: Greenville, SC
Posts: 3,130
Default Re: cPanel mail filer: pip to program

I ran a couple of tests on my dedicated server. I added the code your gave with #!/usr/bin/php added as the first line to a file called test.php and put it in my /home/username/ folder with permissions set to 755. Mail sent to that address was written to the file. I did not have to create the file, the server created it when the message was received. Permissions on that file (testfile.txt) were set to 644 by the system.

I also tried creating a filter based on the Subject line and it worked as well. The only glitch I saw was that in both cases a Mail Delivery Failed message was sent to the email address I sent the message from.
Reply With Quote
  #7  
Old 06-11-2009, 04:03 PM
schweickism schweickism is offline
Hatchling Croc
 
Join Date: Apr 2009
Posts: 17
Default Re: cPanel mail filer: pip to program

Thanks a lot for trying that. It turned out that my problem had to do with the filter itself (I just got done talking to HG support). The regex option in the filter wasn't working for some reason... I'm not sure what could have been wrong with it because it was very simple:
Code:
/MSG[0-9]+/
Edit: For the record, don't use /slashes/ around your regular expressions in cPanel. Removing them fixed it... would have been nice if CP would have released a little documentation on that -.-

Last edited by schweickism; 06-11-2009 at 04:08 PM. Reason: see above
Reply With Quote
  #8  
Old 06-11-2009, 04:47 PM
regentronique's Avatar
regentronique regentronique is offline
King Croc
 
Join Date: Aug 2007
Location: Quebec,Canada
Posts: 969
Default Re: cPanel mail filer: pip to program

The cPanel Perl regex interpretation is somewhat problematic.

They have been informed of this problem for quite a while...
Reply With Quote
  #9  
Old 06-11-2009, 04:49 PM
regentronique's Avatar
regentronique regentronique is offline
King Croc
 
Join Date: Aug 2007
Location: Quebec,Canada
Posts: 969
Default Re: cPanel mail filer: pip to program

Quote:
Originally Posted by GvilleRick View Post
...
...
The only glitch I saw was that in both cases a Mail Delivery Failed message was sent to the email address I sent the message from.
This is because of the return code of your script...
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What FTP program do you use? Sam Off-Topic 47 08-18-2008 11:35 AM
Question from a newbie about cPanel & Mail ladyhelipilot Shared Hosting Support 1 08-08-2008 04:18 AM
FTP Program Yizi Shared Hosting Support 12 06-01-2008 04:09 PM

All times are GMT -5. The time now is 12:45 PM.