Hello,
I have a contact form, a contact mailable, and a contact mail view and a contact controller... in the contact controller I have the to email as a variable because I want to receive the emails and the from email will be the visitors of the page. However in the to method of the Mail class I got this error:
FatalThrowableError in Mailable.php line 382: [] operator not supported for strings
Here is the code
<?php
namespace App\Http\Controllers\pages;
use Mail;
use Toastr;
use App\Mail\Contact;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Requests\ContactFormRequest;
use App\Http\Controllers\Controller;
class ContactController extends Controller
{
public function store(ContactFormRequest $request)
{
$to = 'myemail@email.com';
Toastr::success('Gracias por ponerse en contacto con nosotros');
Mail::to($to)->send(new Contact($request->email, $request->subject, $request->message));
return back();
}
}
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Contact extends Mailable
{
use Queueable, SerializesModels;
public $from;
public $subject;
public $message;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($from, $subject, $message)
{
$this->from = $from;
$this->subject = $subject;
$this->message = $message;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from($this->from)
->view('emails.contact');
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
Buenas
Ha recibidio un correo de: {{ $from }}
Asunto: {{ $subject }}
Mensaje: {{ $message }}
</body>
</html>
Solved, you cant use a message variable because the mail classes use it.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community