Can someone tell me how to send a request from a form to a FormRequest and from there send this data per mail?
Here is my form:
<form class="contact__form" style="background-color: #303233 !important;" method="post" action="{{ route('sendContactMail') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group form-group--light form-group--float">
<input type="text" name="name" class="form-control">
<label>Name</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--light form-group--float">
<input type="text" name="number" class="form-control">
<label>Email Address</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--light form-group--float">
<input type="text" name="email" class="form-control">
<label>Contact Number</label>
<i class="form-group__bar"></i>
</div>
<div class="form-group form-group--light form-group--float">
<textarea name="message" class="form-control textarea-autoheight"></textarea>
<label>Message</label>
<i class="form-group__bar"></i>
</div>
Route sendContactMail
:
Route::post('/sendmail', ['uses' => 'PageController@sendContactMail', 'as' => 'sendContactMail']);
uses: PageController@sendContactMail
:
public function sendContactMail(ContactFormRequest $request)
{
\Mail::to('laurent@kirepo.lu')->send(new ContactForm($request));
}
Yeah well I better stop here, because I followed some tutorials and mixed them up, I didn't found a tutorial fo FormRequests & Mailables.
Anyone got a hint?
public function signUp(Request $request){
$data = $request->all();
$validator = \Validator::make($data, [
'email' => 'email|unique:users'
]);
if ($validator->fails()) {
return "Invalid Email ID provided or Email might be an existing user. Please enter a valid email address";
}else{
\Mail::send("email.welcome",
$dataEmail = array(
"subjectMsg" => "Welcome to .......",
"pass" => $password,
"email" => $data['email']
), function($message) use ($dataEmail)
{
$message->from("hello@domain.com", "You Name here");
$message->to($dataEmail['email'])->subject($dataEmail['subjectMsg']);
});
if(count(\Mail::failures()) > 0){
return "An error occured. Please try again";
}else {
return "success";
}
}
}
ROUTE
Route::post('/add-user', 'YourController@signUp');
BLABE (resources/views/email/welcome.blade.php) //If you are sending template email
<html>
<head>
<title></title>
</head>
<body>
<h2>Thank you for signing up</h2>
See your data here: <br>
Subject in the template: {{ $subjectMsg }}
Your password: {{ $pass }}
Your email: {{ $email }}
</body>
</html>
Remember your form action will be to submit to this route : /add-user
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.