How to Pipe / Send an Email to a PHP Script
Sending an email to a PHP script (also called pipe), is a fairly simple task to accomplish. You first need to setup a PHP file and then you will setup pipe forwarding in cPanel. This tutorial is only the basics and is using cPanel to setup the actual pipe. Alright let us get started with the PHP file.
- The very first line of the PHP script is a hashbang (also called shebang). This is a special line which identifies the file as a PHP script and specifies the path to the PHP binary. In most cases it should look like this:
#!/usr/bin/php –q
But on some occasions this just won’t work. If it doesn’t you either have to change the path to the PHP binary or you need to use the following:
#!/usr/bin/php-cli –q
What this does is runs the PHP binary from the Command Line (cli = command line interface).
Notes: Make sure that there are no whitespaces or blank lines before the above line as this will be sent to the mail server, which will result in a bounced message. The –q option instructs PHP not to print its version either, since this will also result in a bounced message.
- Now that we have the first line done, we need to get the emails content. This is accomplished using the following code below:
file_get_contents('php://stdin');
The script itself will grab the emails content using file_get_contents on php://stdin which is where the email is temporarily stored. You can then manipulate it using such functions as preg_match to grab the parts you want.
- Now to put entire the PHP script together. See the code below:
#!/usr/bin/php –q
As you can tell this is just a very simple script that gets the email contents and just sends it back to you. It just lets you know if it was successful.
- Now upload the PHP file to your site and make sure that the script permissions are set correctly. In most cases, you would simply need to change the permissions, either via your cPanel FileManager or an FTP client and set them to 755. This will make the script executable.
- Now on to setting up the pipe forwarding (sending an email to our PHP script), follow the steps below:
- Log in to your cPanel.
- Click on the “Forwarders” icon, under the “Mail” tab.
- Click on the “Add Forwarder” button.
- Fill in “Address to Forward” and put the mail address you would like to pipe the messages from.
- Select “Pipe to a Program” and fill in the full path to the PHP script which will handle the messages. Luckily in cPanel 11 makes this easy because it automatically puts you in your home directory. So all you need to do is just add a relative path. Click here to see the cPanel image.
I hope that this tutorial has helped you. If you have any questions please comment below.
seems very usefull script short but effective
Read the article, more immersive the environment! SwissGer Backpack
The content is really good. I like it and hope to read more from you. Keep the good work. This site is really awesome.
It seems to be a very useful script. Thanks for sharing it clearly.
http://www.starcooleg.com
????? ?????? ??? ????? ???????? ????? ?????? ?????? ??? ???? ????? ??????? ?? ???? ???? ?? ???
what difference this pipe with yahoo pipe?
Very informative. I was creating a contact form and looking for a solution.
df
Migrants who travel to different EU states face
deportation back to the EU country they initially entered.
Connecting it up – Connecting your PMS to your Channel Supervisor and supplying your
rates and inventory to the OTAs and Booking engine with a two-method connection has been found by our consulting groups to
increase availability by 30% on your hotel web site, sounds unbelievable?
Your article has so much potential to learn from
FmwzqVMxATtLbI
nolQIDkg
rhoPjlWmx