seeker1's avatar

Error code 500 when expecting 250.

Hello Everyone I am building a web app implementing the usual registration and logging, decided to use fortify for auth. The implementation went well and all but i noticed something rather disturbing, if the user while registering enters an email address that can't be reached either because it doesn't exist the email verification process returns an http code that is catched by the redirectIfAuthenticated middleware. This then causes an error saying expected http code 250 received code 500. I am pretty new to laravel so i would like to know if this is just on my part or if there is an effective workaround this. Thanks

0 likes
14 replies
Snapey's avatar

look in your log files. your message sounds like an error in sending email (probably email verification)

1 like
seeker1's avatar

Yes this is actually related to the email sending, that is i am still in local setup and i used an smtp server for testing the email verification. When a user logs in with an existing/reachable email address everything works fine and they get the mail, but in the other case i get the error message

Expected response code "250/251/252" but got code "550", with message "550 Unknown recipient".

That error is thrown at the redirectIfAuthenticated middleware when it tries to return the next request. I would like to know how to effectively handle this. Thanks

kokoshneta's avatar

@seeker1 Those are SMTP status codes from the mail system – not server error codes or HTTP status codes. SMTP status code 550 (note: 550, not 500!) means that the recipient’s email is invalid, which you already knew, since you’ve discovered it only happens with invalid addresses. That status code is then converted into an exception by Laravel to help you gracefully handle such scenarios.

I don’t know why redirectIfAuthenticated middleware is receiving an SMTP response – that sounds like something is amiss in how you’ve set things up. The actual e-mail sending (including receiving a response from the SMTP server) should be happening either after your middleware has run or in a route that doesn’t have any such middleware (e.g., if you relegate it to a queue).

1 like
seeker1's avatar

@kokoshneta Well I see. But i didn't implement the auth logic myself i just used fortify

Snapey's avatar

@seeker1 login process should never reach the redirectIfAuthenticated middleware, so I dont know how you got in there.

seeker1's avatar

@Snapey I realize that, but as i just said i only used what came with fortify. I just followed the documentation on how to implement it. After which i noticed this problem.

Snapey's avatar

@seeker1 what make you think its in the redirectIfAuthenticated middleware? Show the error dump or use its share link

seeker1's avatar

@Snapey Expected response code "250/251/252" but got code "550", with message "550 Unknown recipient".

app/Http/Middleware/RedirectIfAuthenticate.ph : 29

use App\Providers\RouteServiceProvider;

use Closure;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Auth;

use Symfony\Component\HttpFoundation\Response;

use App\Models\User;



class RedirectIfAuthenticated

{

    /**

     * Handle an incoming request.

     *

     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next

     */

    public function handle(Request $request, Closure $next, string ...$guards): Response

    {

        $guards = empty($guards) ? [null] : $guards;



        foreach ($guards as $guard) {

            if (Auth::guard($guard)->check()) {

                return redirect(RouteServiceProvider::HOME);

            }

        }



        return $next($request);

    }

}

Sorry I tried sharing the link but this is my first day on laracast and it ain't allowing me to include links the first day. Thanks

kokoshneta's avatar

@seeker1 Just copy-paste the link and add a couple of space so the parser doesn’t recognise it as a link.

1 like
Snapey's avatar

can you just paste the error and the stack trace

seeker1's avatar

https:// flareapp.io/ share/ 95J6n6M5

1 like
amitsolanki24_'s avatar

Check your smtp credentials something went wrong with your SMTP configuration

JussiMannisto's avatar

@amitsolanki24_ If you don't know what's going on, please don't pretend you do while giving advice. It will lead people down the wrong tracks and waste their time. At least add "I think" or something similar to indicate that you're just guessing.

Please or to participate in this conversation.