Hey everyone, I have a really weird problem
I am using phpmailer & captcha on my php file that first validates the captcha, then uses phpmailer to send mail. I’ve done this several times before but I’m getting stuck now. The page is just timing out…
It’s super weird because I can execute the captcha portion alone, and it works fine. It will give me a successful response. I can also execute the phpmailer portion alone as well, and it will send mail to the designated email address. BUT when I combine the two, the page will just time out, and eventually it will parse the rest of the page and return an error.
I don’t know if this is an issue with captcha, or an issue with phpmailer, because again, they both work just fine if I isolate them from each other.
Here is my code:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
echo "hi";
$responseKey = $_POST["captcha"];
$secretKey = "";
$userIP = $_SERVER["REMOTE_ADDR"];
$response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$responseKey."&remoteip=".$_SERVER["REMOTE_ADDR"]), true);
if ($response["success"] == false) {
print_r("error");
}
$userDetails = json_decode($_POST["jsonFile"], true);
$userDetails["name"] = filter_var($userDetails["name"], FILTER_SANITIZE_STRING);
$userDetails["message"] = filter_var($userDetails["message"], FILTER_SANITIZE_STRING);
$userDetails["email"] = filter_var($userDetails["email"], FILTER_SANITIZE_EMAIL);
$userDetails["phone"] = filter_var($userDetails["phone"], FILTER_SANITIZE_NUMBER_INT);
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host="smtp.ionos.com";
$mail->Port = 587;
$mail->Username = '';
$mail->Password="";
$mail->setFrom('', 'Contact Inquiry'.$userDetails['name']);
$mail->addAddress('', 'No-Reply');
$mail->Subject = 'Contact Inquiry'.$userDetails['name'];
$mail->Body = "Sent From: ".$userDetails['name']."<br>"."Email: ".$userDetails['email']."<br>"."Tel: ".$userDetails['phone']."<br>"."Message: ".$userDetails['message']."<br>";
$mail->isHTML(true);
if($mail->send()){
print_r(200);
}
else{
print_r(300);
}
So here it gets even more bizarre. As the page is timing out, it will eventually print out the following:
“hi error 300”
So the “hi” is coming from the top echo, the “error” is coming from the condition if captcha returns a false response, and the 300 is coming from phpmailer if it fails to send mail.
So again, the page will time out, and it will fail on captcha and on phpmailer. But if I comment out each component, they work completely fine.
I am also calling the page via post method on ajax, however the issue still occurs if I just access the page directly.
If you are curious, the page is www.dfctaxcenter.com/contact/contact.php