5

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>
MAIL_FROM_ADDRESS=from@example.com
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('mail@example.com', '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('newuser@example.com')->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

saurav
  • 4,032
  • 7
  • 38
  • 74
  • Maybe try with `MAIL_ENCRYPTION=null` added to your environment file. It is part of the default mailtrap config. – Namoshek Aug 18 '19 at 07:40
  • @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 ? – saurav Aug 18 '19 at 07:55
  • 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. – Namoshek Aug 18 '19 at 08:16
  • @Namoshek 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. – saurav Aug 18 '19 at 12:10
  • 1
    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. – Namoshek Aug 18 '19 at 12:14
  • 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 facade – saurav Aug 18 '19 at 12:15
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198099/discussion-between-namoshek-and-saurav). – Namoshek Aug 18 '19 at 12:21

1 Answers1

6

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.

zonecc
  • 313
  • 1
  • 10