I'm having some trouble with sending email using laravel. I've looked around the stackoverflow for solutions but none worked so far. Here's my env and code so far.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=myemail.gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=ssl
MAIL_SETUP=false
MAIL_FROM_ADDRESS=myemail.gmail.com
MAIL_FROM_NAME="Namehere"
and this is my mail.php file
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.googlemail.com'),
'port' => env('MAIL_PORT', 465),
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'myemail@gmail.com'),
'name' => env('MAIL_FROM_NAME', 'myemail@gmail.com'),
],
Now this is my code. It's just a simple to test the email function. This is the class created in mail folder
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NewTicketMail extends Mailable
{
use Queueable, SerializesModels;
public $details;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($details)
{
$this->$details;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject('Mail from ')->view('emails.new_ticket_mail');
}
}
and this is the route called
Route::get('send-email', function(){
$details = [
'title'=> 'New Ticket Received',
'body' => 'We have received your ticket and will process it. Please do not reply to this
email'
];
\Mail::to('receiver@gmail.com')->send(new \App\Mail\NewTicketMail($details));
return view('emails.thanks');
});
the route works if i commented out the Mail to line. any suggestions? I've been at it for hours.