Closed craighooghiem closed 10 years ago
Isn't that true for any character that doesn't belong there?
The email adresses used here are probably entered by some user, and it is there that you should validate and make sure the address is correct.
The only reason it makes sense to me is because if someone enters
email@test.com (space at the end)
they intended to provide a valid email
email@things.*&^$
is not a valid email in any way and cannot be salvaged. I can salvage an email that was pasted into a field and happened to have a space at the end. I guess my point is that the email package has validation, so we don't necessarily validate email addresses elsewhere if we can try / catch here - but if I tell someone their email is invalid and the only issue is a space at the end it's going to be inconvenient.
Why don't you trim before passing it to Email package?
I can do that. However, the email package has a validation method for validating email addresses. If we're going to validate emails here, why not toss a quick trim() on there to make sure we're not saying _this email cannot be used_ when it's a perfectly usable email.
I can alter the code across our applications to trim beforehand, but I guess my point is that I see no downside to doing it this way.
I just tested this and emails with spaces on the end do send. So technically it's an issue with the php filter, but this solution still works.
I'll leave it at that - if there's no interest just close it.
I know this should be the responsibility of the developer to clean their inputs, but does it hurt to trim here? The issue is that the FILTER_VALIDATE_EMAIL fails if there's a space at the end of an email.