【问题标题】:Mail configuration settings changes in the .env file not taking effect in Laravel 8.env 文件中的邮件配置设置更改在 Laravel 8 中未生效
【发布时间】:2021-08-09 10:13:27
【问题描述】:

最初,我的 .env 文件中的邮件配置设置指向我的 gmail 帐户,并且联系表单工作正常。我现在已将设置更改为指向 webmail 并运行 php artisan config:cache 但邮件仍在发送到我的 gmail。下面是我的配置设置,我还通过 gmail 向它发送电子邮件并从 web 邮件发送回 gmail 来测试 web 邮件,它工作正常。非常感谢任何帮助。

MAIL_MAILER=smtp
MAIL_HOST=mywebmail
MAIL_PORT=465
MAIL_USERNAME=sales@mydomain
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=sales@mydomain
MAIL_FROM_NAME="Laravel"

PS:我的配置/Mail.php

<?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', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => 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'),
        ],
    ],

];

【问题讨论】:

  • 检查 config/mail.php 并尝试 php artisan optimize:clear 和 php artisan optimize
  • 在 config:cache 命令之后应该应用新设置。我会检查 config/mail.php 是否使用 env
  • @ApurvBhavsar php artisan optimize 在清除后不需要,通常 config:cache 就足够了。
  • 如果您的邮件正在排队并以这种方式发送,您还应该执行php artisan queue:restart 以便内存中存储的任何内容也会随着您最近的更改而刷新。
  • @ApurvBhavsar 我到底应该在配置/邮件中查看什么?我在我的问题中也添加了文件的代码。

标签: php laravel email


【解决方案1】:

问题出在我的控制器上。我正在向我的gmail而不是我的网络邮件发送电子邮件。我在更改邮件设置时忘记更改它。将 mygmail 更改为我的 webmail 后,它就可以正常工作了。

public function store(Request $request)
    {
        $data =  $request->validate([
            //
        ]);

        Mail::to('mygmail.com')
            ->send(new ContactMe($data));

        return redirect(route('contact-us.index'))->with('flash', "Thank you, 
                                                    we'll be in touch soon");
    }

【讨论】:

    猜你喜欢
    • 2019-04-23
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    相关资源
    最近更新 更多