feat: core utilities - CSRF, auth, encryption, PHPMailer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Gestoría LP
2026-03-01 23:28:54 +00:00
parent 10bc97e8b9
commit 322fc78f2b
7 changed files with 7299 additions and 0 deletions

40
includes/mailer.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/../vendor/phpmailer/PHPMailer.php';
require_once __DIR__ . '/../vendor/phpmailer/SMTP.php';
require_once __DIR__ . '/../vendor/phpmailer/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
function sendEmail(string $subject, string $htmlBody, ?string $toEmail = null): bool {
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USER;
$mail->Password = SMTP_PASS;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = SMTP_PORT;
$mail->CharSet = 'UTF-8';
$mail->setFrom(SMTP_USER, SMTP_FROM_NAME);
$mail->addAddress($toEmail ?? SMTP_USER);
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $htmlBody;
$mail->AltBody = strip_tags($htmlBody);
$mail->send();
return true;
} catch (\Exception $e) {
error_log('Email error: ' . $e->getMessage());
return false;
}
}
function buildWhatsAppLink(string $serviceName, string $clientName, string $phone): string {
$message = "Hola, soy *{$clientName}* y estoy interesado/a en el servicio de *{$serviceName}*. Mi teléfono es {$phone}. Acabo de enviar mi solicitud por la página web.";
return 'https://wa.me/' . WHATSAPP_NUMBER . '?text=' . urlencode($message);
}