无法连接到服务器:连接被拒绝(111) [英] Failed to connect to server: Connection refused (111)
问题描述
我正在使用PHPMailer发送smtp电子邮件.如果我在WordPress网站中使用相同的设置,则可以正常工作.但我的首要任务是在自定义php页面中使用.在那里,它给出了以下错误
I am using PHPMailer to send the smtp emails. If I use the same setting in a WordPress site, it works fine. But my priority is to use in a custom php page. And there, it is giving the following errors
SMTP错误:无法连接到服务器:连接被拒绝(111)
SMTP connect()失败.
SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我的代码在下面
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'emails/PHPMailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 587;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "mzubim@gmail.com";
$mail->Password = "password";
//Set who the message is to be sent from
$mail->setFrom('mzubim@gmail.com', 'Zubair Mushtaq');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@gmail.com', 'Secure Developer');
//Set who the message is to be sent to
$mail->addAddress('abulogics@gmail.com', 'Abulogicss');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("convert HTML into a basic plain-text alternative body");
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
推荐答案
尝试正常工作
<?php
include "emails/PHPMailer/PHPMailerAutoload.php";
//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
//Username to use for SMTP authentication
$mail->Username = "@gmail.com";
$mail->Password = "";
//Set who the message is to be sent from
$mail->setFrom('mzubim@gmail.com', 'Zubair Mushtaq');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@gmail.com', 'Secure Developer');
//Set who the message is to be sent to
$mail->addAddress('abulogics@gmail.com', 'Abulogicss');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML("convert HTML into a basic plain-text alternative body");
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
这篇关于无法连接到服务器:连接被拒绝(111)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!