Bos*_*IGA 5 laravel laravel-5 laravel-5.4
我无法发送带有用户地址的电子邮件作为FROM和回复
在FormRequest中:
public function persist()
{
$reservation = Resa::create(
$this->only(['nom', 'email', 'phone', 'formule', 'date_arr', 'date_ret', 'nb_adu', 'nb_enf', 'lemessage'])
);
Mail::to('contact@cotiga.fr')
->from($reservation->email, $reservation->nom)
->replyTo($reservation->email, $reservation->nom)
->send(new Reservation($reservation));
}
Run Code Online (Sandbox Code Playgroud)
我有错误:
FatalThrowableError in ReservationForm.php line 48:
Call to undefined method Illuminate\Mail\PendingMail::from()
Run Code Online (Sandbox Code Playgroud)
我尝试了充分的可能性,但我无法改变字段FROM和REPLYTO你能帮助我吗?谢谢
该Mail门面不实现replyTo()了方法.相反,这种方法已经转移到了Mailable类本身.官方文档建议使用该build()方法来设置Mailable,但这并不总是方便的(例如,每次replyTo字段可能不同)
但是,如果您仍想使用类似的语法,则可以使用:
$mailable = new myMailableClass;
$mailable->replyTo('reply@to.com');
Mail::to('email@tocom')
->send($mailable);
Run Code Online (Sandbox Code Playgroud)
有关Mailable类的可用方法的完整列表,请参阅Mailable文档
在 Laravel 5.4 Mailables 中replyTo,subject、cc、bcc等可以在build方法中的mailable内设置。这也适用于to也可以在 Mail 外观上设置的 。
这是一个使用属性数组可邮寄的联系表单的简单示例:
您可以to直接在MailFacade上使用静态方法,但作为示例,我们将在 mailable 中设置它:
Mail::send(new ContactCompany($attributes));
Run Code Online (Sandbox Code Playgroud)
然后设置replyTo里面的build方法:
class ContactCompany extends Mailable
{
use Queueable, SerializesModels;
public $attributes;
/**
* Create a new message instance.
*
* @param $attributes
*/
public function __construct($attributes)
{
$this->attributes = $attributes;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->to($this->attributes['departmentEmail'], config('app.name'));
$this->replyTo($this->attributes['email'], $this->attributes['name']);
$this->subject(sprintf("New contact message from %s", $this->attributes['name']));
return $this->markdown('emails.contact.company');
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,Mail::alwaysFrom()和Mail::alwaysReplyTo()之前可以使用Mail::send()设置from和replyTo的所有电子邮件,所以一定要小心使用他们。
| 归档时间: |
|
| 查看次数: |
4269 次 |
| 最近记录: |