Files
2025-11-02 22:52:08 +01:00

70 lines
1.6 KiB
Plaintext

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
function sendmail($subject, $from, $body, $cc=[], $bcc=[], $to=[]) {
global $develop;
$ret = [];
$ret['error'] = false;
$mail = new PHPMailer(true);
try {
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Debugoutput = function($str, $level) {
// Debug-Ausgabe in Datei schreiben
file_put_contents(__DIR__ . '/phpmailer_debug.log',
date('Y-m-d H:i:s') . " [Level $level] $str\n", FILE_APPEND);
};
if ($develop == 'true') {
$mail->Host = 'mailhog';
$mail->Port = 1025;
} else {
$mail->SMTPAuth = true;
$mail->Host = "mail.gmx.de";
$mail->Port = "587";
$mail->SMTPSecure = "tls";
$mail->Username = "sternwarte.welzheim@gmx.de";
$mail->Password = "4NT&%nH9&5wz";
}
$mail->setFrom("sternwarte.welzheim@gmx.de", 'Sternwarte-Welzheim');
if (count($to) != 0) {
foreach ($to as $t) {
$mail->addAddress($t);
}
}
$mail->Subject = $subject;
$mail->Body = $body;
if (count($cc) != 0) {
foreach ($cc as $c) {
$mail->addCC($c);
}
}
if(count($bcc) != 0) {
foreach ($bcc as $bc) {
$mail->addBCC($bc);
}
}
$mail->addReplyTo($from);
$mail->send();
$ret ['oktext'] = 'Mail erfolgreich versendet';
} catch (Exception $e) {
$ret['error'] = true;
$ret['errortext'] = $mail->ErrorInfo;
}
return $ret;
}
?>