I´m trying to send an email confirmation when a contact form is submitted. So, I have a controller to do it and all it works fine.
The only problem is due to a textarea
field which is making problems to me.
This is the output problem:
[previous exception] [object] (TypeError(code: 0): htmlspecialchars(): Argument #1 ($string) must be of type string, Illuminate\\Mail\\Message given at D:\\Proyectos\\PÁGINA PERSONAL\\profesional_website\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php:118)
So, I'm debugging to check variable type and I checked that it was a string. I tried to parse such as strval($message)
and concatenating such as trim($message." ")
but it didn't work.
I attach controller code:
class EmailController extends Controller
{
function sendEmail (Request $request) {
Log::debug(gettype($request->description));
$formData = array(
'name' => $request->name,
'last_names' => $request->last_names,
'mail'=> $request->email,
'message'=> $request->description,
'phone' => $request->phone
);
Mail::to($formData['mail'])->send(new NotifyMail($formData));
if (Mail::failures()) {
$response['success'] = false;
$response['message'] = 'Ha ocurrido un error';
return $response;
}else{
$response['success'] = true;
$response['message'] = 'Mensaje enviado correctamente';
return $response;
}
}
}
And the blade view:
<div style="background-color:#ffcc66;text-align:center;padding:30px 0">
<h1 style="color: #fff;">¡Bienvenido a alexdevs, {{$name}}!</h1>
<p style="color: #fff;">Si este es tu problema:</p>
<p style="color: #fff;padding:20px 50px">{{$message}}</p>
<p style="color: #fff">¡Encontraremos una solución perfecta!</p>
<p style="color: #fff">Me pondré en contacto contigo lo antes posible a través de tu correo: {{$mail}}</p>
<h3 style="color: #fff;">¡Muchas gracias!</h3>
<img src="{{asset('img/negative_rounded_brand.png')}}" alt="alexdevs_logo"
style="height:50px;width:50px;margin-top:30px">
</div>
And this is the Mailable
class:
class NotifyMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail.client', $this->data);
}
}