I didn’t do it.

Really, I didn’t–I was framed. And you could be too if you’re using the PHP mail() function to handle your contact form without taking any extra security measures.

Last night I found out (the hard way), that my simple contact form was quite an ingenious spam tool. Somebody got on Elliot Swan Designs, opened up my contact form, was able to add in some custom headers, then send out bulk email–as me. Quite ingenious, and quite annoying.

It was pretty late, so I had to just shut down my contact forms for the night, but when I got up I found a user comment on the documentation for mail() that recommended using something like the following code to protect against mail injections:

if(eregi("MIME-Version:",$_POST['field1'].$_POST['feild2'].$_POST['etc'])) {die('Get out, spammer.');}

For good measure I added a second line to it:

if(eregi("Content-Type:",$_POST['field1'].$_POST['feild2'].$_POST['etc'])) {die('Get out, spammer.');}

Hopefully that’ll keep them spammers outa there.