首页 > 解决方案 > 发送没有主题的 Laravel Mailable

问题描述

我有一个奇怪的问题,我绝对需要从我的 Laravel 应用程序发送一个没有主题的邮件。

目前,这是build()我的邮件:

public function build()
{
    return $this->from('example@example.com')
    ->view('emails.shipments.remitShipmentFileImages')
    ->subject(null)
    ->attach(storage_path($this->file));
}

但我也试过:

public function build()
{
    return $this->from('example@example.com')
    ->view('emails.shipments.remitShipmentFileImages')
    ->subject('')
    ->attach(storage_path($this->file));
}

但是当我收到电子邮件测试时,我的主题行中会出现“处理汇款文件”。我究竟做错了什么?

标签: laravelemaillaravel-5

解决方案


如果没有主题集,则最终使用类名:

protected function buildSubject($message)
{
    if ($this->subject) {
        $message->subject($this->subject);
    } else {
        $message->subject(Str::title(Str::snake(class_basename($this), ' ')));
    }

    return $this;
}

您可以尝试覆盖该buildSubject方法以删除空白主题的后备:

protected function buildSubject($message)
{
    $message->subject($this->subject);

    return $this;
}

只要 swift 允许空白主题,我想应该没问题。


推荐阅读