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
]);
}
}