0

I trying to send email in laravel using localhost but not receiving email in inbox neither in spam while it successfully send from laravel application not showing any error. This is my controller funciton.

$user = $request->all();
Mail::send('emails.email', ['testVar' => $user], function ($m) use ($user) {
    $m->from('raja.waleed21@gmail.com', $user['doctor_firstname']);
    $m->to('raja.waleed21@gmail.com', $user['doctor_firstname']);
});

This is my email template.

<html>
    <head></head>
    <body>
        {{  $testVar['doctor_firstname']  }}
    </body>
</html>

this is .env file setting.

MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=raja.waleed2121@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

This is my config/mail.php file

<?php

return [

    'default' => env('MAIL_MAILER', 'smtp'),

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

        'ses' => [
            'transport' => 'ses',
        ],

        'mailgun' => [
            'transport' => 'mailgun',
        ],

        'postmark' => [
            'transport' => 'postmark',
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path'      => '/usr/sbin/sendmail -bs',
        ],

        'log' => [
            'transport' => 'log',
            'channel'   => env('MAIL_LOG_CHANNEL'),
        ],

        'array' => [
            'transport' => 'array',
        ],
    ],

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name'    => env('MAIL_FROM_NAME', 'Example'),
    ],

    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

what is the issue as I have not receiving email nor any error.Thanks in advance.

Rwd
  • 34,180
  • 6
  • 64
  • 78
waleed
  • 1

1 Answers1

0

In your env, MAIL_MAILER is mailgun. So this line 'default' => env('MAIL_MAILER', 'smtp'), firstly lookup env file, if mailgun is your driver, mailgun service require mailgun keys as seen as config/services.php so change MAIL_MAILER to smtp in .env file. Ps: i am using 465 port with ssl intead of tls

for mailgun

In .env file

MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=my.domain.com
MAILGUN_SECRET=mYsE1cR3t
MAILGUN_ENDPOINT=api.eu.mailgun.net/v3/mg.domain.com
MAIL_FROM_ADDRESS=no-reply@domain.com
MAIL_FROM_NAME=MYAPP

In config/mail.php

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

In config/services.php

'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
        'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
    ],
Omer YILMAZ
  • 1,234
  • 1
  • 7
  • 15
  • AIL_MAILER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=raja.wed2121@gmail.com MAIL_PASSWORD=password.MAIL_ENCRYPTION=tls MAIL_FROM_ADDRESS=null MAIL_FROM_NAME="${APP_NAME}" – waleed May 03 '20 at 10:09
  • this is what i changed but getting error "stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed" – waleed May 03 '20 at 10:09
  • If you want to use ssl, please enable openssl on your app server. I updated my answer for mailgun – Omer YILMAZ May 03 '20 at 10:20