41 lines
1.4 KiB
PHP
41 lines
1.4 KiB
PHP
<?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);
|
|
}
|