Which laravel version you are using?
Dec 5, 2017
6
Level 1
How to send mail from a custom form ?
Hey guys, i'm currently trying to do a personal project where people can book a talent by filling in form and the form data will pass on to email's content and send it to the talent's email. How do i pass the data to the email ?
This is what i currently have (i've already setup Mailtrap)
bookingEnquiryMail Controller
public function bookingEnquiryMail(Request $request, User $user) {
$data = array(
'bookingName' => $request->name,
'bookingLocation' => $request->location,
'bookingDate' => $request->date,
'bookingNote' => $request->note,
'bookingAmount' => $request->amount
);
Mail::send('emails.booking-enquiry', $data, function($message) use ($data, $user){
$message->from('[email protected]');
$message->to($user->email);
$message->subject('test');
});
return redirect('/talent')
}
booking-form blade template
<form method="POST" action="/talent/{{$user->id}}">
<input type="hidden" name="_token" value="{{{ csrf_token() }}}">
<div class="form-group">
<label for="bookingName">Representative Name</label>
<input type="string" name="bookingName" class="form-control" value="">
</div>
<div class="form-group">
<label for="bookingLocation">Location</label>
<input type="string" name="bookingLocation" class="form-control" value="">
</div>
<div class="form-group">
<label for="bookingDate">Date</label>
<input type="date" class="form-control" name="bookingDate">
</div>
<div class="form-group">
<label for="bookingNote">Add a Note</label>
<input type="string" class="form-control" name="bookingNote">
</div>
<div class="form-group">
<label for="bookingAmount">Offer Amount</label>
<input type="string" class="form-control" name="bookingAmount">
</div>
<button type="submit" class="btn btn-primary">Send Booking Enquiry</button>
</form>
supposed to be email content template
<p>{{$bookingName}}</p>
<p>{{$bookingLocation}}</p>
<p>{{$bookingDate}}</p>
<p>{{$bookingNote}}</p>
<p>{{$bookingAmount}}</p>
I just dont know how to do mail stuffs in general, and the examples i have seen seem to have different structure so it makes me confused
Please or to participate in this conversation.