ARTICLE AD BOX
I am trying to send an email via gmail app password using current version of PHPMailer library in Core PHP for a contact form.
but I keep receiving this following error:
2026-02-12 06:34:55 SMTP ERROR: Failed to connect to server: (0) SMTP Error: Could not connect to SMTP host.
Its working on localhost but doesn't work on server (Server name is Webuzo).
$mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = '[email protected]'; // gmail which i used to create app pass $mail->Password = 'xxxxxxxxxxxxxxxx'; // gmail App Password $mail->SMTPSecure = 'ssl'; $mail->Port = 465; $mail->SMTPDebug = 2; $mail->setFrom('[email protected]', 'Contact'); $mail->addAddress('[email protected]'); $mail->isHTML(true); $mail->Subject = 'Enquiry from Rodevra'; $mail->Body = '<p>test</p>'; if(!$mail ->send()){ $result="Something went wrong. Please try again."; } else{ $result="Thanks ".$_POST['fname']." ".$_POST['lname']." for contacting us. We'll get back to you soon!"; }I tried port 587 with TLS as well, but I received the same connection timeout.
I checked the network tab, but nothing appeared except status 200.
Even when I tried using the domain configurations which I created for the email, the same error appeared: "Could not connect to SMTP," with a "name or service unknown" message.
I have checked other posted questions, but I haven't found anything helpful.
