Ouch! This script is a disaster area. A malicious user could use your server to send spam or other unpleasant emails.
Firstly, don't send the recipient from the form. Hard-code it into the PHP script or store it somewhere else inaccessible to the user. The user can modify the contents of form elements (yes, even hidden ones) arbitrarily.
Secondly, add two CRLF sequences before the beginning of the message or after the end of the headers. PHP may do this automatically, but inserting extra headers at the top of a message is historically a common way to abuse mailing scripts.
Thirdly, validate all the input you receive before inserting it into a mail header. For example, a name should consist only of alphanumeric characters, a space, or a hyphen. Don't forget to check for non-English characters as well. $email may consist of many things, but should not contain greater-than or lesser-than symbols (< and >), CR or LF characters ("\r" or "\n").
Fourthly, all URLs sent as Location headers should be absolute, according to the HTTP specification. Most browsers will error-correct this, but you shouldn't rely upon it.
Fifthly, the SMTP specification says that mail headers should be separated by a CRLF sequence ("\r\n") not a single LF ("\n").
Sixthly, strip out all HTML tags by doing:
Code:
$comments = preg_replace('/<[^>]+>/g', '', $comments);
Bookmarks