Home
/
Website Help
/
PHP Questions
/
How to pipe an email to a PHP script?

How to pipe an email to a PHP script?

In some cases you may need to redirect a given mailbox to a PHP script to handle the incoming messages. To do this, go to your Site Tools > Email > Filters and select the desired email account.

Then fill in the desired filter name and criteria and in the Perform the following actions: dropdown menu select Pipe to a Program.

In the next field fill in the full path to the script which will handle the messages. For example, if you create a script/file called pipescript.php placed inside your website’s public_html folder you should fill in

/home/customer/www/yourdomainname.com/public_html/pipescript.php

inside the Pipe to a Program field.

There are several important things you should check regarding the PHP script which is handling the email messages:

  • Ensure the very first line of the script is a hashbang (also called shebang). This is a special line which identifies the file as a PHP script. In most cases it should look like this:

#!/usr/bin/php -q

  • Make sure that there are no white spaces 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;
  • Make sure that the script permissions are set correctly. You need to change the permissions, either via your Site Tools -> File Manager or through an FTP client and set them to 755. This will make the script executable.

Share This Article