|
9 | 9 | use Laminas\Validator\EmailAddress; |
10 | 10 | use Laminas\Validator\NotEmpty; |
11 | 11 | use Light\App\Enum\ContactTopicEnum; |
| 12 | +use Psr\Log\LoggerInterface; |
12 | 13 | use Throwable; |
13 | 14 |
|
14 | 15 | use function htmlspecialchars; |
@@ -44,9 +45,14 @@ final class ContactService |
44 | 45 |
|
45 | 46 | private const array RESERVED_FIELDS = ['topic', 'name', 'email', 'company', 'stack', 'message', 'contact']; |
46 | 47 |
|
47 | | - #[Inject('dot-mail.service.contact')] |
48 | | - public function __construct(private readonly MailServiceInterface $mailService) |
49 | | - { |
| 48 | + #[Inject( |
| 49 | + 'dot-mail.service.contact', |
| 50 | + 'dot-log.default_logger', |
| 51 | + )] |
| 52 | + public function __construct( |
| 53 | + private readonly MailServiceInterface $mailService, |
| 54 | + private readonly LoggerInterface $logger, |
| 55 | + ) { |
50 | 56 | } |
51 | 57 |
|
52 | 58 | /** |
@@ -115,10 +121,25 @@ public function send(array $data): bool |
115 | 121 | $this->mailService->setBody($this->buildBody($data)); |
116 | 122 |
|
117 | 123 | try { |
118 | | - return $this->mailService->send()->isValid(); |
119 | | - } catch (Throwable) { |
| 124 | + $result = $this->mailService->send(); |
| 125 | + } catch (Throwable $exception) { |
| 126 | + $this->logger->error('Contact form email could not be sent: {message}', [ |
| 127 | + 'message' => $exception->getMessage(), |
| 128 | + 'exception' => $exception, |
| 129 | + ]); |
| 130 | + |
120 | 131 | return false; |
121 | 132 | } |
| 133 | + |
| 134 | + if (! $result->isValid()) { |
| 135 | + $this->logger->error('Contact form email could not be sent: {message}', [ |
| 136 | + 'message' => $result->getMessage(), |
| 137 | + ]); |
| 138 | + |
| 139 | + return false; |
| 140 | + } |
| 141 | + |
| 142 | + return true; |
122 | 143 | } |
123 | 144 |
|
124 | 145 | /** |
|
0 commit comments