我知道这个问题被问过很多次,但是我找不到解决我问题的方法。我读了这篇文章: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
https://wordpress.org/support/topic/smtp-connect-failed-error-and-what-to-do/
SMTP connect() failed phpmailer
这是我使用的教程:https://www.youtube.com/watch?v=t0zwgJrSHd4
**我得到的错误是:** SMTP connect()失败。
我的代码:
<?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和my_pwd替换为我的信息
-我在Google帐户中允许使用安全性较低的应用程序。 -我的电子邮件和密码正确。
谢谢!
答案 0 :(得分:2)
您在主机名上犯了一个小错误:
$mail-> Host = "smpt.gmail.com";
是
$mail-> Host = "smtp.gmail.com";