1

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" ?

Lawrence I. Siden
  • 9,191
  • 10
  • 43
  • 56

5 Answers5

2

Rather than configuring PHP, a generalized solution would be to stand up a dummy SMTP server.

See this question.

Community
  • 1
  • 1
Dolph
  • 49,714
  • 13
  • 63
  • 88
  • Thanks. I already looked at that thread. All the solutions either required Windows, or were for Java servers. I'm on linux and my MTA is qmail. I did find a better solution and I'm testing it now. If it works, I'll post a response to my own question. – Lawrence I. Siden Jul 27 '10 at 18:27
  • @Fosco, can you justify why it's a terrible idea? @Isiden, the SMTP servers suggested run on Java, not your app. – Dolph Jul 27 '10 at 19:53
  • Well, instead of limiting the change to just the one application during testing, now the entire server is incapable of sending legitimate emails. See Isiden's post below re: his solution... – Fosco Jul 27 '10 at 19:59
  • Yes, the entire TEST *server* is isolated from the PRODUCTION environment. – Dolph Jul 27 '10 at 20:18
0

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.

Fosco
  • 38,138
  • 7
  • 87
  • 101
  • Sorry. I didn't write the application. I have a copy of the database and I tried to change all the email addresses to my own, but the database is not normalized and there are still many tables with live e-mail addresses that I haven't found yet. – Lawrence I. Siden Jul 27 '10 at 18:28
  • I was suggesting you change the function that sends the email, not the database. The email address is used as a parameter in the mail() function and you could replace it with your own. – Fosco Jul 27 '10 at 18:36
  • --; Suggesting that the OP hardcode configuration data? For shame. – Dolph Jul 27 '10 at 19:57
  • How about enabling the configuration to go into 'testing' mode and having a 'testing email address' to route all emails to. That's what I'm suggesting.. not hardcoding configuration data. – Fosco Jul 27 '10 at 20:00
0

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.

Borealid
  • 95,191
  • 9
  • 106
  • 122
  • Are you referring to iptables? That's interesting, but I think I found a more elegant solution, at least for now. – Lawrence I. Siden Jul 27 '10 at 18:37
  • @Isiden Yes, using iptables you can do this :-). I'm glad you've got a solution, whatever it is. – Borealid Jul 27 '10 at 18:40
  • Well, not quite. I found that mail is still getting out to other people. I tried sudo /sbin/iptables -t nat -A OUTPUT -m tcp --dport 25 -j DNAT --to-destination 65.19.154.62 but got iptables: Unknown error 4294967295 The IP address is to smtp.dummysmtp.com – Lawrence I. Siden Jul 27 '10 at 22:07
  • @Isiden: why are you using the nat table? Shouldn't you be using mangle? – Borealid Jul 27 '10 at 22:28
0

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.

theproxy
  • 31
  • 4
0

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.

Lawrence I. Siden
  • 9,191
  • 10
  • 43
  • 56