Files
sternwarte_server/html/sternwarte/TSTMAIL/index.php
2025-11-02 22:52:08 +01:00

75 lines
2.0 KiB
PHP

<?php
// index.php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
// Konfiguration: Account
$myuser = "sonderfuehrung@sternwarte-welzheim.de";
$mypass = "UNK44mkap5";
// Wenn Formular abgeschickt wurde:
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$subject = trim($_POST["subject"]);
$message = trim($_POST["message"]);
$mail = new PHPMailer(true);
try {
// SMTP-Einstellungen
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->SMTPAuth = true;
$mail->Username = $myuser;
$mail->Password = $mypass;
$mail->SMTPSecure = 'tls'; //PHPMailer::ENCRYPTION_STARTTLS; // oder PHPMailer::ENCRYPTION_STARTTLS
$mail->Port = 587; // 587 für STARTTLS
// Absender und Empfänger
$mail->setFrom($myuser, 'Webmailer');
$mail->addAddress('rxf@fuerst-stuttgart.de', 'Empfänger');
// Inhalt
$mail->isHTML(false);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
$status = "✅ E-Mail wurde erfolgreich gesendet!";
} catch (Exception $e) {
$status = "❌ Fehler beim Senden: {$mail->ErrorInfo}";
}
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Mini PHP Mailer</title>
<style>
body { font-family: sans-serif; max-width: 600px; margin: 40px auto; }
form { display: flex; flex-direction: column; gap: 10px; }
input, textarea { padding: 8px; font-size: 1em; width: 100%; }
button { padding: 10px; font-size: 1em; cursor: pointer; }
.status { margin-top: 20px; }
</style>
</head>
<body>
<h1>Mail senden über Exchange</h1>
<form method="post">
<label>Betreff:</label>
<input type="text" name="subject" required>
<label>Nachricht:</label>
<textarea name="message" rows="6" required></textarea>
<button type="submit">Senden</button>
</form>
<?php if (!empty($status)): ?>
<div class="status"><?= htmlspecialchars($status) ?></div>
<?php endif; ?>
</body>
</html>