diff --git a/framework/core/src/Api/Controller/SendTestMailController.php b/framework/core/src/Api/Controller/SendTestMailController.php index 8d94f837b6..bd67d4693d 100644 --- a/framework/core/src/Api/Controller/SendTestMailController.php +++ b/framework/core/src/Api/Controller/SendTestMailController.php @@ -11,9 +11,10 @@ use Flarum\Http\RequestUtil; use Flarum\Locale\TranslatorInterface; +use Flarum\Mail\Job\SendInformationalEmailJob; use Flarum\Settings\SettingsRepositoryInterface; use Illuminate\Contracts\Mail\Mailer; -use Illuminate\Mail\Message; +use Illuminate\Contracts\Queue\Factory; use Laminas\Diactoros\Response\EmptyResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -24,7 +25,8 @@ class SendTestMailController implements RequestHandlerInterface public function __construct( protected Mailer $mailer, protected TranslatorInterface $translator, - protected SettingsRepositoryInterface $settings + protected SettingsRepositoryInterface $settings, + protected Factory $queue ) { } @@ -33,23 +35,15 @@ public function handle(ServerRequestInterface $request): ResponseInterface $actor = RequestUtil::getActor($request); $actor->assertAdmin(); - $infoContent = $this->translator->trans('core.email.send_test.body'); - - $title = $this->translator->trans('core.email.send_test.subject'); - $forumTitle = $this->settings->get('forum_title'); - $userEmail = $actor->email; - $username = $actor->display_name; - - $this->mailer->send( - [ - 'text' => 'flarum.forum::email.plain.information.base', - 'html' => 'flarum.forum::email.html.information.base' - ], - compact('infoContent', 'userEmail', 'forumTitle', 'title', 'username'), - function (Message $message) use ($actor) { - $message->to($actor->email); - $message->subject($this->translator->trans('core.email.send_test.subject')); - } + $this->queue->connection('sync')->push( + new SendInformationalEmailJob( + email: $actor->email, + displayName: $actor->display_name, + subject: $this->translator->trans('core.email.send_test.subject'), + body: $this->translator->trans('core.email.send_test.body'), + forumTitle: $this->settings->get('forum_title'), + bodyTitle: $this->translator->trans('core.email.send_test.subject') + ) ); return new EmptyResponse(); diff --git a/framework/core/src/Queue/QueueFactory.php b/framework/core/src/Queue/QueueFactory.php index 9701189be3..f4118875fd 100644 --- a/framework/core/src/Queue/QueueFactory.php +++ b/framework/core/src/Queue/QueueFactory.php @@ -18,7 +18,7 @@ class QueueFactory implements Factory /** * The cached queue instance. */ - private ?Queue $queue; + private ?Queue $queue = null; /** * Expects a callback that will be called to instantiate the queue adapter, diff --git a/framework/core/src/User/Job/RequestPasswordResetJob.php b/framework/core/src/User/Job/RequestPasswordResetJob.php index fb130765b8..de9eb8c4de 100644 --- a/framework/core/src/User/Job/RequestPasswordResetJob.php +++ b/framework/core/src/User/Job/RequestPasswordResetJob.php @@ -53,10 +53,10 @@ public function handle( $queue->push(new SendInformationalEmailJob( email: $user->email, + displayName: Arr::get($data, 'username'), subject: $subject, body: $body, forumTitle: Arr::get($data, 'forum'), - displayName: Arr::get($data, 'username'), bodyTitle: $subject )); }