Created
October 15, 2015 17:18
-
-
Save busti/f976c7347556e27814f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
mb_internal_encoding('UTF-8'); | |
function addInformation(DOMDocument $dom, $fields) { | |
$tags = $dom->getElementsByTagName('input'); | |
for ($i = 0; $i < $tags->length; $i++) { | |
foreach ($tags->item($i)->attributes as $attr) { | |
if ($attr->nodeName == 'name') { | |
$tags->item($i)->setAttribute('value', $fields[$attr->nodeValue]); | |
} | |
} | |
} | |
$dom->getElementsByTagName('textarea')->item(0)->nodeValue = $fields['msg']; | |
} | |
$fields = array('fname', 'lname', 'str', 'strnr', 'plz', 'email', 'tel', 'msg'); | |
$dfields = array('fname', 'lname', 'email', 'tel'); | |
$captcha; | |
$alert = false; | |
foreach ($fields as $field) { | |
if (isset($_POST['fname'])) { | |
$fields[$field] = $_POST[$field]; | |
} else { | |
header('HTTP/1.1 500 Internal Server Error'); | |
echo '<h2>500 Internal Server Error!</h2>'; | |
exit; | |
} | |
if (in_array($field, $dfields)) { | |
if ($fields[$field] == null || $fields[$field] == '') | |
$alert = true; | |
} | |
} | |
if (isset($_POST['g-recaptcha-response'])) { | |
$captcha = $_POST['g-recaptcha-response']; | |
} else { | |
header('HTTP/1.1 500 Internal Server Error'); | |
echo '<h2>500 Internal Server Error!</h2>'; | |
exit; | |
} | |
if (!$captcha || $alert) { | |
$html = new DOMDocument(); | |
libxml_use_internal_errors(true); | |
$html->loadHTMLFile('kontakt.html'); | |
libxml_use_internal_errors(false); | |
if ($alert) { | |
$html->getElementById('formError')->setAttribute('style', 'display: block !important'); | |
} | |
if (!$captcha) { | |
$html->getElementById('captError')->setAttribute('style', 'display: block !important'); | |
} | |
addInformation($html, $fields); | |
echo $html->saveHTML(); | |
exit; | |
} | |
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=SecretKeyGoesHere&response='.$captcha.'&remoteip='.$_SERVER['REMOTE_ADDR']); | |
$data = json_decode($response); | |
if (isset($data->success) AND $data->success==true) { | |
readfile('nachricht.html'); | |
} else { | |
$html = new DOMDocument(); | |
libxml_use_internal_errors(true); | |
$html->loadHTMLFile('kontakt.html'); | |
libxml_use_internal_errors(false); | |
$html->getElementById('captError')->setAttribute('style', 'display: block !important'); | |
addInformation($html, $fields); | |
echo $html->saveHTML(); | |
exit; | |
} | |
/*foreach ($fields as $field) { | |
if ($fields[$field] == null || $fields[$field] == '') { | |
$fields[$field] = '--Keine Angabe--'; | |
} | |
}*/ | |
$to = '[email protected]'; | |
$subject = 'Eine neue Nachicht wurde von deiner Website versendet'; | |
$headers = 'Reply-To: '. strip_tags($fields['email']) . '\r\n'; | |
$headers .= 'MIME-Version: 1.0\r\n'; | |
$headers .= 'Content-Type: text/html; charset=utf-8\r\n'; | |
$message = | |
'Absenderinformationen<br>' . | |
'Name: ' .$fields['fname']. '<br>' . | |
'Nachname: ' .$fields['lname']. '<br>' . | |
'Straße: ' .$fields['str']. '<br>' . | |
'Hausnummer: ' .$fields['strnr']. '<br>' . | |
'Postleitzahl: ' .$fields['plz']. '<br>' . | |
'E-Mail Addresse: ' .$fields['email']. '<br>' . | |
'Telefonnummer: ' .$fields['tel']. '<br><br><br>' . | |
'Nachicht:<br>' .$fields['msg']; | |
mail($to, $subject, $message, $headers); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment