【问题标题】:PHPmailer fails,error: SMTP connect() failedPHPmailer 失败,错误:SMTP 连接()失败
【发布时间】:2020-04-29 17:50:06
【问题描述】:

我知道这个问题被问了很多次,但我找不到解决问题的方法。我读过这篇文章: 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() failed.

我的代码:

<?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 帐户中使用不太安全的应用程序。 - 我的邮箱和密码是正确的。

谢谢!

【问题讨论】:

    标签: php phpmailer


    【解决方案1】:

    你在主机名上犯了一个小错误:

    $mail-> Host = "smpt.gmail.com";
    

    它是:

    $mail-> Host = "smtp.gmail.com";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-13
      • 2015-08-09
      • 2016-11-10
      • 2014-05-20
      • 2016-07-14
      • 1970-01-01
      • 2015-09-25
      • 2016-11-13
      相关资源
      最近更新 更多