dsqve08622 2018-07-25 14:00
浏览 34
已采纳

如何在回复地址中设置经过身份验证的用户的电子邮件?

I have this code to send an email to the conference organizer:

public function contactOrganizer($id, Request $request){
    $conference = Conference::find($id);

    $user = Auth::user();

    $message = $request->message;
    $subject = $request->subject;

    Mail::to($conference->organizer_email)->send(new UserNotification($conference, $user, $message, $subject));
    Session::flash('email_sent', 'Your email was sent with success for the conference organizer.');

    return redirect()->back();
}

With this code the email is sent to the conference organizer, that is correct. The issue is that in the from address, instead of appear the email of the authenticted user, the user that sent the email, it appears the email configured in the .env file in the MAIL_USERNAME. So the conference organizer receives the email but dont know the email of the user that sent the email.

So, do you know how to set a reply-to address with the email of the authenticated user?

UserNotificaiton

class UserNotification extends Mailable
{
    use Queueable, SerializesModels;

    public $conference;
    public $user;
    public $message;
    public $subject;


    public function __construct(Conference $conference, User $user, $message, $subject)
    {
        $this->conference = $conference;
        $this->user = $user;
        $this->message = $message;
        $this->subject = $subject;
    }

    public function build()
    {
        return $this
            ->from($this->user->email)
            ->to($this->conference->organizer_email)
            ->markdown('emails.userNotification', [
                'message' => $this->message,
                'subject' => $this->subject
            ]);
    }
}
  • 写回答

2条回答 默认 最新

  • dongxi7722 2018-07-25 14:07
    关注

    You can use replyTo

    public function build()
        {
            return $this
                ->from($this->user->email)
                ->to($this->conference->organizer_email)
                ->replyTo($this->user->email, $this->user->name)
                ->markdown('emails.userNotification', [
                    'message' => $this->message,
                    'subject' => $this->subject
                ]);
        }
    

    Where $this->user->email and $this->user->name contains the email address and name of the authenticated user respectively.

    Ref: https://laravel.com/docs/5.1/mail

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。