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

38 lines
1.1 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;
}
require(dirname(__FILE__) . '/../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' => '***REMOVED***', //'kontakt@tobias-radloff.de',
'fromName' => 'Tobias Radloffs Kontaktformular'
];
try {
SendEmail($_POST['email'], $mailContents);
} catch (Exception $e) {
GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
}
header("Location: {$successURL}");
?>