php Laravel 5.4 更改降价邮件主题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43446060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:50:20  来源:igfitidea点击:

Laravel 5.4 change the subject of markdown mail

phplaravelemaillaravel-5.4

提问by Shashika

I have used markdown mailableswhich is a new feature in laravel 5.4. I have successfully implemented a mail sender. It seems, the subject of the mail is named as the name of the mailableclass. I need to change the subject of the mail and it's hard to find any resources regarding this.

我使用了markdown mailables,这是 laravel 5.4 中的一个新功能。我已经成功地实现了一个邮件发件人。看来,邮件的主题被命名为mailable类的名称。我需要更改邮件的主题,而且很难找到有关此的任何资源。

回答by Pankit Gami

There is subject method in laravel mailables.

laravel mailables 中有主题方法。

All of a mailable class' configuration is done in the build method. Within this method, you may call various methods such as from, subject, view, and attach to configure the email's presentation and delivery. : https://laravel.com/docs/5.4/mail#writing-mailables

所有可邮寄类的配置都在 build 方法中完成。在此方法中,您可以调用各种方法,例如 from、subject、view 和 attach 来配置电子邮件的呈现和传递。: https://laravel.com/docs/5.4/mail#writing-mailables

You can achieve this like this :

你可以这样实现:

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('[email protected]')
                ->subject('Your Subject')
                ->markdown('emails.orders.shipped');
}

You may need to execute php artisan view:clearafter modifying your class.

您可能需要php artisan view:clear在修改类后执行。

回答by rStyles

If the email subject is the same for all emails then just overload the $subject parameter in your extended Mailable class.

如果所有电子邮件的电子邮件主题都相同,则只需在扩展的 Mailable 类中重载 $subject 参数即可。

/**
 * The subject of the message.
 *
 * @var string
 */
public $subject;