Forum Moderators: coopster
If the user specifies the destination e-mail address, they can send mail to anyone they like. If they can specify all or part of the message contents, then a user can stick spam or some virus/trojan payload into the message body. If both, they you're running an open relay by accident, and may find your server hijacked to send spam.
The solution to these problems is strict input checking. For many forms, you can even hard-code the address to mail to, which limits exposure to whoever collects the form input and makes the form unappealing to spammers because there's only one target address they can hit with it. Don't ever count on the forms you write for enforcement of the constraints you want, nor on javascript you might add to the page. Verify everything server-side, because that's the only environment you can trust.
(message body and reply-to address)
The rest (destination, subject) are already set up. You mentioned "a user can stick spam or some virus/trojan payload into the message body" - is this possible at the moment?
$ dict munge
2 definitions found
From Jargon File (4.3.0, 30 APR 2001) [jargon]:
munge /muhnj/ vt. 1. [derogatory] To imperfectly transform information.
2. A comprehensive rewrite of a routine, data structure or the whole
program. 3. To modify data in some way the speaker doesn't need to go
into right now or cannot describe succinctly (compare {mumble}). 4. To
add {spamblock} to an email address.
This term is often confused with {mung}, which probably was derived
from it. However, it also appears the word `munge' was in common use in
Scotland in the 1940s, and in Yorkshire in the 1950s, as a verb, meaning
to munch up into a masticated mess, and as a noun, meaning the result of
munging something up (the parallel with the {kluge}/{kludge} pair is
amusing). The OED reports `munge' as an archaic verb meaning "to wipe (a
person's nose)".
I was using deffinition 3 :) How you transform the user data depends on what you want to protect against and what you want the message to be able to contain. One possible approach would be to delete any character other than [A-Za-z0-9@\.\?\s\n], leaving you with very simple text, space, newlines, and not even much punctuation. Bland, to say the least, but someone would be pretty hard pressed to squeeze something obnoxious into that character set. Exactly what you allow and don't, though, is your own call based on what you need to get out of the input.
I might also do something like calling htmlentities() on the whole message, on the theory that it would change enough important characters to make any executable content un-executable. That's not robust by any means, but it would be a decent heuristic.
Ok, say I just want to make sure I don't get attachments or malicious code.
Its not possible to send attachements through a <textarea> so I think you can stop worrying about attachments .. also malicious code will not execute even if pasted and sent if it is going to come through as plain text.
If you are getting it as html, you can use some thing like this
$string = strip_tags($string, '<a><b><i><u>');
it will strip html tags except those in the second argument ..
you can see more about this here
[php.net...]