framework: Email Verification invalid Domain in Email
- Laravel Version: 5.7.9
- PHP Version: 7.2.10
- Database Driver & Version: mysql Ver 14.14 Distrib 5.7.23, for Linux (x86_64)
Description:
If email verification is enabled, the site breaks if an email with a none registered domain is entered.
Swift_TransportException (554)
Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients "
You could overwrite the sendEmailVerificationNotification
method and wrap the everything within a try catch block.
public function sendEmailVerificationNotification()
{
$verifyEmail = new VerifyEmail($this);
try {
Mail::to($this->email)
->send($verifyEmail);
} catch (Swift_TransportException $e) {
//
}
}
But then it happens that the user is stuck into an endless loop where the user receives a massage that the email should be verified after login. But the user can’t, because the email ist not send due to for example a typo the user made.
It is not even possible to redirect the user to another page since sendEmailVerificationNotification()
is called after the user has been registered through the Illuminate\Auth\Events\Registered
event.
Does someone have a workaround for this issue?
Steps To Reproduce:
- Enable E-Mail Verification
- Head to
https://DOMAIN.TLD/register
- Lets assume that your E-Mail address is
tim@hallotim.de
but you made a misstake and typetim@hellotim.de
as E-Mail address (this domain is not registered). - Hit the send button.
- The site crashes.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 17 (2 by maintainers)
I am getting the same
error on 5.8 version. I have entered a correct, existing email address from the users table using SMTP driver and complete, correct credentials in .env and in config/mail.php. I could not catch the exception myself because I did not write any code. The error is generated in the Laravel native /password/reset route (Auth password renewal). Update: the issue has nothing to do with the email server, because the same error appears if I put a wrong email password in the .env file 2. Update: we did a new installation of Laravel 6 in a new environment, following the examples from the documentation. The database has been created by artisan migrate (except the 191 character fix). We can register new users, log in, log out, but as soon as we fill the “password forgotten” email form exactly the same error pops up on the /password/email url. SOLVED The problem was in the /config.mail.php We wrongly had
and that changed to
All fine now.
That’s true. The bug is not that the email will not be sent.
The bug is how Laravel handles this. Laravel will show the 500 page because the exception thrown by swift mailer is unhandled. This is not really helpful for the user… There should be a validation error like message which tells the user that an invalid email was entered.
The requirement for the issue is parable 5.7.9 or higher…
Have you guys seen this https://laravel.com/docs/5.8/verification
New email validation mechanism for laravel >=5.8.
Seems they have added a new class to the auth folder that standardizes a way to do this, and have included a new view type blade template for the mail, as well as having included it as a contract in the app\user model
I still like my very inconvenient reminder of the email address that is unverified by flash message, and including a “wrong email?” button next to the forgot password button, that opens an input field nezt to the username/pw boxes for the new email, and upon validation of user/PS the new email is stored and validation resent to the new address.
@driesvints Could you please reopen this issue? The problem also seems to affect others and has been prematurely closed.