php PHPMailer:使用远程 SMTP 服务器,在本地主机下工作,远程服务器上的连接被拒绝(111)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21668488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:20:35  来源:igfitidea点击:

PHPMailer: Using remote SMTP server, works under localhost, Connection refused (111) on remote server

phpemailsmtpphpmailer

提问by a.real.human.being

I've got a bizarre problem here. I'm trying to use PHPMailer to send an email, through SMTP. I have a website hosted by GoDaddy and it's that SMTP account that I'm trying to use to send the mail.

我这里有一个奇怪的问题。我正在尝试使用 PHPMailer 通过 SMTP 发送电子邮件。我有一个由 GoDaddy 托管的网站,它是我试图用来发送邮件的 SMTP 帐户。

  1. It works if I execute my PHP file on my localhost server.
  2. It does not work if I execute my PHP file on GoDaddy's server.
  1. 如果我在我的本地主机服务器上执行我的 PHP 文件,它会起作用。
  2. 如果我在 GoDaddy 的服务器上执行我的 PHP 文件,它就不起作用。

The error message I get is:

我得到的错误信息是:

SMTP -> ERROR: Failed to connect to server: Connection refused (111)

SMTP -> ERROR: Failed to connect to server: Connection refused (111)

I checked phpinfoon both localhost and the remote server. Both have smtp_portlisted as 25. I'm using WAMP on my machine and the server is some form of Linux (which I know nothing about and have no idea how to administer).

我检查phpinfo了本地主机和远程服务器。两者都smtp_port列为25。我在我的机器上使用 WAMP,服务器是某种形式的 Linux(我对它一无所知,也不知道如何管理)。

Here is the code in question:

这是有问题的代码:

INDEX.PHP:

索引.PHP:

<?php
date_default_timezone_set('America/Los_Angeles');
include_once("phpmailer/class.phpmailer.php");

$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->Port = 25;

$mail->IsSMTP();
$mail->Host = 'smtpout.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result

$mail->ClearAddresses();
$mail->AddAddress('[email protected]', 'Receiver Name');
$mail->From = "[email protected]";
$mail->FromName = "Username";
$mail->Subject = 'Hi there';
$mail->Body = "This is a message";

if ($mail->Send()) {
    echo "Message sent!\n";
}
else {
    echo "Message failed!\n";
    print_r($mail->ErrorInfo);
}

exit();
?>

回答by Amit Yadav

I think you should perform two step 1) check your port as suggested on godaddy support http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account2)use "relay-hosting.secureserver.net" as your host instead of "smtpout.secureserver.net"

我认为您应该执行两个步骤 1) 按照 Godaddy 支持http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting 上的建议检查您的端口-to-my-email-account2) 使用“relay-hosting.secureserver.net”作为你的主机而不是“smtpout.secureserver.net”

GoDaddy does allow to send emails using Gmail as your SMTP, just need to get rid of the smtp.gmail.com and use their Host instead. This is my setup:

GoDaddy 确实允许使用 Gmail 作为您的 SMTP 发送电子邮件,只需要摆脱 smtp.gmail.com 并改用他们的主机。这是我的设置:

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "[email protected]";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...

Reference (see first two posts) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

参考(见前两篇文章)http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

回答by Karen Danielyan

If your hosting has own email server, the server will use the following ports 25,465,587. Settings for GoDaddy:

如果您的主机有自己的电子邮件服务器,服务器将使用以下端口 25,465,587。GoDaddy 的设置:

$mail->isSMTP(); 
$mail->Host = localhost; 
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';

//$mail->SMTPSecure = 'tls'; 
//$mail->Port = 587;

For other providers you have to create a mailbox with your domain:

对于其他提供商,您必须使用您的域创建一个邮箱:

$mail->isSMTP(); 
$mail->Host = localhost; 
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'password';

//$mail->SMTPSecure = 'tls'; 
//$mail->Port = 587;