Setup Email Forwarding in cPanel

Forwarders allow you to send a copy of all mail from one email address to another. For example, if you have two different email accounts, joe@example.com and joseph@example.com, you could forward joe@example.com to joseph@example.com so that you do not need to check both accounts. Or you can send it to multiple addresses for example info@example.com could be forwarded to two or more people. Note that the forwarded mail will still be delivered to the original address if it exists. You do not need to create the original email account if you are only forwarding it to other addresses and will not be using it to send email.

Important Note: We do not recommend using this feature for setting up email forwarding from your email address on the hosting server to an email provider elsewhere. The reason is that any spam received on your email will pass through as it is to the destination address. The server at the receiving end will consider your cPanel hosting server to be the source of that spam delivering it to their server. We recommend that proper email accounts should be created and email should be fetched using POP3 or IMAP.

Simple Email Forwarder

When you are logged into cPanel, click on Forwarders in the Email section.

It lists currently configured email forwarders. You can forward one email address to multiple recipients.

Click Add Forwarder to go to next screen to setup new email forwarding:

In Address to Forward: type the required email address that you are forwarding from. In the above example we are using support address on our domain businessx.com.

Under Destination you have a choice of

a) Forward to Email Address (it can be an email address at another domain or on the same domain). This is typical setup.

b) Discard and send an error to the sender (at SMTP time) e.g. when that email address no longer exists (someone left the company and email has been turned off).

If you click on Advanced Options, the area will expand. We explain these options below:

c) Forward to a system account (this should never be used)

d) Pipe to a Program: This is an advanced feature. You can forward the incoming email on this address to a software (script) that can process the email and take an action. Some web applications require you to setup such pipe, which means forwarding all emails to a script. This is explained later in this tutorial below.

e) Discard (Not Recommended) as said this is not recommended and should not be used. We hope cPanel will one day remove this feature! 🙂

Once you are done with the choice, click Add Forwarder button to create the new email forwarding.

Your new forwarder is created. Click Go Back to go back to the Forwarders screen where you can see your new forwarder in the list of forwarders. You can delete the forwarder. You cannot edit it. If you need to modify an existing forwarder, simply delete it and add a new one.

Using Trace link you can find out if the email resolves correctly or if there is an issue with underlying email setup of your domain.

Forward All Email for a Domain

There is another feature available on Forwarders screen in cPanel called Domain Forwarder. This feature allows all mail sent to a domain to be forwarded to another domain. You can use this feature if you have a parked domain but do not have any email configured for it, and would like emails addressed to that domain go to your primary domain. Domain forwarding takes place only when a delivery is not successful on that domain. For example, a user sends an email to john@example1.com. If john@example1.com is an existing email address or auto responder, then the email will not be forwarded. The email will be forwarded if john@example1.com is not an existing email address or auto responder.

Click on Add Domain Forwarder at the top of the screen to continue:

Select the domain from the drop down for which you want emails forwarded to another and then enter the other domain in the text box where you want those forwarded, and click Add Domain Forwarder to finish.

How to use the Pipe to Program Option

When creating simple email forwarder, there is an advanced option to send that email to a program. This is called email piping to program. When you use the pipe to program option, enter a path relative to your home directory for your script. For example, if your cPanel username is ‘john’, and your script is in your home directory at/home/john/script.pl, you would enter this in the Pipe to a Program box: test.pl

To ensure the script will work, the script must be executable. The hashbang line must also exist at the top of the script

  1. If you are using PHP, this should be the hashbang line at the top of the script: #!/usr/local/bin/php -q
  2. If you are using Perl, this should be the hashbang line at the top of the script: #!/usr/bin/perl

If a hashbang is not in your script, enter the path to the Perl or PHP interpreter in the Pipe to a Program box. This should be followed by the full path to the script:

  1. Perl users run this command: /usr/bin/perl /home/john/test.pl
  2. PHP users run this command: /usr/local/bin/php /home/john/test.php

If you are using PHP, ensure that your code is appropriately wrapped in start and end tags.

Make sure that your script uses the proper file permissions (0700). To change your script’s file permissions: chmod 0700 myscript.php where myscript.php is meant to stand for your script’s location and file name.

Let us know if you face any problem or if you have any comments.