Laravel not sending mail to mailtrap inbox
Asked Answered
F

1

10

I have tried using sendmail in laravel but it did not work . Check my post here Sending mails through Laravel is inconsistent

So , i tried using mailtrap's fake smtp server in laravel. It's not working here too. I am on Bitnami Mamp stack 7.1.15-0, Laravel 5.8 and testing it locally.

I followed this article to setup my code

https://blog.mailtrap.io/send-email-in-laravel/

I have created one free account in mailtrap. https://mailtrap.io/inboxes

and here is my configuration in .env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=<myusername>
MAIL_PASSWORD=<mypassword>
[email protected]
MAIL_FROM_NAME=Example

My mail.php remains the same as default configuration.

My mailable's class (ReminderMail.php)'s build function

public function build()
{
    Log::info("Building the mailable class");


    return $this->from('[email protected]', 'Mailtrap')
        ->subject('Mailtrap Confirmation')
        ->markdown('emails.reminder')
        ->with([
            'name' => 'New Mailtrap User',
            'link' => 'https://mailtrap.io/inboxes'
        ]);


}

My client code

  echo "\n before sending mail";

    \Mail::to('[email protected]')->send(new \App\Mail\ReminderMail());

    echo "\n Mail sent";

My echos are printing properly.

My emails/reminder.blade.php file

 @component('mail::message')
Hello **{{$name}}**,  {{-- use double space for line break --}}
Thank you for choosing Mailtrap!

Click below to start working right now
@component('mail::button', ['url' => $link])
Go to your inbox
@endcomponent
Sincerely,  
Mailtrap team.
@endcomponent

But still i am not receiving mails in my mailtrap inbox.

Best Regards,

Saurav

Fondness answered 18/8, 2019 at 7:25 Comment(7)
Maybe try with MAIL_ENCRYPTION=null added to your environment file. It is part of the default mailtrap config.Comic
@Namoshek...i did that now...but facing the same result...just updated the question with some of my system setup details...i am on localhost...but that shouldn't be a problem i think ?Fondness
Normally it shouldn't be an issue, but it is hard to tell because depending on where you are working on this, it might be that your company has blocked outgoing connections on ports other than 80/443 for example. Maybe try telnet smtp.mailtrap.io 2525 in a console to see whether the port is accessible at all.Comic
@Comic doing telnet gives me this Connected to smtp.mailtrap.io. Escape character is '^]'. 220 mailtrap.io ESMTP ready and then followed by Connection closed by foreign host.Fondness
In this case there is no connection issue and your problem must be somewhere else. But to be honest, it is quite hard to debug at this point as everything you described seems fine to me.Comic
thanks for your consistent help so far...can the internal laravel classes be logged ?...i would like to see the internal logging of the Mail facadeFondness
Let us continue this discussion in chat.Comic
D
14

It might be an issue with cache. Run:

php artisan config:cache

This will clear and configure your cache again. Then try sending the email once again.

Dambro answered 19/8, 2019 at 1:12 Comment(2)
oh yes...it worked after i cleared the cache...thanks a lot for the tipFondness
I had the same problem, I ran the above command but it was not enough. Since I had setup a Supervisor to manage the queue of tasks I had also to restart the supervisor service. So, double check that in case the config:cache command doesn't work.Impeachable

© 2022 - 2024 — McMap. All rights reserved.