Compare commits
No commits in common. "2edfdcc179415fd319483ecff8be93a59e9eee69" and "b65755de8d231affd95edb390c5a4ef25c415086" have entirely different histories.
2edfdcc179
...
b65755de8d
@ -1,35 +1,17 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
function sanitize_text(string $name, string $type) {
|
||||
$filters = array(
|
||||
'text' => FILTER_SANITIZE_SPECIAL_CHARS,
|
||||
'email' => FILTER_SANITIZE_EMAIL,
|
||||
);
|
||||
function sanitize_text(string $name) {
|
||||
$text = filter_var($_POST[$name], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
||||
$text = trim($text);
|
||||
$text = filter_var($_POST[$name], $filters[$type]);
|
||||
$text = stripslashes($text);
|
||||
$text = htmlspecialchars($text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
function prepare_message_body($message) {
|
||||
// Replace HTML-Entities with actual carriage returns and line feeds
|
||||
$message = str_replace(" ", "\r", $message);
|
||||
$message = str_replace(" ", "\r", $message);
|
||||
|
||||
// Ensure line breaks via carriage return + line feed
|
||||
$message = str_replace("\r\n", "\n", $message);
|
||||
$message = str_replace("\n", "\r\n", $message);
|
||||
|
||||
$message = "Nachricht von: $name\r\n\r\n" . $message;
|
||||
$message = base64_encode($message);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sending email
|
||||
* Sending email (Platzhalter)
|
||||
*
|
||||
* mail(): Braucht auf dem Server einen korrekt konfigurierten Mailserver
|
||||
* phpmailer: Bibliothek, der per Composer installiert wird. Tut ganz gut mit SMTP.
|
||||
@ -37,14 +19,12 @@ function prepare_message_body($message) {
|
||||
function send_message_to_office($subject, $message, $name, $email) {
|
||||
return mail(
|
||||
getenv('WTF_CONTACT_TO'),
|
||||
"=?UTF-8?B?" . base64_encode($subject) . "?=",
|
||||
prepare_message_body($message),
|
||||
$subject,
|
||||
$name . "\r\n" . $message,
|
||||
$additional_headers = array(
|
||||
"From" => getenv('WTF_CONTACT_FROM'),
|
||||
"Reply-To" => $email,
|
||||
"Return-Path" => getenv('WTF_RETURN_PATH'),
|
||||
"Content-Type" => "text/plain; charset=utf-8",
|
||||
"Content-Transfer-Encoding" => "base64",
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -95,10 +75,10 @@ function prepare_response() {
|
||||
$response['errors'][] = 'Wir glauben Sie sind ein Bot.';
|
||||
}
|
||||
if (!array_key_exists('errors', $response)) {
|
||||
$subject = sanitize_text('subject', 'text');
|
||||
$message = sanitize_text('message', 'text');
|
||||
$name = sanitize_text('name', 'text');
|
||||
$email = sanitize_text('email', 'email');
|
||||
$subject = sanitize_text('subject');
|
||||
$message = sanitize_text('message');
|
||||
$name = sanitize_text('name');
|
||||
$email = sanitize_text('email');
|
||||
|
||||
if (!send_message_to_office($subject, $message, $name, $email)) {
|
||||
$response['errors'][] = 'Ihre Nachricht konnte nicht übermittelt werden.';
|
||||
|
Loading…
Reference in New Issue
Block a user