A forwarder sends mail that arrives for one address on to another, without a mailbox in between. It is handy for addresses like sales@example.com that should land in someone's existing inbox. This guide covers single-address forwarders, domain forwarders, the default address for unknown recipients, piping mail to a script, and how to stop forwarded mail being rejected.
Note: You run cPanel's mail server on your own Linux VPS.
Before you start
- A cPanel login for the account.
- The domain's MX record pointing at this server, so mail arrives here in the first place.
- The destination addresses you want to forward to.
Forward a single address
- In cPanel, open Email » Forwarders.
- Under Create an Email Account Forwarder, click Add Forwarder.
- In Address to Forward, enter the local part, for example
sales, and choose the domain. - Under Destination, choose Forward to Email Address and enter the target, such as
owner@gmail.com. - Click Add Forwarder.
The address does not need a mailbox. If a mailbox with the same name exists, it keeps a copy and the forwarder sends another copy onwards.
To forward to several people, add one forwarder per destination for the same address.
Forward a whole domain
A domain forwarder sends mail for every address at one domain to the same address at another domain. For example, anything@old-example.com goes to anything@example.com.
- On Forwarders, click Add Domain Forwarder under Forward All Email for a Domain.
- Choose the source domain and type the destination domain.
- Click Add Domain Forwarder.
Existing mailboxes and single forwarders on the source domain still work; the domain forwarder handles the rest.
Set the default address (catch-all)
The default address decides what happens to mail sent to addresses that do not exist at your domain.
- Open Email » Default Address.
- Choose the domain.
- Pick an action:
- Discard the email while your server processes it by SMTP time with an error message. The sender gets a bounce. This is the safest choice.
- Forward to Email Address. Every unknown address is delivered to one inbox, a true catch-all.
- Click Change.
Warning: A catch-all collects huge volumes of spam sent to random addresses, and forwarding that spam to Gmail or Outlook can damage your server's reputation. Use the reject option unless you really need a catch-all.
Pipe mail to a script
Some helpdesk and ticket systems read email by having it piped into a script. On the Add Forwarder page, choose Advanced Options » Pipe to a Program, then enter the script path relative to the home directory, for example:
helpdesk/pipe.phpThe script must be executable and start with a valid interpreter line, for example #!/usr/local/bin/php -q. Set permissions from SSH:
chmod 755 /home/USER/helpdesk/pipe.phpIf the script prints any output, the sender gets a bounce containing it, so make sure it runs silently.
Avoid SPF failures when forwarding
When your server forwards a message from someone@bank.com to Gmail, Gmail sees it coming from your IP, which is not in the bank's SPF record. It may mark the message as spam or reject it.
Ways to reduce this:
- Enable SRS (Sender Rewriting Scheme) on the server. In WHM, open Service Configuration » Exim Configuration Manager, find Enable Sender Rewriting Scheme (SRS) Support on the Mail tab, and turn it on. SRS rewrites the envelope sender so SPF passes for your domain.
- Turn on spam filtering so obvious spam is not forwarded at all. See SpamAssassin and Spam Filters in cPanel.
- Prefer a mailbox plus collection for important mail: create a mailbox and let Gmail fetch it over POP3 or IMAP instead of forwarding.
Check it works
Send a test message from an outside account to the forwarded address. It should appear at the destination within a minute. Then open Email » Track Delivery, search for the address, and confirm the forward shows as delivered. From SSH, you can also see what Exim would do:
exim -bt sales@example.comThe output names the destination address and the router that handles it.
Troubleshooting
- Forwarded mail never arrives: check Track Delivery for a rejection from the destination, often an SPF or spam block. Enable SRS and spam filtering.
- Bounce mentions "pipe to |/home/...": the script failed or produced output. Run it by hand from SSH to see the error.
- Catch-all fills the inbox with spam: switch the default address back to rejecting unknown recipients.
- Domain forwarder ignored for some addresses: a mailbox or forwarder already exists for those addresses and takes priority.
Next steps
- Trace any message: track email delivery in cPanel and WHM.
- Send automatic replies: create email autoresponders in cPanel.
