Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hachiman's avatar

Mailtrap laravel

So i need to test mail and i am using mailtrap but i keep getting a error and i can't find what it is

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required
"

I followed the instructions on the laravel docu and the mailtrap docu

mail.php file


    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'mailtrap.io'),  

    'port' => env('MAIL_PORT', 2525),

    'from' => ['address' => 'from@exampe.com', 'name' => 'Example'],
    
    'encryption' => 'tls',

    'username' => env('username i got from mailtrap'),

    'password' => env('password i got from mailtrap'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'pretend' => false,

.env file

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username i got from mailtrap
MAIL_PASSWORD=password i got from mailtrap

am i missing something?

0 likes
11 replies
toniperic's avatar
Level 30

Change in your mail.php

'username' => env('username i got from mailtrap'),
'password' => env('password i got from mailtrap'),

to

'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),

The first parameter you pass to env() method is the config key, and not the default value. You could pass the default value as second parameter, likewise:

'username' => env('MAIL_USERNAME', 'your username'),
'password' => env('MAIL_PASSWORD', 'your password'),

What you have done is told your application to look for config with key in the .env file. So if your username on mailtrap was "foobar", your app was looking for config with key "foobar", instead of MAIL_USERNAME.

Hope that helps.

5 likes
toniperic's avatar

@mstnorris what's pseudocode? Think that's copy/pasted from his mail.php file.

It's that he's referencing "username i got from mailtrap" key from his .env file, which obviously doesn't exist, hence the authorization failed.

mstnorris's avatar

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading.

As in, I think he removed the sensitive parts in order to post on here, I don't think that is their actual file.

toniperic's avatar

As in, I think he removed the sensitive parts in order to post on here, I don't think that is their actual file.

@mstnorris, yeah ofcourse he'd hide the credentials. I was asking what's pseudocode'ish in his post.

If you substitute the "username i got from mailtrap" with "mstnorris" (if that was the username on mailtrap), what his app was doing is looking at the .env file for config with key of "mstnorris" instead of key MAIL_USERNAME. His .env file has a key of MAIL_USERNAME, but there's no key with "mstnorris" (per se).

Put simply, it should be this:

MAIL_USERNAME=mstnorris

and what his mail.php file is after is

mstnorris=someValue

which of course doesn't work.

3 likes
milewski's avatar

dont forget to restart the server after changing .env file... or the changes wont take effect

4 likes
shez1983's avatar

You don't have to restart your server for changes in .env files.. not sure where you got that from? @milewski

faylite's avatar

Restarting artisan serve did the trick for me, for some reason. shrugs

1 like
Polar_Bear's avatar

Same here, (restarting artisan served fixed it)...I thought .env file changes were reloaded every time without need to reset, but apparently there is some additional layer that this clears.

Please or to participate in this conversation.