I'm building a PHP contact form and am using the htmlspecialchars() function to convert html characters into their literal equivalents to avoid XSS attacks.
OK, thats fine, but when I send the email (to my Yahoo account), the email is shown as just plain text, so < is printed in the email as < which I don't want, since I still want the user to be able to use these characters in fields, but obviously only as literals, not as html.
So, a few questions,
1. Do I need to escape html chars at all if I am only sending a plain text email? Or only if the email will be rendered as an html email?
(I won't be printing any of the data in any page, so it is only the generated email that concerns me.)
2. Can I gaurentee that all email clients will only view the email as plain text instead of trying to render it as html? Or is there a way to force the email client to view the email as either text or html?
3. If someone could just clarify for me exactly when html characters should be escaped in form input that would be good.
I think only if,
i. the data will be printed in the site somewhere
ii. the data will be entered into a database
iii. the data will be formed into an html email
But *not* if the data will only be stored/viewed as plain text. Is this right?
Thanks in advance to anyone who can help me with this!
OK, thats fine, but when I send the email (to my Yahoo account), the email is shown as just plain text, so < is printed in the email as < which I don't want, since I still want the user to be able to use these characters in fields, but obviously only as literals, not as html.
So, a few questions,
1. Do I need to escape html chars at all if I am only sending a plain text email? Or only if the email will be rendered as an html email?
(I won't be printing any of the data in any page, so it is only the generated email that concerns me.)
2. Can I gaurentee that all email clients will only view the email as plain text instead of trying to render it as html? Or is there a way to force the email client to view the email as either text or html?
3. If someone could just clarify for me exactly when html characters should be escaped in form input that would be good.
I think only if,
i. the data will be printed in the site somewhere
ii. the data will be entered into a database
iii. the data will be formed into an html email
But *not* if the data will only be stored/viewed as plain text. Is this right?
Thanks in advance to anyone who can help me with this!