dsfh40613182 2014-01-09 11:25
浏览 791

无法连接到SMTP主机。 邮件程序错误:SMTP错误:无法连接到SMTP主机

I'm using PHPMailer for sending mail with authentication, but i'm getting the following message when i tried to run my sendmessage.php.

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) 
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

can anyone please tell me why i'm getting this message...and some solution for this

Mycode is as given below

sendmessage.php

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>

<?php

//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded


$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myemailid@gmail.com";
$mail->Password = "myemailpassword";
$mail->SetFrom('myemailid@gmail.com','vgvb');
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress('myfriendemailid');
 if(!$mail->Send())
    {
    echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
    echo "Message has been sent";
    }
?>

</body>
</html>
  • 写回答

3条回答 默认 最新

  • dongshou7903 2014-01-09 11:33
    关注

    Try this

    $mail->Host = "ssl://smtp.gmail.com";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题