Email piping is a way to interact with a web server without using a browser. Instead, you use your email client by sending emails to a specific address that gets routed to a script on your server, instead of an email inbox.
Email piping opens up a whole new world of possibilities that were previously limited to a web browser.
Forget long URL’s with cryptic parameters – you can run the same script on your server and pass much longer parameters, while using a more intuitive and familiar approach – email!
Getting started
To get started with email piping, you’ll need to configure an email address to be forwarded to a script on your server. This approach varies depending on the MTA (Mail Transport Agent).
This can be somewhat complicated, so for me the easiest approach was to pay $8/month and let Host Gator handle the technical details of the email forwarding.
It’s very simple through their control panel interface. Just choose “Forwarders” in the Mail utilities box:

Then designate an email address to be forwarded, along with the script that should run when email is received:

The script
The pipe script (which email gets sent to) should start off with the path to PHP:
#!/usr/bin/php -qThis varies by server/host, so make sure you have the right information there, otherwise nothing will work. Also, make sure the script has permissions of 755, which will allow it to be executed.
You can then write any PHP you want to run when an email is received.
Processing the email source
I won't go into full details on this, but I'll get you started.
To obtain the email message source (headers, body, etc), do this:
... $fd = fopen("php://stdin", "r"); $email = ""; while ( !feof($fd) ) { $email .= fread($fd, 1024); } fclose($fd);You now have a variable that contains the full message source (
Here is an example email source, obtained using the code above, after sending an email to the forwarding address:
From matthom@gmail.com Tue Sep 28 17:05:56 2010 Received: from mail-gy0-f179.google.com ([209.85.160.179]:36572) by gator1170.hostgator.com with esmtp (Exim 4.69) (envelope-from) id 1P0iJA-0006aw-0G for share@matthom.com; Tue, 28 Sep 2010 17:05:56 -0500 Received: by gyh4 with SMTP id 4so71271gyh.38 for ; Tue, 28 Sep 2010 15:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=g3zLYH4xKxcPrHOD18z9YfpQcnk/GaJedfustWU5uGs=; b=H+HmC+fIzAqXQnDt0hYhzn6w1/oaJ3eUUvwIkXUNAMdheJzp0FPm4d29B4hfQC93/2 Q9YZKhfgue66s1jH84QTk0iTpO8LFbCSx2sfEu9AxdxfFnb8HwWTgV7ok8x4YUh0g1JM BqqF5kTGS2w5rCad5rEQCTN1jVlrqKGmXqc8Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=wkY+GVo67m0rQ8uNsUFqffH+TGpYhg/b0JQtQQrEdG0N8weAarpKScMD/Jyu5OpvRW jBJlo60LoQ3Dmtbj7nMW/fbTYJlj5KdxrCFlsoSGi0sR/0gI7R9bNV1sxDZlZ4lCGPF+ abiiXV+4y3FKUMCTROufVfMgohpN0lOu+mE2A= Received: by 10.220.168.213 with SMTP id v21mr147395vcy.134.1285711556311; Tue, 28 Sep 2010 15:05:56 -0700 (PDT) Received: from [192.168.1.3] (30.sub-75-205-181.myvzw.com [75.205.181.30]) by mx.google.com with ESMTPS id v13sm2215736vcr.46.2010.09.28.15.05.52 (version=SSLv3 cipher=RC4-MD5); Tue, 28 Sep 2010 15:05:53 -0700 (PDT) Message-ID: <4CA266BC.6090403@gmail.com> Date: Tue, 28 Sep 2010 17:05:48 -0500 From: Matt Thommes User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: share@matthom.com Subject: test email pipe Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit testing To do something with this using PHP, you'll need some functions that parse the email (systematically read through it). This can get quite complex due to the differences in how the email source appears, so it's best to find some pre-made functions that do this, such as the PHP Mailparse library.
At the very least, it should be easy to obtain the subject text (without the need for a library) by doing something like this:
$lines = explode("\n", $email); foreach ($lines as $k => $line) { if ( preg_match("/^Subject:/", $line) ) { $subject = substr($line, 9); } }Here we break apart each individual line from the email source, and check to see which line starts with "Subject:". In mostly all cases, we can safely assume the actual email subject appears right after that. So our PHP variable,
$subjectwould contain"test email pipe".But for the body of the message, it can get more complicated depending on where it appears in the message source. In our example above, it appears at the very end of the string, but it may not always be in that spot. That's why we need a pre-built PHP function library to help take care of as many scenarios as possible.
My technical meanderings and other nonsense. Published since 2002. No, really. I'm *that* internet-old. I remember the days of