-
-
Save thelebster/dd311977b5de70fb1477bc50ae747fe4 to your computer and use it in GitHub Desktop.
A command to test that email has been setup correctly in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use Mail; | |
| class EmailCommand extends Command | |
| { | |
| /** | |
| * The name and signature of the console command. | |
| * | |
| * @var string | |
| */ | |
| protected $signature = 'emailtest'; | |
| /** | |
| * The console command description. | |
| * | |
| * @var string | |
| */ | |
| protected $description = 'Test the Amazon SES email client'; | |
| /** | |
| * Create a new command instance. | |
| * | |
| * @return void | |
| */ | |
| public function __construct() | |
| { | |
| parent::__construct(); | |
| } | |
| /** | |
| * Execute the console command. | |
| * | |
| * @return mixed | |
| */ | |
| public function handle() | |
| { | |
| Mail::raw('This is the body', function ($message) { | |
| $message->from(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME')); | |
| $message->to('targetemail@example.com', 'User\'s Name'); | |
| $message->subject('Hello From ' . env('MAIL_FROM_NAME')); | |
| }); | |
| if (count(Mail::failures()) > 0) { | |
| $errors = 'Failed to send email, please try again.'; | |
| $this->comment(PHP_EOL . $errors . PHP_EOL); | |
| } | |
| $this->comment(PHP_EOL . "Check your email!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment