Add PHP contactform
Add initial version of the PHP contact form.
This commit is contained in:
parent
ec09644398
commit
bb5bb36c2d
46
static/contactform.php
Normal file
46
static/contactform.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
require 'PHPMailer/src/Exception.php';
|
||||
require 'PHPMailer/src/PHPMailer.php';
|
||||
require 'PHPMailer/src/SMTP.php';
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
// Lade die Konfigurationsdatei
|
||||
$config = require '/var/www/vhosts/hosting205886.ae948.netcup.net/bar-filipo.de/credentials/config.php';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$name = htmlspecialchars($_POST['name']);
|
||||
$email = htmlspecialchars($_POST['email']);
|
||||
$message = htmlspecialchars($_POST['message']);
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
// SMTP-Einstellungen aus der Konfigurationsdatei laden
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $config['smtp_host'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $config['smtp_username'];
|
||||
$mail->Password = $config['smtp_password'];
|
||||
$mail->SMTPSecure = $config['smtp_encryption'];
|
||||
$mail->Port = $config['smtp_port'];
|
||||
|
||||
// E-Mail-Einstellungen
|
||||
$mail->setFrom($config['smtp_username'], 'Formular-Betreiber');
|
||||
$mail->addAddress($config['recipient']);
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = 'Neue Nachricht vom Kontaktformular';
|
||||
$mail->Body = "Name: $name<br>E-Mail: $email<br>Nachricht: $message";
|
||||
$mail->AltBody = "Name: $name\nE-Mail: $email\nNachricht: $message";
|
||||
|
||||
$mail->send();
|
||||
echo 'Nachricht wurde erfolgreich gesendet.';
|
||||
} catch (Exception $e) {
|
||||
echo "Fehler beim Senden der Nachricht: {$mail->ErrorInfo}";
|
||||
}
|
||||
} else {
|
||||
echo 'Ungültige Anfrage';
|
||||
}
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user