[英]Sending an E-Mail with a different Reply-To in Laravel 5
我在Laravel中使用SMTP配置了此電子郵件。 它運作良好。
我希望一些用戶能夠使用自己的電子郵件地址發送電子郵件。
我曾經這樣做過:
Mail::to($receiver)->from("myconfiguredSTMPemail@mycompany.com")->send(new email());
我現在這樣做:
Mail::to($receiver)->from($email_given_by_the_user)->send(new email());
這很好但我不喜歡這樣,因為我實際上是從我的電子郵件發送它們,而不是從用戶提供的電子郵件中發送它們,即使最終用戶將其視為$email_given_by_the_user
。 我想將其發送為myconfiguredSTMPemail@mycompany.com
但是當用戶想要回復時,它會回復$email_given_by_the_user
。 有沒有辦法做到這一點?
在Laravel 5.4 Mailables中,replyTo,subject,cc,bcc和其他可以在構建方法中的mailable中設置。 對於也可以在Mail外觀上設置的內容也是如此。
所以你可以這樣做:
$attributes = ['replyTo' => $email_given_by_the_user];
Mail::to($receiver)->from("myconfiguredSTMPemail@mycompany.com")->send(new email($attributes));
和電子郵件課程
class email extends Mailable
{
public $attributes;
public function __construct($attributes = null)
{
$this->attributes = $attributes;
}
public function build()
{
if(!empty($this->attributes['replyTo']))
$this->replyTo($this->attributes['replyTo']);
...
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.