How can I configure PHP to send all outgoing mail to my own account so that I can test a business application without actually sending mails to unsuspecting businesses, such as "Congratulations, you have a new account. You will be billed for $xxx" ?
Rather than configuring PHP, a generalized solution would be to stand up a dummy SMTP server.
See this question.
So you already wrote the application and it uses live email addresses, and now you want to test it? Did you use a centralized function for mail or are there tons of mail() calls all over the code? Sorry but you're going to have to change every mail() call. Do yourself a favor and replace them all with your own function, and then handle test/live functionality in that one location.
You can redirect all port 25 traffic on the server running PHP to a mailserver/port which delivers all mail to you.
This is the only 100% foolproof method of which I know.
You could create a Google Apps account (or use your dummy server), create a catch-all email account and have it sent to the domain. All you would have to do is look at the catch-all account.
I found this site: http://dummysmtp.com/.
My server is running qmail, so I edited the contents of /var/qmail/control/smtproutes like so:
:smtp.dummysmtp.com username *password*
It worked when I sent a simple mail with PHP mail(), but later I found that mail is still getting out to other people. I had to crawl into the bowels of the code and found this:
/* Choose the mailer */
switch($this->Mailer) {
case 'sendmail':
$result = $this->SendmailSend($header, $body);
break;
case 'smtp':
$result = $this->SmtpSend($header, $body);
break;
case 'mail':
$result = $this->MailSend($header, $body);
break;
default:
$result = $this->MailSend($header, $body);
break;
//$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
//$result = false;
//break;
}
So I had to make sure that each option was configured to send its mail to dummysmtp.com. Once I got that figured out, it all worked.