cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution

How to properly set an email pipe to a php script

Hello everyone

I've spent at least 2 days trying to figure out what is wrong with my configuration to pipe an email to a php script. I've tried dozens of combinations and no errors or logs are being generated.

 

I'd really appreciate some feedback on how to walk throught the config so I could find what is wrong with my setup.

 

My first question would be about the field "pipe to a program" in the e-mail filter...

Should we use the full path of the script or just the relative path? Should we also use the pipe sign at the very beggining or not? I've tried all the combinations 😞

 

|/home/xxx/public_html/path_to_script/script.php or

|/public_html/path_to_script/script.php or

/home/xxx/public_html/path_to_script/script.php or

public_html/path_to_script/script.php or

????

Thanks

 

 

 

1 ACCEPTED SOLUTION
Super User IV

@LeonardoDuarte 

 

I found the following information when I just googled for this....

 

In some cases you might need to redirect a given mailbox to a PHP script to handle the incoming messages. This can be easily done with cPanel -> Forwarders tool.

To set up pipe forwarding, you can follow the steps below:

- Log in to your cPanel;

- Click on the Forwarders icon, under the Mail section;

- Click on the Add Forwarder button;

- Fill in Address to Forward and put the mail address you would like to pipe the messages from.

- Click on the Advanced options link and select Pipe to a Program. Then fill in the full path to the script which will handle the messages. If you create a script/file called pipescript.php placed inside your home folder you should fill in  /home/username/pipescript.php inside the Pipe to a Program field. If the script is situated inside the public_html/ folder you should fill in /home/username/public_html/pipescript.php

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/local/php70/bin/php-cli -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. In most cases, you would simply need to change the permissions, either via your cPanel -> File Manager or through an FTP client and set them to 755. This will make the script executable.
I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. Thank You Info If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community

View solution in original post

3 REPLIES 3
Super User IV

@LeonardoDuarte 

 

I found the following information when I just googled for this....

 

In some cases you might need to redirect a given mailbox to a PHP script to handle the incoming messages. This can be easily done with cPanel -> Forwarders tool.

To set up pipe forwarding, you can follow the steps below:

- Log in to your cPanel;

- Click on the Forwarders icon, under the Mail section;

- Click on the Add Forwarder button;

- Fill in Address to Forward and put the mail address you would like to pipe the messages from.

- Click on the Advanced options link and select Pipe to a Program. Then fill in the full path to the script which will handle the messages. If you create a script/file called pipescript.php placed inside your home folder you should fill in  /home/username/pipescript.php inside the Pipe to a Program field. If the script is situated inside the public_html/ folder you should fill in /home/username/public_html/pipescript.php

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/local/php70/bin/php-cli -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. In most cases, you would simply need to change the permissions, either via your cPanel -> File Manager or through an FTP client and set them to 755. This will make the script executable.
I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. Thank You Info If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community

View solution in original post

Hi, thanks for your reply.

It's not working yet 😢

 

Do you know if any log is generated by PHP that I could check?

 

I've printed in a simple php file that the PHP binary is located in /usr/local/bin/lsphp so i tried both #!/usr/local/bin/lsphp -q and #!/usr/local/bin/lsphp-cli -q but it's still not working 

 

Thanks again

 

Leo

 

@LeonardoDuarte 

In regards to a log - not sure as I've never tried this

Re: PHP 7.1 it would just be changing 70 to 71 in the path

I am a GoDaddy End User - Just Like You
Check out my site! | I currently manage over 300 WordPress Websites
* Please note that I offer free advice on this forum. Thank You Info If you would like personalized help, please contact me. Otherwise, please ask your question in the proper forum so the answer can assist EVERYONE in the community and not just you. Thanks! *

Once your issue is resolved,
please be sure to come back and click accept for the solution

Get Better Support on the Community Boards!
Etiquette When Asking for Help from the Community