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

uccdev's avatar

Laravel: email is sent, but not received?

So I have this function to send an email:

         public function email($data) {
               Mail::raw("Simple email to confirm email functionality works", function($message) {
                 $message->to('[email protected]');
                 $message->from('[email protected]');
               });
               if (count(Mail::failures()) > 0) {
                 Log::info("Error! Email did not send.");
               }
               Log::info("email sent");
         }

    .....
    self::email($data);
    ....

My config/mail.php is configured like so:

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'port' => env('MAIL_PORT', xxx),
    'from' => [
            'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
            'name' => env('MAIL_FROM_NAME', 'me'),
    ],
            ....

So I expect my mailtrap account, when the function is called, to send an email to the designated "[email protected]". And it does, it sends an email: I can see that clearly from the logs on my mailtrap account.

But, [email protected] receives nothing. Not in my inbox, and not in my junk email.

Any advice on what could be going on here? Any help would be appreciated

0 likes
11 replies
uccdev's avatar

I should have included this earlier, but I have this implemented already:

         MAIL_DRIVER=smtp
         MAIL_HOST=smtp.mailtrap.io
         MAIL_PORT=2525
         MAIL_USERNAME=my_username
         MAIL_PASSWORD=my_password
         [email protected]
         MAIL_FROM_NAME=Anon
         MAIL_ENCRYPTION=null

And I'm confused how I can't be sending mail to mailtrap if, when I log into my mailtrap inbox, I can see the inbox with my email message, and the from-to addresses included?

Is there anything this is missing?

aurawindsurfing's avatar

I'm sorry, your question was that you are not receiving emails. Can you show the screenshot? Are you receiving them after all?

uccdev's avatar

Apologies, Aura, I wasn't sure how to post images on here. https://imgur.com/27jR2na

The email shows the mailtrap.io account I've configured with "[email protected]" (which is also my outlook address). As you can see, it sending an email to "[email protected]" by the hour

However, when I check [email protected] for the corresponding email, it doesn't exist. I can't show a screenshot of there, but it gets no message at all, in either inbox or junk, at least not with the email I keep sending it. And yet, there's my mailtrap.io, clearly containing the message I'm sending.

Is this any clearer? Have I crossed my wires in configuration somewhere?

munazzil's avatar

Have you using the localhost or dedicated server for this then you should, go to the Account->security->Less secure app access to on because it was default as off if you used localhost.

uccdev's avatar

Interesting, thank you. I'm testing on both my local computer and on a server. Where can I adjust those settings?

munazzil's avatar

In your gmail account under the google apps there having Account with your profile image,visit there and do the needful.

uccdev's avatar

But I'm not using a google app or any gmail accounts in these exchanges. "[email protected]" is referencing a work email, not a google email

erikverbeek's avatar
Level 9

Are you switching to a real SMTP server when you're testing to see if receive the email in your inbox?

I might be reading your question wrong but it sounds like you're expecting to see a single email in both mailtrap and your inbox. Which is not what mailtrap does.

Mailtrap 'traps' all you outgoing mails and displays them in their inbox view instead of sending out real emails. This allows you to test your application with real email addresses without spamming real people.

2 likes
uccdev's avatar

I think I've made just that confusion, @erikverbeek My mistake. I'd like to test it by emailing a real address: do you have any recommended emailing tools for just that, which work with laravel?

Please or to participate in this conversation.