Issues with captcha & mailer

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 = "";
$response = json_decode(file_get_contents("".$secretKey."&response=".$responseKey."&remoteip=".$_SERVER["REMOTE_ADDR"]), true);
if ($response["success"] == false) {

$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->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = '';
$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>";

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

Instead of returning 300, what happens if you return $mail->ErrorInfo ?

1 Like

My god you beautiful son of a bitch

MAN it was the freaking SMTP that was causing this blockage. I have been going at this crap for hours and hours and hours.

thank you so much my friend, i will tell this story about you to my grand kids you better believe that

[quote=“alex067, post:1, topic:317881”]
the “error” is coming from the condition if captcha returns a false response,[/quote]

And note that you continue to send the email even if the captcha returns a false response, presumably that’s just while you are testing.

Don’t know if they have improved it lately but last time I used the google recaptcha it was broken within a day and i started getting spam.

I ended up just putting a picture of an animal like a dog and asking people to write what the type of animal is in a box. Didn’t have a problem with bots after that and just as many people still going through the form without a problem.

I guess just keep an eye on it if it’s sending out emails.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.