t-r.de/content/misc/contact.php

40 lines
1.2 KiB
PHP

<?php
// inspired by: https://www.unixdude.net/posts/2017/Nov/29/pelican-contact-form/
// The 'address' form field is in the code but doesn't get rendered on the page. The message will only get sent if the field is empty, thus weeding out bots that will just fill out any form field
if ( $_POST['address'] != '' ) {
header('Location: /');
exit;
}
$webroot = $_SERVER['DOCUMENT_ROOT'];
require($webroot . '/functions.php');
$successURL = '/success.html';
$errorURL = '/error.html';
$err = 'Nachrichtversand fehlgeschlagen';
$body = [
'Diese Nachricht wurde soeben durch das Kontaktformular auf t-r.de übermittelt:',
"Name: {$_POST['name']}",
"Emailadresse: {$_POST['email']}",
"Nachricht: {$_POST['nachricht']}"
];
$mailContents = [
'subject' => 'Diese Nachricht kam ueber das Kontaktformular von t-r.de',
'bodyText' => implode("\n\n", $body),
'fromAddress' => $general['notificationAddress'],
'fromName' => 'Tobias Radloffs Kontaktformular'
];
try {
SendEmail($general['notificationAddress'], $mailContents);
} catch (Exception $e) {
GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
}
// success
GracefulExit($successURL, "Deine Nachricht wurde erfolgreich verschickt und ist jetzt auf dem Weg zu mir.");
?>