I have been starting to learn laravel, everything has going well until I tried to send a test email to mailtrap, it should be sent when I register the user, everything goes fine but when the Mail::to line executes it throws an Server Error.
This is my .env config:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=xxxxxx
MAIL_PASSWORD=xxxxxx
MAIL_ENCRYPTION = null
This is where I try to send the email:
error_log("Checking mail");
Mail::to($user->email)->send(new EmailRegister);
error_log("Everything is fine.");
return response()->json("OK", 200);
The error logs are for me to know with console in wich part it get stuck.
This is my mailable:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class EmailRegister extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.registered');
}
}
And finally this is the view it´s supposed to send:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Welcome to the APP </h1>
</body>
</html>
As you can see is something kind of easy just for testing, but I get stuck on the Mail::to($user->email) and I don´t know why.
I´m also using the Mail Facade in my controller.
use Illuminate\Support\Facades\Mail;
If someone could tell me what I´m doing wrong I would be very grateful.