PHP secure email

巴扎黑
Release: 2016-11-11 18:03:48
Original
1394 people have browsed it


PHP Secure Email

PHP E-mail

PHP Error

In the PHP e-mail script in the previous section, there is a vulnerability.

PHP E-mail Injection

First, look at the PHP code in the previous section:

   Email: 
Subject:
Message:

"; } ?>
Copy after login

The problem with the above code is that unauthorized users can insert data in the email header through the input form.

What will happen if the user adds these texts to the input box in the form?

someone@example.com%0ACc:person2@example.com

%0ABcc:person3@example.com,person3@example.com,

anotherperson4@example.com,person5@example.com

%0ABTo: person6@example.com

As usual, the mail() function puts the above text into the email header, so now the header has additional Cc:, Bcc: and To: fields. When the user clicks the submit button, this e-mail will be sent to all the addresses above!

PHP Prevent E-mail Injection

The best way to prevent e-mail injection is to validate the input.

The following code is similar to the previous section, but we have added an input validator to detect the email field in the form:

   Email: 
Subject:
Message:

"; } ?>
Copy after login

In the above code, we use a PHP filter to validate the input:

FILTER_SANITIZE_EMAIL Remove illegal characters of email from string

FILTER_VALIDATE_EMAIL Verify email address



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!