Pipe an email to a script
From WebHost Wiki
For whatever reason, you may want to pipe the contents of an email to a script (to build your own, easily accessible to-do list, autoresponders, or more complex applications such as bounce handling for an e-zine system), and this quick guide will show you how to do that!
Contents |
Cpanel 11
Simply access the Forwarders>Add New Forwarder option and then select the 'pipe to a Program' option box. Enter the path to the php file that handles the forwarding and you are done!
Getting started
There are two things to set up - the email account in cPanel, and then your script.
- Firstly you want to create an email alias.
- Open cPanel
- → go to Mail
- → go to Forwarders
- → go to Add Forwarder
- Now choose the email address you want to receive these emails (for instance help@domain.com).
- Now, in the box where one would normally put the email address to be forwarded to, you need to put the pipe symbol '|', language, any operators, and of cours the script location. On most web servers, you use the following:
Perl
| perl /home/USERNAME/public_html/cgi-bin/SCRIPT.pl
Then to access the email in the script, use the standard perl of
while ($line = <STDIN>) {
chomp $line;
#do whatever must be done
}
PHP
| php -q -n /home/USERNAME/public_html/SCRIPT.php
Then to access the email in the script, use the standard PHP of
$email_file = fopen("php://stdin", "r");
// Do whatever must be done
See also
External links
- Another useful guide for mail-PHP - http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/
