-1
Hello, everybody!
I am studying PHP-Laravel (I am new in the language tb). I need to send an email, but it is presenting me the error
Symfony Component Debug Exception Fatalthrowableerror: Class 'App Http Controllers Mails' not found in file C: dev github phpLaravel blog app Http Controllers Contactscoalescocontroller.php on line 28
I researched and found the solution to use the knife using the use Illuminate\Support\Facades\Mail;
Even so, the error persists. When I have the content of the email rendered, it works normally. Only in the sending that gives this problem. Look at my code below:
Controller:
<?php
namespace App\Http\Controllers;
use App\Models\ContatoFaleConosco;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\App;
use App\Mail\ContatoFaleConoscoMail;
use Illuminate\Support\Facades\Mail;
class ContatoFaleConoscoController extends Controller
{
private $app;
public function __construct(){
$this->app= App::getFacadeRoot();
}
public function send(Request $request){
$model = $this->app->make('App\Models\ContatoFaleConosco');
$model->assunto = $request->input('assunto');
$model->mensagem = $request->input('mensagem');
$model->remetente->nome = $request->input('remetente.nome');
$model->remetente->email = $request->input('remetente.email');
Mails::to($model->remetente->email)->send(new ContatoFaleConoscoMail($model));
return (new ContatoFaleConoscoMail($model))->render();
}
}
Mailable:
<?php
namespace App\Mail;
use App\Models\ContatoFaleConosco;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ContatoFaleConoscoMail extends Mailable
{
use Queueable, SerializesModels;
public $model;
public $nomeRemetente;
public function __construct(ContatoFaleConosco $contatoFaleConosco)
{
$this->model = $contatoFaleConosco;
$this->nomeRemetente = $this->model->remetente->nome;
}
public function build()
{
return $this->view('emails.contato-fale-conosco')
->from($this->model->remetente->email, $this->nomeRemetente);
}
}
Thank you so much there
I took a look at the documentation and saw
Mail::to
to send, you useMails::to
I don’t know if it’s the right call of the method.– Ricardo Lucas