<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// bestanden
$dir = str_replace('\\', '/', dirname(__FILE__).'/PHPMailer/src');
require $dir . '/Exception.php';
require $dir . '/PHPMailer.php';
require $dir . '/SMTP.php';
if (array_key_exists('contact_email', $_POST)) {
date_default_timezone_set('Europe/Amsterdam');
// smtp connection
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.xxxxx.nl';
$mail->SMTPSecure = 'ssl'; // tls, ssl
$mail->Port = 465; // tls:587 ssl:465
// smtp authentication
$mail->SMTPAuth = true;
$mail->Username = 'info@example.nl';
$mail->Password = 'xxxxx';
// debug geen:0 client:1 server/client:2
$mail->SMTPDebug = 0;
// FROM: existing mailbox in your domain
// DO NOT use the submitter's address here
$mail->setFrom('noreply@example.nl', 'No Reply');
// TO: your address
$mail->addAddress('info@example.nl');
// optional cc and bcc
// $mail->addCC('cc@example.nl');
// $mail->addBCC('bcc@example.nl');
if (array_key_exists('contact_name', $_POST) && array_key_exists('contact_message', $_POST)) {
if ($mail->addReplyTo($_POST['contact_email'], $_POST['contact_name'])) {
$mail->Subject = 'Contact website';
$message = '<div>Naam: ' . $_POST['contact_name'] . '</div>';
$message .= '<div>Email: ' . $_POST['contact_email'] . '</div>';
$message .= '<div>Bericht: ' . $_POST['contact_message'] . '</div>';
// html part
$msg = str_replace(PHP_EOL, '<br>', $message);
$msg = str_replace('\\', '|', $msg);
$mai->Body = $msg;
// text part
$txt = strip_tags($message);
$mail->AltBody = $txt;
// send the message, check for errors
if (!$mail->send()) {
echo 'Sorry, er gaat wat mis. Probeer het later nog eens.';
if ($mail->SMTPDebug <> 0) {
echo $mail->ErrorInfo;
}
} else {
echo 'Bedankt voor uw mail.';
}
} else {
echo 'Ongeldige naam of emailadres.';
}
} else {
echo 'Ongeldige naam of bericht.';
}
} else {
echo 'Formulier ingediend zonder e-mailadres.';
}