new: usr: a new feature came up - the abandoned plays can be restored, if both users are registered users #7
This commit is contained in:
67
src/Service/Email/SendContactMailService.php
Normal file
67
src/Service/Email/SendContactMailService.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
namespace App\Service\Email;
|
||||
|
||||
use App\Entity\ContactMessage;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
|
||||
/**
|
||||
* Class SendContactMailService
|
||||
*
|
||||
* @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. 19.
|
||||
*/
|
||||
readonly final class SendContactMailService
|
||||
{
|
||||
public function __construct(
|
||||
#[Autowire(env: 'APP_CONTACT_MAIL_ADDRESS')]
|
||||
private string $appContactMailAddress,
|
||||
private LoggerInterface $logger,
|
||||
private MailerInterface $mailer,
|
||||
) {
|
||||
}
|
||||
|
||||
public function send(ContactMessage $contactMessage): void
|
||||
{
|
||||
try {
|
||||
$this->mailer->send(
|
||||
new TemplatedEmail()
|
||||
->from('noreply@mineseeker.hu')
|
||||
->to($this->appContactMailAddress)
|
||||
->replyTo($contactMessage->getEmail())
|
||||
->subject('New Contact Message from ' . $contactMessage->getName())
|
||||
->htmlTemplate('emails/contact_notification.html.twig')
|
||||
->context(['message' => $contactMessage])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Failed to send contact notification email: ' . $e->getMessage(), [
|
||||
'exception' => $e,
|
||||
'message' => $contactMessage,
|
||||
]);
|
||||
throw new RuntimeException('Failed to send contact notification email: ' . $e->getMessage());
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->logger->error('Failed to send contact notification email: ' . $e->getMessage(), [
|
||||
'exception' => $e,
|
||||
'message' => $contactMessage,
|
||||
]);
|
||||
throw new RuntimeException('Failed to send contact notification email: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user