And here is the sendemail file:
`<?php
require_once('phpmailer/PHPMailerAutoload.php');
$toemails = array();
$toemails[] = array(
'email' => 'tobi.ruettger@googlemail.com', // Your Email Address
'name' => 'A&B Group' // Your Name
);
// Form Processing Messages
$message_success = 'Vielen Dank. Wir haben ihre Nachricht erfolgreich erhalten.';
// Add this only if you use reCaptcha with your Contact Forms
$recaptcha_secret = '6LcxzyMUAAAAAL58bxqJv55jbZoyLn-162wMBUkt'; // Your reCaptcha Secret
$mail = new PHPMailer();
// If you intend you use SMTP, add your SMTP Code after this Line
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if( $_POST['template-contactform-email'] != '' ) {
$company = isset( $_POST['template-contactform-company'] ) ? $_POST['template-contactform-company'] : '';
$name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
$lastname = isset( $_POST['template-contactform-lastname'] ) ? $_POST['template-contactform-lastname'] : '';
$email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
$phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
$subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
$message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';
$subject = isset($subject) ? $subject : 'Neue Nachricht vom Kontaktformular';
$botcheck = $_POST['template-contactform-botcheck'];
if( $botcheck == '' ) {
$mail->SetFrom( $email , $name );
$mail->AddReplyTo( $email , $name );
foreach( $toemails as $toemail ) {
$mail->AddAddress( $toemail['email'] , $toemail['name'] );
}
$mail->Subject = $subject;
$company = isset($company) ? "Firma: $company<br><br>" : '';
$name = isset($name) ? "Vorname: $name<br><br>" : '';
$lastname = isset($lastname) ? "Nachname: $lastname<br><br>" : '';
$email = isset($email) ? "Email: $email<br><br>" : '';
$phone = isset($phone) ? "Telefonnummer: $phone<br><br>" : '';
$subject = isset($subject) ? "Betreff: $subject<br><br>" : '';
$message = isset($message) ? "Nachricht: $message<br><br>" : '';
$referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';
$body = "$company $name $lastname $email $phone $subject $message $referrer";
// Runs only when File Field is present in the Contact Form
if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
$mail->IsHTML(true);
$mail->AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
}
// Runs only when reCaptcha is present in the Contact Form
if( isset( $_POST['g-recaptcha-response'] ) ) {
$recaptcha_response = $_POST['g-recaptcha-response'];
$response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );
$g_response = json_decode( $response );
if ( $g_response->success !== true ) {
echo '{ "alert": "error", "message": "Bitte bestätigen Sie dass Sie kein Roboter sind." }';
die;
}
}
// Uncomment the following Lines of Code if you want to Force reCaptcha Validation
// if( !isset( $_POST['g-recaptcha-response'] ) ) {
// echo '{ "alert": "error", "message": "Captcha not Submitted! Please Try Again." }';
// die;
// }
$mail->MsgHTML( $body );
$mail->CharSet="UTF-8";
$sendEmail = $mail->Send();
if( $sendEmail == true ):
echo '{ "alert": "success", "message": "' . $message_success . '" }';
else:
echo '{ "alert": "error", "message": "Ihre Nachricht konnte auf Grund eines **Fehlers** nicht gesendet werden. Bitte versuchen Sie es später noch einmal.<br /><br />**Reason:**<br />' . $mail->ErrorInfo . '" }';
endif;
} else {
echo '{ "alert": "error", "message": "Bot **Detected**.! Clean yourself Botster.!" }';
}
} else {
echo '{ "alert": "error", "message": "Bitte **füllen Sie alle Pflichtfelder aus**." }';
}
} else {
echo '{ "alert": "error", "message": "Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut." }';
}
?>