How to Piping email to PHP Script in DigitalOcean

Posted March 5, 2018 3.9k views
PHPEmailUbuntu 16.04

I need to pipe incoming emails to a specific address to a PHP script on DigitalOcean. I have done this on shared servers in Cpanel using a forwarder to |/opt/alt/php56/usr/bin/php -q /home/somesite/public_html/folder/somescript.php but I’m not sure how to set up something similar (if possible) on DigitalOcean VPS.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

In 15+ years working with PHP I’ve never had to use this particular feature. Doing some research, it seems that every reference to this I’ve found relies on this feature in cPanel rather than using lower level tools.

We generally recommend against running your own email services. They can quickly become a major time-sink and require more attention than most services to prevent abuse.

If you are writing the handler script yourself you have some other options. One alternative would be to create a CRON job that runs every few minutes and checks a POP or IMAP mailbox for new messages. This way there would be no piping and your script would simply pull new messages from the mail server you are using.

Another option would be to use cPanel on your server in order to take advantage of this feature in the same way you did previously. We don’t offer cPanel licenses but you can purchase a VPS license from or a reseller and install it on your droplet. cPanel/WHM features it’s own installer that makes the initial setup quite easy.

by Mitchell Anicas
When setting up a web site or application under your own domain, it is likely that you will also want a mail server to handle the domain's incoming and outgoing email. While it is possible to run your own mail server, it is often not the best option for a variety of reasons. This guide will cover many of the reasons that you may not want to run your own mail server, and offer a few alternatives.