From a65ef819780cf81810dfcc435753892de0dff5d5 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Tue, 30 Apr 2024 15:39:32 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20feat:=20Make=20subject=20and=20?= =?UTF-8?q?body=20configurable=20through=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You can now set the email subject (--subject=) and body (--body=) from the command line. This enabled us to add a the mail:test command to our deployment proces, and add rules in our inbox to route the test emails --- src/Console/Commands/MailTestCommand.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Console/Commands/MailTestCommand.php b/src/Console/Commands/MailTestCommand.php index 316a941..8de141a 100644 --- a/src/Console/Commands/MailTestCommand.php +++ b/src/Console/Commands/MailTestCommand.php @@ -13,7 +13,9 @@ class MailTestCommand extends Command * @var string */ protected $signature = 'mail:test - {--to= : The email address to send the test email to.}'; + {--to= : The email address to send the test email to.} + {--subject=Test email : The subject of the test email} + {--body=This is a test email from WordPress. : The body of the test email}'; /** * The console command description. @@ -81,8 +83,8 @@ public function handle() $mail = wp_mail( $recipient, - 'Test Email', - 'This is a test email from WordPress.' + $this->option('subject'), + $this->option('body') ); if ($mail) { From 797ba56b828cabf1f4276524ec2ff03f5b364dfc Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Wed, 25 Sep 2024 23:18:19 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20Correct=20class=20pat?= =?UTF-8?q?h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 'Roots\AcornMail\' does not correctly reflect the class path --- src/AcornMailServiceProvider.php | 4 ++-- src/Console/Commands/MailTestCommand.php | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/AcornMailServiceProvider.php b/src/AcornMailServiceProvider.php index 0372e57..74310c6 100755 --- a/src/AcornMailServiceProvider.php +++ b/src/AcornMailServiceProvider.php @@ -13,7 +13,7 @@ class AcornMailServiceProvider extends ServiceProvider */ public function register() { - $this->app->singleton('Roots\AcornMail', fn () => AcornMail::make($this->app)); + $this->app->singleton(AcornMail::class, fn () => AcornMail::make($this->app)); } /** @@ -30,6 +30,6 @@ public function boot() ]); } - $this->app->make('Roots\AcornMail'); + $this->app->make(AcornMail::class); } } diff --git a/src/Console/Commands/MailTestCommand.php b/src/Console/Commands/MailTestCommand.php index 8de141a..914f76b 100644 --- a/src/Console/Commands/MailTestCommand.php +++ b/src/Console/Commands/MailTestCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Str; +use Roots\AcornMail\AcornMail; class MailTestCommand extends Command { @@ -13,9 +14,7 @@ class MailTestCommand extends Command * @var string */ protected $signature = 'mail:test - {--to= : The email address to send the test email to.} - {--subject=Test email : The subject of the test email} - {--body=This is a test email from WordPress. : The body of the test email}'; + {--to= : The email address to send the test email to.}'; /** * The console command description. @@ -49,7 +48,7 @@ class MailTestCommand extends Command */ public function handle() { - $package = app('Roots\AcornMail'); + $package = app()->make(AcornMail::class); if (! $package->configured()) { $this->components->error('The mail SMTP configuration is not set.'); @@ -66,7 +65,7 @@ public function handle() $config = collect($phpmailer) ->filter(fn ($value, $key) => in_array($key, array_keys($this->options))) ->map(fn ($value, $key) => $key === 'Password' ? Str::mask($value, '*', 0) : $value) - ->map(fn ($value, $key) => Str::finish($this->options[$key], ': ').(is_null($value) || empty($value) ? 'Not set' : "{$value}")); + ->map(fn ($value, $key) => Str::finish($this->options[$key], ': ') . (is_null($value) || empty($value) ? 'Not set' : "{$value}")); $this->components->bulletList($config); }); @@ -83,8 +82,8 @@ public function handle() $mail = wp_mail( $recipient, - $this->option('subject'), - $this->option('body') + 'Test Email', + 'This is a test email from WordPress.' ); if ($mail) {