Oct 11 2009
Posted by Webmasters-central.com as Tutorials
Simply you will pipe incoming email to one or more email addresses to your script, either php or cgi or asp …
Example: You have two email addresses like subscribe@yourdomain.com and unsubscribe@yourdomain.com. You want the email that are coming to these two addresses are forwarded to a script, then you will use ‘Email piping’.
Email piping is a server side feature and your host must enable it for you to use it.
Directly uploading .forward, .qmail-default files to root directory:
Previously the set up of email piping used to be very difficult. I have used .qmail-default, .forward, .procmailrc files based on the type of server email program to set up email piping on my clients sites.
1. Create a file called qmail-default.txt or forward.txt or procmailrc.txt on your computer.
2. Keep one of the following lines in that file. You need to change the path to your site path. Try both and test or ask your host which one is correct.
“|/usr/local/bin/php /home/path/to/your/script.php”
“|/home/path/to/your/script.php”
3. Upload it to your root directory and change it to .qmail-default or .forward or .procmailrc.
Ask your host before you do this. They will advice you whether piping can be allowed and the way to do it exactly …
Sometimes .procmailrc file doesn’t work with above simple path. I haven’t seen many hosts installing Procmail nowadays. You need to use something like this:
LOGFILE=$HOME/.procmail-log
:0:
* ^TO_address@domain
|/home/path/to/your/script.php
Using graphical interface of your hostpanel:
Nowadays all hosts are offering panels like Cpanel, Hsphere, Directadmin etc which are having simple graphical user interfaces for you to set up piping.
I explained Cpanel set up here. You might have other hostpanels with different look and links, but the whole idea is same.
1. Login into your Cpanel. Click on ‘Forwarders’ link. Some of the Cpanels need to click on ‘Email’ link to see ‘Forwarders’ link. Click on ‘Add Forwarder’ button.
2. Enter details there.
* Enter your email from which you want the email to be piped to.
* Select the last radio button.
* Enter the path: Make sure the path is correct. You have to enter the path like ‘public_html/script/script.php’. See this tutorial on how to get server file path and document root.
* Click on ‘Add Forwarder’ button.

3. Now goback to your Cpanel ‘Home’ and click on ‘Forwarders’ again. You will see the piping path you have set up there.

* Make sure you are not created a pop3 account for that email. If I created a pop3 account for subscribe@mysite.com, the email will be catched by the pop3 before it will be piped into the script.
* Sometimes piping from catch-all email address works (on old Cpanels I think), but better not to use catch-all email address of the site to pipe email to a script.
* Make sure the path to the script is correct. See this tutorial on how to get server file path and document root.
* Make sure the script to which you are piping is chmoded 755. 755 makes the script executable.
* Upload the script file in ASCII mode rather than BINARY mode.
* Ask the author of the script to see if he added Shebang line to the script. This would be #/usr/bin/php in case of PHP script, #/usr/bin/perl in case of CGI script.
Send an email to the email you have set up in Step 2 of the above procedure. If email piping is functioning, you should see the desired end result(s). Like -
* Sender added to your list
* Sender unsubscribed from your list
* The email added as a helpdesk ticket in your helpdesk system
* User modified in your database etc.
Whatever your end result is, you should see it if piping is working OK. If not go through all above steps and tips.
One Response
Eric Sebasta
January 10th, 2010 at 12:08 am
1Great article, but remember that for php it should be -q to suppress notices and the like fumbling up stdin and stdout . This is in the pipe and the shebang
#/usr/bin/php -q
<?php
// start output buffering
ob_start();
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i
From this you could read $lines and track keywords, emails and anything else your little heart wanted.
RSS feed for comments on this post · TrackBack URI
Leave a reply