Laravel Mailtrap在本地主机上不起作用

时间:2020-05-20 19:00:15

标签: php laravel smtp mailtrap

我有一个Laravel 7.0项目,当我尝试向电子邮件陷阱发送电子邮件时,出现以下错误。

Swift_TransportException不支持的sendmail命令标志[]。必须 是“ -bs”或“ -t”之一,但可以包含其他标志。

我的.env文件中有关注

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=MY_USERNAME
MAIL_PASSWORD=MY_PASSWORD
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example
MAIL_ENCRYPTION=tls

也尝试清除配置缓存,但不起作用。

php artisan config:cache

3 个答案:

答案 0 :(得分:1)

请务必重新启动队列并再次运行工作:

php artisan queue:restart

php artisan queue:work

documentation 由于队列工作者是长期存在的进程,因此他们不会在不重新启动的情况下注意到您的代码的更改。因此,使用队列工作器部署应用程序的最简单方法是在部署过程中重新启动工作器。

答案 1 :(得分:0)

确保在config/mail.php中有命令标志

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

根据laravel/laravel存储库here

中的定义

答案 2 :(得分:0)

我有同样的问题,如果您使用的是gmail,请尝试此操作,同时添加 MAIL_FROM_ADDRESS

    public IEnumerable<Control> GetAll(Control control, Type type)
    {
        var controls = control.Controls.Cast<Control>();

        return controls.SelectMany(ctrl => GetAll(ctrl, type))
                                  .Concat(controls)
                                  .Where(c => c.GetType() == type);
    }

    private TextBox lastFocussedTextbox;

    private void Form1_Load(object sender, EventArgs e)
    {
        foreach(TextBox textbox in GetAll(this, typeof(TextBox)))
        {
            textbox.LostFocus += (_s, _e) => lastFocussedTextbox = textbox;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if(lastFocussedTextbox != null)
        {
            lastFocussedTextbox.Text = button1.Text;
        }
    }
相关问题