feat: core utilities - CSRF, auth, encryption, PHPMailer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
40
includes/mailer.php
Normal file
40
includes/mailer.php
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user