Php – Redirect all email sent via PHP’s mail() function to single external address

emailPHPpostfixredirect

I currently have php running on my desktop (OS X 10.6.7) with the ability to send emails via the mail() function by having set "relayhost" in /etc/postfix to my ISP as well having as an entry in /etc/postfix/relay_password.

What I would like to have happen (since this is a development computer) is for all emails sent via PHP's mail() function to be delivered to only one external address (so that it then shows up in my Mail.app inbox).

In /usr/local/lib/php.ini I have tried setting "sendmail_path = sendmail -i $email", but it is still delivered to the address specified in the call to mail() within the php script.

I have seen How to redirect all outgoing email from postfix to a single address for testing, but this did not help me.

Best Answer

You can try this:

recipient_canonical_maps = pcre:/etc/postfix/recipient_canonical.pcre

Then put a catch-all in /etc/postfix/recipient_canonical.pcre:

/.*/ your@email.com