【问题标题】:Sending an email using a Shared hosting使用共享主机发送电子邮件
【发布时间】:2020-07-07 08:53:20
【问题描述】:

我正在使用 Laravel 7,我想使用共享主机默认邮件服务发送电子邮件。

这是我的 .env 文件电子邮件配置

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

这是我在 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',
    ],
],

但是没有邮件发送给用户,也没有显示任何错误。

我可能做错了什么?

【问题讨论】:

    标签: laravel laravel-mail


    【解决方案1】:

    您可以通过Swift_TransportException 捕获错误,如下所示:

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 2023-03-20
      • 2015-01-03
      相关资源
      最近更新 更多