I know this question was asked many times but I couldn't find something to solve my problem. I've read this posts: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
https://wordpress.org/support/topic/smtp-connect-failed-error-and-what-to-do/
SMTP connect() failed phpmailer
and this is the tutorial I used: https://www.youtube.com/watch?v=t0zwgJrSHd4
**the error I get is:**SMTP connect() failed.
my code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
$name= $_POST['name'];
$email= $_POST['email'];
$message= $_POST['message'];
$subject1 = "thank you for contacting CouplesLove Support! -No replay-";
$body1 = "hello $name! thank you for contacting us! we will replay to this email:$email <br> your message: $message <br><br> this is an automated message, please do not replay to this email";
$subject2 ="new contact submition from $name";
$body2 ="submition: <br> name:$name <br> email: $email <br> message:$message";
require_once "../PHPMailer/PHPMailer.php";
require_once "../PHPMailer/SMTP.php";
require_once "../PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail-> isSMTP();
$mail-> Host = "smpt.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "My_email@gmail.com";
$mail->Password = "My_pwd";
$mail->Port = 587;
$mail-> SMTPSecure = "tls";
$mail->IsHTML(true);
$mail-> SetFrom($email, $name);
$mail-> AddAddress("My_email@gmail.com");
$mail-> Subject = $subject2;
$mail->Body = $body2;
if($mail->Send()){
header("Location: ../contact.php?success");
}
else{
header("Location: ../contact.php?$mail->ErrorInfo");
echo $mail->ErrorInfo;
}
?>
my_email and my_pwd are replaced by my information
-I allowed less secure apps in my google account. -my email and password are correct.
thank you!
You made a little error on the host name :
$mail-> Host = "smpt.gmail.com";
it's :
$mail-> Host = "smtp.gmail.com";