Hallo,
ich habe mein Kontaktformular jetzt mal neu gemacht, allerdings läuft es nicht wie gewünscht.
Das neue Formular findet ihr hier: neues Formular
Folgendes Problem: wenn ich alle Felder ordnungsgemäß ausfülle und die Anfrage absende, erfolgt die Fehlermeldung: Es besteht Spamverdacht. Bitte Angaben überprüfen.
Klickt man dann einfach nochmal auf "Absenden", geht die Anfrage raus. Woran liegt das bzw. was habe ich falsch gemacht?
Wenn die Anfrage dann versendet ist, möchte ich gerne, dass das Formular ausgeblendet wird und dort steht: Mitteilung wurde erfolgreich versandt.
Stattdessen erscheint die Mitteilung ganz oben über dem header links.
Hier ist mein Quellcode dazu:
<?php
session_start();
error_reporting(E_ERROR | E_PARSE);
date_default_timezone_set('Europe/Berlin');
$script_root = substr(__FILE__, 0,
strrpos(__FILE__,
DIRECTORY_SEPARATOR)
).DIRECTORY_SEPARATOR;
$remote = getenv("REMOTE_ADDR");
function encrypt($string, $key) {
$result = '';
for($i=0; $i<strlen($string); $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}
@require('config.php');
// form-data should be deleted
if ($_POST['delete']){
unset($_POST);
}
// form has been sent
if ($_POST["kf-km"]) {
// clean data
$name = stripslashes($_POST["name"]);
$email = stripslashes($_POST["email"]);
$betreff = "Sleddogsteam - Kontaktformular";
$nachricht = stripslashes($_POST["nachricht"]);
if($cfg['DATENSCHUTZ_ERKLAERUNG']) { $datenschutz = stripslashes($_POST["datenschutz"]); }
$date = date("d.m.Y | H:i");
$ip = $_SERVER['REMOTE_ADDR'];
$UserAgent = $_SERVER["HTTP_USER_AGENT"];
$host = getHostByAddr($remote);
// formcheck
if(!$name) {
$fehler['name'] = "<span class='errormsg'>Geben Sie bitte Ihren <strong>Namen</strong> ein.</span>";
}
if (!preg_match("/^[0-9a-zA-Z_.-]+@[0-9a-z.-]+\.[a-z]{2,6}$/", $email)) {
$fehler['email'] = "<span class='errormsg'>Geben Sie bitte Ihre <strong>E-Mail-Adresse</strong> ein.</span>";
}
if(!$nachricht) {
$fehler['nachricht'] = "<span class='errormsg'>Geben Sie bitte eine <strong>Nachricht</strong> ein.</span>";
}
// -------------------- SPAMPROTECTION ERROR MESSAGES START ----------------------
if($cfg['Honeypot'] && (!isset($_POST["mail"]) || ''!=$_POST["mail"])){
$fehler['Honeypot'] = "<span class='errormsg'>Es besteht Spamverdacht. Bitte überprüfen Sie Ihre Angaben.</span>";
}
if($cfg['Links'] < preg_match_all('#http(s?)\:\/\/#is', $nachricht, $irrelevantMatches)){
$fehler['Links'] = "<span class='errormsg'>Ihre Nachricht darf ".(0==$cfg['Links'] ? 'keine Links' :
(1==$cfg['Links'] ? 'nur einen Link' :
'maximal '.$cfg['Links'].' Links'
)
)." enthalten.</span>";
}
if(''!=$cfg['Badwordfilter'] && 0!==$cfg['Badwordfilter'] && '0'!=$cfg['Badwordfilter']){
$badwords = explode(',', $cfg['Badwordfilter']); // the configured badwords
$badwordFields = explode(',', $cfg['Badwordfields']); // the configured fields to check for badwords
$badwordMatches = array(); // the badwords that have been found in the fields
if(0<count($badwordFields)){
foreach($badwords as $badword){
$badword = trim($badword); // remove whitespaces from badword
$badwordMatch = str_replace('%', '', $badword); // take human readable badword for error-message
$badword = addcslashes($badword, '.:/'); // make ., : and / preg_match-valid
if('%'!=substr($badword, 0, 1)){ $badword = '\\b'.$badword; } // if word mustn't have chars before > add word boundary at the beginning of the word
if('%'!=substr($badword, -1, 1)){ $badword = $badword.'\\b'; } // if word mustn't have chars after > add word boundary at the end of the word
$badword = str_replace('%', '', $badword); // if word is allowed in the middle > remove all % so it is also allowed in the middle in preg_match
foreach($badwordFields as $badwordField){
if(preg_match('#'.$badword.'#is', $_POST[trim($badwordField)]) && !in_array($badwordMatch, $badwordMatches)){
$badwordMatches[] = $badwordMatch;
}
}
}
if(0<count($badwordMatches)){
$fehler['Badwordfilter'] = "<span class='errormsg'>Folgende Begriffe sind nicht erlaubt: ".implode(', ', $badwordMatches)."</span>";
}
}
}
// -------------------- SPAMPROTECTION ERROR MESSAGES ENDE ----------------------
if($cfg['DATENSCHUTZ_ERKLAERUNG'] && isset($datenschutz) && $datenschutz == ""){
$fehler['datenschutz'] = "<span class='errormsg' style='color:red;font-size:.75rem;'>Sie müssen die <strong>Datenschutzerklärung</strong> akzeptieren.</span><br />";
}
// there are NO errors > send mail
if (!isset($fehler))
{
// ------------------------------------------------------------
// -------------------- send mail to admin --------------------
// ------------------------------------------------------------
// ---- create mail-message for admin
$mailcontent = "Folgendes wurde am ". $date ." Uhr per Formular geschickt:\n" . "--------------------------------------------------------------------------------------\n\n";
$mailcontent .= "Name: " . $name . "\n";
$mailcontent .= "E-Mail: " . $email . "\n\n";
$mailcontent .= "Nachricht:\n" . $_POST['nachricht'] = preg_replace("/\r\r|\r\n|\n\r|\n\n/","\n",$_POST['nachricht']) . "\n\n";
if($cfg['DATENSCHUTZ_ERKLAERUNG']) { $mailcontent .= "\n\nDatenschutz: " . $datenschutz . " \n"; }
$mailcontent .= "\n\nIP Adresse: " . $ip . "\n";
$mailcontent = strip_tags ($mailcontent);
$success = false;
// ---- send mail to admin
if($smtp['enabled'] !== 0) {
require_once __DIR__ . '/smtp.php';
$success = SMTP::send(
$email,
$ihrname,
$empfaenger,
$betreff,
$mailcontent
);
}
else {
$success = sendMyMail($email, $name, $empfaenger, $betreff, $mailcontent);
}
// ------------------------------------------------------------
// ------------------- send mail to customer ------------------
// ------------------------------------------------------------
if(
$success &&
(
2==$cfg['Kopie_senden'] // send copy always
)
){
// ---- create mail-message for customer
$mailcontent = "Vielen Dank für die Nachricht. Wir werden schnellstmöglich darauf antworten.\n\n";
$mailcontent .= "Zusammenfassung: \n" .
"-------------------------------------------------------------------------\n\n";
$mailcontent .= "Name: " . $name . "\n";
$mailcontent .= "E-Mail: " . $email . "\n\n";
$mailcontent .= "Nachricht:\n" . str_replace("\r", "", $nachricht) . "\n\n";
$mailcontent = strip_tags ($mailcontent);
// ---- send mail to customer
if($smtp['enabled'] !== 0) {
SMTP::send(
$empfaenger,
$ihrname,
$email,
"Ihre Anfrage",
$mailcontent,
array()
);
} else {
$success = sendMyMail($empfaenger, $ihrname, $email, "Ihre Anfrage", $mailcontent);
}
}
// redirect to success-page
if($success){
if($smtp['enabled'] === 0 || $smtp['debug'] === 0) {
echo "Die Mitteilung wurde erfolgreich versandt.";
}
}
}
}
// clean post
foreach($_POST as $key => $value){
$_POST[$key] = htmlentities($value, ENT_QUOTES, "UTF-8");
}
?>
<?php
function sendMyMail($fromMail, $fromName, $toMail, $subject, $content){
$boundary = md5(uniqid(time()));
$eol = PHP_EOL;
// header
$header = "From: =?UTF-8?B?".base64_encode(stripslashes($fromName))."?= <".$fromMail.">".$eol;
$header .= "Reply-To: <".$fromMail.">".$eol;
$header .= "MIME-Version: 1.0".$eol;
// content without attachments
if(is_array($attachments) && 0<count($attachments)){
// content
$message = "--".$boundary.$eol;
$message .= "Content-type: text/plain; charset=utf-8".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$message .= $content.$eol;
}
else{
$message = $content;
}
// subject
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
// send mail
return mail($toMail, $subject, $message, $header);
}
?>
Alles anzeigen
Wäre schön, wenn mir jemand helfen kann, da ich von PHP eigentlich null Plan habe.