Created
October 1, 2024 20:01
-
-
Save morales2k/34d84778868e6efb458721aaf369d4f3 to your computer and use it in GitHub Desktop.
Raw email sender Artisan command to help test email pipelines are well setup; Decoupled from any project specific mailable.
This file contains 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
namespace App\Console\Commands; | |
use Illuminate\Support\Facades\Mail; | |
use Illuminate\Console\Command; | |
class SendTestEmailCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'send:test-email {email?} {subject?} {message?}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Send a test email using the configured mailer.'; | |
public function handle() | |
{ | |
// Get the optional arguments | |
$email = $this->option('email') ?: '[email protected]'; // default to "[email protected]" | |
$subject = $this->option('subject') ?: 'Test Email'; | |
$message = $this->option('message') ?: 'This is a test email sent using the Laravel Artisan command.'; | |
// Send a plain text message using Mail::raw() | |
Mail::raw([ | |
'subject' => $subject, | |
'message' => $message, | |
'from' => config('mail.from.address'), | |
'to' => $email, | |
], function ($message) use ($subject, $message) { | |
$message->subject($subject) | |
->text($message); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment