I am trying to send the data from a Contact form to email, but I am getting the following error htmlspecialchars() expects parameter 1 to be string, object given
. Given below is my code. This is from a blog I found trying to get this done. I followed all the steps mentioned there.
ContactController.php
public function index() {
return view('front.contact');
}
public function storeForm(Request $request) {
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10',
'message' => 'required'
]);
contact::create($request->all());
\Mail::send('email', array(
'name'=> $request->get('name'),
'phone'=> $request->get('phone'),
'email'=> $request->get('email'),
'message'=> $request->get('message')
), function ($message) use ($request) {
$message->from($request->email);
$message->to('olindo.testing@gmail.com')->subject('Hello Admin | New Appointment');
});
return back()->with('success', 'Thank you for contacting us. We will get back to you soon.');
email.blade.php Contact.blade.php
<form action="" method="post" action="{{ route('contact.save') }}">
@csrf
<div class="kt-contact-form margin-top-60 form-group">
<div id="message-box-conact"></div>
<h3 class="title">Get in touch</h3>
<p>
<input id="name" type="text" placeholder="Your Name" name="name">
</p>
<p>
<input id="email" type="text" placeholder="Your Email" name="email">
</p>
<p>
<input id="phone" type="text" placeholder="Your Phone Number" name="phone">
</p>
<p>
<textarea id="message" placeholder="Write msg here" name="message"></textarea>
</p>
<input type="submit" name="send" value="SEND REQUEST" class="button">
</div>
</form>
model
class contact extends Model
{
use HasFactory;
public $fillable = [
'name',
'email',
'phone',
'message',
];
}