addPublicPath('/contact*'); if (function_exists('add_filter')) { add_filter('contact.subject_sanitize', function ($subject) { $subject = is_string($subject) ? $subject : ''; $subject = strip_tags($subject); $subject = preg_replace('/\s+/', ' ', trim($subject)); return $subject; }, 10); add_filter('contact.message_sanitize', function ($message) { $message = is_string($message) ? $message : ''; $message = strip_tags($message); $message = trim($message); return $message; }, 10); } if (function_exists('add_action')) { add_action('contact.submitted', function (Contact $contact) { $dsn = $_ENV['MAILER_DSN'] ?? ''; if (!$dsn) { $transport = Transport::fromDsn(sprintf( 'smtp://%s:%s@%s:%s?encryption=%s', $_ENV['MAIL_USERNAME'] ?? '', $_ENV['MAIL_PASSWORD'] ?? '', $_ENV['MAIL_HOST'] ?? 'localhost', $_ENV['MAIL_PORT'] ?? '25', $_ENV['MAIL_ENCRYPTION'] ?? '' )); } else { $transport = Transport::fromDsn($dsn); } $mailer = new Mailer($transport); $to = $_ENV['MAIL_TO_ADDRESS'] ?? $_ENV['MAIL_FROM_ADDRESS'] ?? null; if (!$to) { return; } $email = (new Email()) ->from($_ENV['MAIL_FROM_ADDRESS'] ?? 'no-reply@localhost') ->to($to) ->subject('Nova mensagem de contato: ' . ($contact->subject ?? '')) ->html( '

Nova mensagem de contato

' . '

Nome: ' . htmlspecialchars($contact->name) . '

' . '

Email: ' . htmlspecialchars($contact->email) . '

' . '

Telefone: ' . htmlspecialchars((string)$contact->phone) . '

' . '

Assunto: ' . htmlspecialchars($contact->subject) . '

' . '

Mensagem:
' . nl2br(htmlspecialchars($contact->message)) . '

' ); try { $mailer->send($email); } catch (\Throwable $e) { } }, 10); } } }