【问题标题】:phpmailer : Could not connect to SMTP host [duplicate]phpmailer:无法连接到 SMTP 主机 [重复]
【发布时间】:2016-05-21 17:21:24
【问题描述】:

这是来自 phpmailer 文件的示例代码。我编辑了一些代码,它给了我错误。我也尝试更改端口号,但每次都给我同样的错误

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                       // set mailer to use SMTP
$mail->Host = "localhost";            // specify main and backup server
$mail->SMTPAuth = true;               // turn on SMTP authentication
$mail->Username = "mygmail@gmail.com";  // SMTP username
$mail->Password = "password_is_correct"; // SMTP password

$mail->From = "mygmail@gmail.com";
$mail->FromName = "Harsh Patel";
$mail->AddAddress("mygmail@gmail.com");          // name is optional

$mail->WordWrap = 50;                         // set word wrap to 50 characters
$mail->IsHTML(true);                            // set email format to HTML

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>

【问题讨论】:

  • 您的代码基于一个过时的示例,并且您使用的是旧版本的 PHPMailer。 Get the latest。您还应该在发帖前进行搜索。

标签: php phpmailer


【解决方案1】:

在您使用 gmail smtp 时尝试这些更改

$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 587;
$mail->SMTPSecure = 'tls';

【讨论】:

    猜你喜欢
    • 2012-05-24
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    相关资源
    最近更新 更多