-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.8] Use a library for email validation #26503
[5.8] Use a library for email validation #26503
Conversation
6adb78a
to
0fd6ca1
Compare
Why do we need |
0fd6ca1
to
ea1f631
Compare
@staudenmeir because any library should declare its own dependencies. If Swiftmailer stops depending on that package, we need to make sure we're still pulling it in. |
@phroggyy You must add the new dependency to the |
ea1f631
to
be1d9fd
Compare
Good one @X-Coder264. Done. |
Thanks |
@taylorotwell do you think it is a good idea to fork this to 5.4? there is so many big projects that can't be upgraded to php 7 and still stuck in 5.4.x and would benefit from this a ton |
@jycr753 heya sorry but 5.4 is EOL and won't be getting any more updates. It's important that you upgrade to the latest versions to get bug and security fixes as well as make use of the latest features. |
These changes allow for multiple email validators to be added when checking for valid emails. This is a continuation of the previous PR: laravel/framework#26503 Basically this allows for two things: - Make use of multiple email validators provided by the egulias/email-validator package - Use the previous (and much requested) filter_var validation By default nothing's breaking because it'll still use the RFC validator to when no validators are passed to the email validation rule. But you can opt to include different ones or multiple ones: 'email' => 'email:rfc,dns' Or opt for the pre-5.8 behavior: 'email' => 'email:filter' Which will use `filter_var` to validate the email address. This should give people a little more flexibility when doing email validation.
This causes https://stackoverflow.com/questions/58725526/validation-of-an-email-address-in-laravel Laravel 7 seems to have a workaround of using 'email:rfc' but laravel 6 does not. |
@ymotorwala Laravel v6 isn't maintained anymore. Please upgrade to Laravel 9. |
Summary
This PR aims to resolve #13215 and similar problems users may experience when trying to send emails with non-ascii characters. The current version of Laravel is dependent on Swiftmailer ^6.0, which added support for RFC5630 email addresses. However, the
email
validation rule in the current version of Laravel relies on PHP's built-in email validation, which is based on the 1982 RFC822 according to the official documentation.Thus, the aim here is just to bring the framework's validation inline with what we support in terms of SMTP sending (through Swiftmailer).
Breaking Changes
This PR will result in a breaking change – emails that (incorrectly) were considered invalid will now be considered valid. e.g hej@bär.se. Any applications that have been relying on the strict RFC822 validation will thus need updating (e.g users that run their own antiquated email servers).
Impact: Low
Notes
new EmailValidator
rather than$this->container->make()
was a conscious decision to reduce backwards compatibility issues, as$this->container
is only defined if the validator factory is used