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

phpMick's avatar
Level 15

Sendgrid config

Hi,

Is anyone using sendgrid to send e-mails?

Are you using username/password or an API key?

I'm not getting e-mails and I can't see any errors.

Cheers,

Mick

0 likes
27 replies
programators's avatar

Do you mean sendmail integrated with laravel ? . Present your .env file

phpMick's avatar
Level 15

Doh, I mean sendgrid. (Edited OP).

phpMick's avatar
Level 15
MAIL_MAILER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=blahblahblah
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Me"
MAIL_FROM_ADDRESS="[email protected]"
Mail::to('[email protected]')->send(new TestEmail());
phpMick's avatar
Level 15

That isn't the address I am using, I am using the e-mail address that I used to create the sendgrid account.

I am just following the guide. No, I don't currently have a domain.

Sinnbeck's avatar

Ok, are you sure that the email account allows sending from sendgrid? If It doesn't' the email will either bounce, or end up in the spam folder :)

Sinnbeck's avatar

Same issue. :) To send from a gmail account you need to allow it in the gmail settings, and use their servers (not sendgrid). You sadly need to use a domain that you control

Snapey's avatar

Yes, send from a domain that you own, otherwise your email will be treated as spoofed.

You may also be able to look in your sendgrid account to see if the number of messages you sent is increasing, and if they are seeing any bouncebacks.

Sinnbeck's avatar

There is also a chance that you can find a test email account inside the sendgrid dashboard :) perhaps something like [email protected]

Sinnbeck's avatar

Try checking storage/laravel.log to see if there are any errors

phpMick's avatar
Level 15

OK, change of plan. Forget Sendgrid for now.

What is the simplest way to send mails from Laravel?

Snapey's avatar

What is the simplest way to send mails from Laravel?

Mailtrap.io

Make sure your application is actually generating emails.

phpMick's avatar
Level 15

OK, I'm trying mailtrap:

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=zzzzz
MAIL_PASSWORD=zzzzz
MAIL_ENCRYPTION=tls

$data = ['message' => 'This is a test'];
Mail::to('[email protected]')->send(new TestEmail($data));

mail.php

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

Still nothing.......

Sinnbeck's avatar

Any chance your config is cached?

php artisan config:clear
phpMick's avatar
Level 15

Sheesh, I was doing this in a test, I tried in web.php and it worked.

Take a look at what was lurking in phpunit.xml:

<server name="MAIL_MAILER" value="array"/>

Thanks for your help and patience!

Mick

Sinnbeck's avatar

Oh. Yes real mails should not be sent from tests.. That is by design. Remember to tell us stuff like that ;)

phpMick's avatar
Level 15

I know, I wasn't even really writing a test, just tinkering.

phpMick's avatar
Level 15

And when I go back to Sendgrid I get:

Blocked
Unauthenticated email from whereIwork.com is not accepted due to domain's DMARC policy

I guess, this is as good as working.

Sinnbeck's avatar

Yeah that sounds about right :) You need to validate the domain (spf and such) to send with it properly :)

Please or to participate in this conversation.