Skip to content

Commit cb82ac0

Browse files
tombrouckeretlehs
andauthored
✨ Make subject and body configurable through option (#10)
Co-authored-by: Ben Word <[email protected]>
1 parent 829aad9 commit cb82ac0

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,17 @@ MAIL_ENCRYPTION=ssl
5151
Once the credentials are properly configured, you can send a test email using Acorn's CLI:
5252

5353
```sh
54-
$ wp acorn mail:test [--to=]
54+
$ wp acorn mail:test [--to=] [--subject=] [--body=]
55+
```
56+
57+
You can customize the test email subject and body:
58+
59+
```sh
60+
# Test with custom subject and body
61+
$ wp acorn mail:test --subject="Deploy Test" --body="Deployment successful"
62+
63+
# Test with custom recipient
64+
$ wp acorn mail:test [email protected]
5565
```
5666

5767
If any errors are detected, they will be printed to console.

src/AcornMailServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AcornMailServiceProvider extends ServiceProvider
1313
*/
1414
public function register()
1515
{
16-
$this->app->singleton('Roots\AcornMail', fn () => AcornMail::make($this->app));
16+
$this->app->singleton(AcornMail::class, fn () => AcornMail::make($this->app));
1717
}
1818

1919
/**
@@ -30,6 +30,6 @@ public function boot()
3030
]);
3131
}
3232

33-
$this->app->make('Roots\AcornMail');
33+
$this->app->make(AcornMail::class);
3434
}
3535
}

src/Console/Commands/MailTestCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Str;
7+
use Roots\AcornMail\AcornMail;
78

89
class MailTestCommand extends Command
910
{
@@ -13,7 +14,9 @@ class MailTestCommand extends Command
1314
* @var string
1415
*/
1516
protected $signature = 'mail:test
16-
{--to= : The email address to send the test email to.}';
17+
{--to= : The email address to send the test email to.}
18+
{--subject=Test email : The subject of the test email}
19+
{--body=This is a test email from WordPress. : The body of the test email}';
1720

1821
/**
1922
* The console command description.
@@ -47,7 +50,7 @@ class MailTestCommand extends Command
4750
*/
4851
public function handle()
4952
{
50-
$package = app('Roots\AcornMail');
53+
$package = app()->make(AcornMail::class);
5154

5255
if (! $package->configured()) {
5356
$this->components->error('The mail SMTP configuration is not set.');
@@ -81,8 +84,8 @@ public function handle()
8184

8285
$mail = wp_mail(
8386
$recipient,
84-
'Test Email',
85-
'This is a test email from WordPress.'
87+
$this->option('subject'),
88+
$this->option('body')
8689
);
8790

8891
if ($mail) {

0 commit comments

Comments
 (0)