Ik heb een contactformulier dat ik via PHPMailer verstuur.
Ik heb alle bug-meldingen aan staan. Ik heb ook getest dat het formulier meldt wanneer er iets fout is.
Dus volgens mij, heb ik alles goed staan, en nadat ik SEND heb gedaan, krijg ik de melding dat het formulier succesvol verzonden is. Echter, de mail komt niet aan!!!
Ik heb ook spam en zo gechecked, maar daar ook niks.
Mijn code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
//Set variables
$firstname = $lastname = $email = $contactmessage = "";
$err = array();
$msg = "";
//Make function to test the input data
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['firstname'])) {
$err['firstname'] = "Firstname is required";
//Limit length and strip HTML tags
} else {
$firstname = test_input($_POST['firstname']);
if(!preg_match("/^[a-zA-Z ]*$/",$firstname)) {
$err['firstname'] = 'Only letters and white space allowed!';
}
}
if (empty($_POST['lastname'])) {
$err['lastname'] = "Lastname is required";
//Limit length and strip HTML tags
} else {
$lastname = test_input($_POST['lastname']);
if(!preg_match("/^[a-zA-Z ]*$/",$lastname)) {
$err['lastname'] = 'Only letters and white space allowed!';
}
}
//Make sure the address they provided is valid before trying to use it
if (empty($_POST['email'])) {
$err['email'] = 'Email is required';
} else {
$email = test_input($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$err['email'] = "Invalid email format";
}
}
//Apply some basic validation and filtering to the message
if (empty($_POST['contactmessage'])) {
$err['contactmessage'] = 'What is your message';
//Limit length and strip HTML tags
} else {
$contactmessage = test_input($_POST['contactmessage']);
}
$name = $firstname.' '.$lastname;
if (count($err) == 0) {
require_once '../../data/data.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 4;
$mail->Host = $host;
$mail->Port = $port;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = $user;
$mail->Password = $pass;
//It's important not to use the submitter's address as the from address as it's forgery,
//which will cause your messages to fail SPF checks.
//Use an address in your own domain as the from address, put the submitter's address in a reply-to
$mail->setFrom = ($from.', '.$fromName);
$mail->addReplyTo($email, $name);
$mail->addAddress = ($addAddress.', '.$addName);
$mail->Subject = 'Contact request';
$body = 'Name: '.$firstname.' '.$lastname;
$body .= '<br>Email: '.$email;
$body .= '<br>Message: '.$contactmessage;
$mail->Body = $body;
$mail->AltBody = $body;
//include_once '../../data/data.php';
if ($mail->send()) {
$success = "<p style='margin-left:10%;padding-bottom:2%;width:60%'><strong>Thank you for contacting us.<br>The following message is successfully sent:</strong><br>";
$success .= $name."<br>".$email."<br>".$contactmessage."</p>";
}
else {
$fail= 'Mailer Error: ' . $mail->ErrorInfo;
}
}
}
?>