Pipe an email to a script

From Email Marketing Wiki
Jump to: navigation, search

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!

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.

  1. Firstly you want to create an email alias.
  2. Open cPanel
  3. → go to Mail
  4. → go to Forwarders
  5. → go to Add Forwarder
  6. Now choose the email address you want to receive these emails (for instance help@domain.com).
  7. 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 MediaCloud servers, you use the following:


 | perl /home/USERNAME/public_html/cgi-bin/SCRIPT.pl 

Then to access the email in the script, use the standard perl of

<perl>while ($line = <STDIN>) { chomp $line;

  1. do whatever must be done



 | php -q -n /home/USERNAME/public_html/SCRIPT.php

Then to access the email in the script, use the standard PHP of

<php>$email_file = fopen("php://stdin", "r"); // Do whatever must be done</php>

See also

External links