<?php
// Foutafhandeling van PHP aanzetten. In productie deze onderste twee lijnen commentariseren met een // ervoor.
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('log_errors', 1);
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// bestanden
$dir = str_replace('\\', '/', dirname(__FILE__) . '/PHPMailer/src');
echo "Pad naar PHPmailer is: " . $dir;
// laad de benodige bestanden in
require $dir . '/Exception.php';
require $dir . '/PHPMailer.php';
require $dir . '/SMTP.php';
// Tijdzone instellen
date_default_timezone_set('Europe/Amsterdam');
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$response = $_POST["g-recaptcha-response"];
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => 'keyxxxxx',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha = json_decode($verify);
if ($captcha->success == false || $captcha->score <= 0.5) {
echo "Sorry! Je bent gedetecteerd als een robot. Stuur maar een mail!";
} else {
echo "Je inzending is goedgekeurd";
// stuur hier een mail
}
}
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
$mail->SMTPDebug = 2; // Debugging voor SMTP. 0 = uit, of 1,2 of 3 voor hogere debugging. 2 is gangbaar bij testen.
$mail->Host = 'mail.provider.nl'; // bijvoorbeeld 'mail.ziggo.nl'
$mail->SMTPSecure = 'ssl'; // 'ssl' of 'tls'
$mail->Port = 465; // 465 (bij ssl) of 587 (bij tls)
$mail->SMTPAuth = true;
//SMTP Authenticatie
$mail->Username = 'test@example.nl'; // emailadres of emailnaam of emailcode ofzo
$mail->Password = 'wachtwoord';
// E-mail instellingen
$mail->setFrom('test@example.nl', ''); // Stel de afzender in, dit moet een bestaande afzender zijn.
$mail->addReplyTo($_POST['contact_email'], $_POST['contact_name']); // Stel een Reply-To adres in
$mail->AddAddress("test@example.nl" ,"Naam van bedrijf");
$mail->Subject = 'Aanvraag informatie'; // Stel hier het onderwerp in
$mail->Body = $_POST['contact_message']; // Stel hier de body van de mail in.
// Verzend het bericht
if (!$mail->send()){
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Bericht is verzonden';
}
}
?>