Sending an email using a Shared hosting

拜拜、爱过 提交于 2021-01-27 17:39:47

问题


I am using Laravel 7 and I want to send an email using shared hosting default mail service.

This is my .env file email configration

MAIL_DRIVER=smtp
MAIL_HOST=hostname
MAIL_PORT=465
MAIL_USERNAME=support@sitename.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl

And this is my default mail in config/mail.php

'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'),
    ],
    'ses' => [
        'transport' => 'ses',
    ],
    'sendmail' => [
        'transport' => 'sendmail',
        'path' => '/usr/sbin/sendmail -bs',
    ],
    'log' => [
        'transport' => 'log',
        'channel' => env('MAIL_LOG_CHANNEL'),
    ],
    'array' => [
        'transport' => 'array',
    ],
],

But there is no email sent to the user, and it doesn't display any errors.

What may I have done wrong?


回答1:


You can catch the error by Swift_TransportException, like this :

try {
    Mail::send('emails.reminder', function ($m) {
      $m->from('hello@app.com', 'Your Application');
      $m->to('user@gmail.com', 'Sender Name')->subject('Your Reminder!');
    });
}catch(\Swift_TransportException $e){
        $response = $e->getMessage(); // catch the error here
}


来源:https://stackoverflow.com/questions/62771490/sending-an-email-using-a-shared-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!