Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Last active June 25, 2020 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzkmx/9ea9c7afaac7a5cb66948ccdfd55b217 to your computer and use it in GitHub Desktop.
Save tzkmx/9ea9c7afaac7a5cb66948ccdfd55b217 to your computer and use it in GitHub Desktop.
Minimal sending of Laravel Emails
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=SG.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="hey@example.net"
MAIL_FROM_NAME="Hey Dude/tte"
<?php
namespace App\Console\Commands;
use App\Mail\TestEmail;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
class SendNotificationTest extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sendnote:test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$data = ['name' => 'Chuchito'];
Mail::to('zazaza@example.za')
->send(new TestEmail($data));
}
}
<p>Este es un correo de prueba para {{ name }}</p>
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TestEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(array $data)
{
$this->viewData = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.test');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment