71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php declare(strict_types=1);
|
|
/**
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
*
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
/*
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
*
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace App\Service\Email;
|
|
|
|
use Exception;
|
|
use Psr\Log\LoggerInterface;
|
|
use RuntimeException;
|
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
|
use Symfony\Component\Mailer\MailerInterface;
|
|
|
|
/**
|
|
* Class SendPasswordResetEmailService
|
|
*
|
|
* @package App\Service\Email
|
|
* @author Lang <https://www.splendidbear.org>
|
|
* @category Class
|
|
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
|
* @link www.splendidbear.org
|
|
* @since 2026. 04. 20.
|
|
*/
|
|
readonly final class SendPasswordResetEmailService
|
|
{
|
|
public function __construct(
|
|
private LoggerInterface $logger,
|
|
private MailerInterface $mailer,
|
|
) {
|
|
}
|
|
|
|
public function send(string $email, string $username, string $resetUrl): void
|
|
{
|
|
try {
|
|
$this->mailer->send(
|
|
new TemplatedEmail()
|
|
->from('noreply@mineseeker.hu')
|
|
->to($email)
|
|
->subject('Reset your MineSeeker password')
|
|
->htmlTemplate('emails/reset_password.html.twig')
|
|
->context([
|
|
'username' => $username,
|
|
'reset_url' => $resetUrl,
|
|
])
|
|
);
|
|
} catch (TransportExceptionInterface|Exception $e) {
|
|
$this->logger->error("Failed to send password reset email: {$e->getMessage()}", [
|
|
'exception' => $e,
|
|
'email' => $email,
|
|
]);
|
|
throw new RuntimeException("Failed to send password reset email: {$e->getMessage()}");
|
|
}
|
|
}
|
|
}
|
|
|