52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/app.php';
|
|
require_once "PHPMailer.php";
|
|
require_once "SMTP.php";
|
|
require_once "Exception.php";
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
|
function sendEmail(string $emailAddress, string $downloadToken, string $smtpPassword): bool
|
|
{
|
|
$mail = new PHPMailer();
|
|
|
|
$mail->isSMTP();
|
|
$mail->Host = app_env('SMTP_HOST', 'mxe98c.netcup.net');
|
|
$mail->SMTPAuth = true;
|
|
$mail->Username = app_env('SMTP_USERNAME', 'info@silias.ch');
|
|
$mail->Password = $smtpPassword;
|
|
$mail->SMTPSecure = app_env('SMTP_SECURE', 'ssl');
|
|
$mail->Port = app_env_int('SMTP_PORT', 465, 1, 65535);
|
|
$mail->CharSet = 'UTF-8';
|
|
|
|
$mail->isHTML(true);
|
|
$mail->setFrom('info@silias.ch', 'Silias Zefix Export');
|
|
$mail->addAddress($emailAddress);
|
|
$bccAddress = app_env('EXPORT_BCC_EMAIL');
|
|
if ($bccAddress !== '' && filter_var($bccAddress, FILTER_VALIDATE_EMAIL)) {
|
|
$mail->addBCC($bccAddress);
|
|
}
|
|
$mail->addReplyTo('info@silias.ch', 'Silias KLG');
|
|
$mail->Subject = 'Ihr Export von Zefix ist bereit';
|
|
$downloadUrl = app_public_base_url() . '/download.php?token=' . rawurlencode($downloadToken);
|
|
$escapedUrl = htmlspecialchars($downloadUrl, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
$retentionHours = app_env_int('DOWNLOAD_RETENTION_HOURS', 48, 1, 720);
|
|
$mail->Body = 'Nutzen Sie den folgenden Link, um Ihre Daten herunterzuladen:<br><a href="' . $escapedUrl . '">' . $escapedUrl . '</a><br><br>Der Link ist ' . $retentionHours . ' Stunden gültig.';
|
|
$mail->AltBody = "Nutzen Sie den folgenden Link, um Ihre Daten herunterzuladen:\n" . $downloadUrl . "\n\nDer Link ist " . $retentionHours . ' Stunden gültig.';
|
|
|
|
if ($smtpPassword === '') {
|
|
error_log('SMTP password is not configured.');
|
|
return false;
|
|
}
|
|
|
|
if (!$mail->send()) {
|
|
error_log('Export email failed: ' . $mail->ErrorInfo);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|