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 AppMail; use IlluminateBusQueueable; use IlluminateContractsQueueShouldQueue; use IlluminateMailMailable; use IlluminateQueueSerializesModels; 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 AppMailNewTicketMail($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.
Advertisement
Answer
In your mail class you are accessing a properties property which does not exist.
Rather in your mailable constructor do something like
public function __construct($details){ $this->details = $details; }
This is for sure one issue. As laravel will throw an unknown property error.
P.s. make sure your env has debug as true if you are not seeing errors in your logs.