ActiveState Code

Recipe 541088: Prevent automated contact form submissions from spammers


Adding few lines of code will kick out the spammer by detecting that the URL of the referrer is not the URL of the form.

Python
1
2
3
4
5
import os
FormURL = 'http://example.tld/contact.html'

...
if os.environ['HTTP_REFERER'] !=  FormURL: return

Discussion

Spammers highjack your contact form to automatically submit automated messages through your email script. This code will prevent that.

Sign in to comment