views:

72

answers:

2

I have a classifieds website, and on each classified there is a tip-form where users may tip a friend about the classified. The tip-forms' action is set to a php-page, which mails the email after sanitizing etc...

I have to filter away spam etc so that my email-server don't get blacklisted or anything...

I have my own server (VPS, Linux) and have thought about a solution...

How does this sound to you:

  1. Install a mail-server
  2. Configure Firewall to ONLY allow connections to the mail-server from my website
  3. Configure the mail-server so that a maximum of 'x' emails may be sent every 5 minutes or so
  4. Create a php filter before sending the mail, which checks for 'bad' words.
  5. If necessary, as last resort, ask the user a question (ex 5+5) before submitting form

I would rather preferr if I didn't have to implement the 5th implementation above...

What do you think?

Also, another q I have that you may answer is:

If an email-server gets blacklisted, is there any way to un-blacklist it? Or whats the solution if this happens?

Thanks

+1  A: 

In terms of the php side of things, you want to limit the number of attempts per hour that a ip can make to the script. Also you'll need to check for header injection & other hacks.

A sample of header injection is on your email address field, a script could insert a new line and then a bcc/cc and use it to send spam directly from your server.

Ben Rowe
Header injection is probably more important than the steps mentioned by the original poster
Rowland Shaw
how to prevent header injection http://www.nyphp.org/PHundamentals/8_Preventing-Email-Header-Injection
Ben Rowe
+1  A: 

1 - Install a mail-server

This is easy using any modern Linux distribution. "yum install" or "apt-get" will handle the details for you. All you have to do is decide which SMTP server you want (postfix, exim, sendmail, etc...)

2 - Configure Firewall to ONLY allow connections to the mail-server from my website

Any recent SMTP server should be configured out-of-the-box to NOT act as an open relay. That means that your 'site A' server will not accept email from 'site B' and forward it to 'site C'. If you don't want to act as a general mail server, you can firewall off the listening ports (TCP ports 25, 465, and 587 are generally used for this). Or you could just configure the server to listen to localhost:25 instead of *:25, so no 'outside' connections will be accepted.

3 - Configure the mail-server so that a maximum of 'x' emails may be sent every 5 minutes or so

This is server-dependent. Here's a serverfault answer for postfix.

4 - Create a php filter before sending the mail, which checks for 'bad' words.

Easy enough. Some str_replace/preg_replace can handle that. Question is how detailed you want to get, or if people using your system from this place will be S.O.L.

5 - If necessary, as last resort, ask the user a question (ex 5+5) before submitting form

Again, easy enough. There's plenty of captcha-like libraries out there.

Marc B