← PHP / Laravel · Contents

PHP-022 / Intermediate

Mail header injection (newlines in recipients or subject)

A03:2021 Injection · CWE-93 CRLF Injection

Why is this a problem?

CRLF followed by Bcc: causes mail to be sent to third parties.

How to fix it

php
$request->validate(['email' => 'required|email:rfc,dns', 'subject' => 'required|max:200']);
Mail::to(config('mail.support'))->send(new Contact($request->only('subject','message'))); // Use Mailable

Further reading