fix: confirm email before sending

This commit is contained in:
Andras Bacsai 2023-09-12 13:19:55 +02:00
parent ab021ee535
commit 8ba18b2ce1

View File

@ -25,30 +25,31 @@
use Mail; use Mail;
use Str; use Str;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\select; use function Laravel\Prompts\select;
use function Laravel\Prompts\text; use function Laravel\Prompts\text;
class TestEmail extends Command class Emails extends Command
{ {
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
* @var string * @var string
*/ */
protected $signature = 'email:test'; protected $signature = 'emails';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Send a test email to the admin'; protected $description = 'Send out test / prod emails';
/** /**
* Execute the console command. * Execute the console command.
*/ */
private ?MailMessage $mail = null; private ?MailMessage $mail = null;
private string $email = 'andras.bacsai@protonmail.com'; private ?string $email = null;
public function handle() public function handle()
{ {
$type = select( $type = select(
@ -187,10 +188,18 @@ public function handle()
} }
} }
$emails = array_unique($emails); $emails = array_unique($emails);
$this->info("Sending to " . count($emails) . " emails.");
foreach ($emails as $email) {
$this->info($email);
}
$confirmed = confirm('Are you sure?');
if ($confirmed) {
foreach ($emails as $email) { foreach ($emails as $email) {
$this->sendEmail($email); $this->sendEmail($email);
} }
} }
break;
}
} }
private function sendEmail(string $email = null) private function sendEmail(string $email = null)
{ {
@ -205,5 +214,6 @@ private function sendEmail(string $email = null)
->subject($this->mail->subject) ->subject($this->mail->subject)
->html((string)$this->mail->render()) ->html((string)$this->mail->render())
); );
$this->info("Email sent to $this->email successfully. 📧");
} }
} }