【问题标题】:laravel mail sending dynamic subjectlaravel 邮件发送动态主题
【发布时间】:2022-06-30 22:02:11
【问题描述】:

我可以使用 laravel 发送邮件,如下所示,但我想要的是这个;我想让主题部分动态化,我该如何实现?

$sendAdmin['sendAdmin'] = $data;
        Mail::to('hello@word.com')->send(new \App\Mail\ContactMail($sendAdmin));
class ContactMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public $details = [];

    public function __construct($details)
    {
        $this->details = $details;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {

        return $this->subject('Hello Mail')->view('email.contactform');
    }
}

【问题讨论】:

    标签: laravel


    【解决方案1】:

    假设主题来自您的$details 数组,这很简单:

    public function build()
    {
        return $this->subject($this->details['subject'])->view('email.contactform');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多