Skip to content
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

Merged

Conversation

phroggyy
Copy link
Contributor

@phroggyy phroggyy commented Nov 13, 2018

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

  • Note that the included dependency is already required by Swiftmailer.
  • Using 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

@phroggyy phroggyy force-pushed the feat/rfc-6530-email-validation branch 2 times, most recently from 6adb78a to 0fd6ca1 Compare November 13, 2018 15:45
@staudenmeir
Copy link
Contributor

Why do we need egulias/email-validator as a separate dependency when it comes with Swift Mailer?

@phroggyy phroggyy force-pushed the feat/rfc-6530-email-validation branch from 0fd6ca1 to ea1f631 Compare November 13, 2018 15:52
@phroggyy
Copy link
Contributor Author

@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.

@X-Coder264
Copy link
Contributor

@phroggyy You must add the new dependency to the illuminate/validation package composer.json too (as the validation component can be used outside of a full Laravel framework app).

@phroggyy phroggyy force-pushed the feat/rfc-6530-email-validation branch from ea1f631 to be1d9fd Compare November 13, 2018 22:37
@phroggyy
Copy link
Contributor Author

Good one @X-Coder264. Done.

@taylorotwell taylorotwell merged commit c071123 into laravel:master Nov 14, 2018
@taylorotwell
Copy link
Member

Thanks

@coquer
Copy link

coquer commented Jun 19, 2019

@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

@driesvints
Copy link
Member

@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.

taylorotwell pushed a commit to illuminate/validation that referenced this pull request Aug 15, 2019
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.
@ymotorwala
Copy link

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.
I guess Laravel 6 too should have this workaround as it is LTS

@driesvints
Copy link
Member

@ymotorwala Laravel v6 isn't maintained anymore. Please upgrade to Laravel 9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants