3

My PHP scripts recieves information (from a user submitted form) and sends it (almost) straight away as an email. What kind of sainitization should I do on the data?

I want to know exactly which PHP function to use to sanitize the data.

4
  • 2
    htmlentities will be agood place to start, also consider using striptags, to only allow harmless tags Commented Jun 11, 2011 at 19:39
  • A few quick questions on this one, what is the data source? What charset is the data being received encoded in? What charset do you send the email in? Commented Jun 11, 2011 at 19:42
  • A form is being submitted by a user not sure what charset (How can I find out?) Commented Jun 11, 2011 at 19:43
  • @Ibu why? Both is completely unnecessary for E-Mail (from a security perspective at least). Commented Jun 11, 2011 at 19:53

3 Answers 3

2

You need to read up on email injection. Take a look here:

http://www.damonkohler.com/2008/12/email-injection.html

Sign up to request clarification or add additional context in comments.

1 Comment

It would probably save you some time.
1

Have a look at PHP Data Filtering. There are a lots of built in php functions which can be used for data validation and sanitization.

4 Comments

Okay that's good for making sure the email address is valid and that kind of stuff. But how is it going to protect me from, the above mentioned, email injection?
The links suggested by datasage and Alix are useful. I replied to your question: "I want to know exactly which PHP function to use to sanitize the data."
Can you give me an example of, say, validating $message (which contains the users message) to make sure that there is no email injections. (Perhaps it's a matter of just showing me exactly which method of filter_var() to use?)
The message contains text. So, you could try to use filter_var($message, FILTER_SANITIZE_STRING) and check the output. I suggest you to read the links in order to understand what are the possible vulnerabilities and check them.
1

You'll want to:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.