PHPMailer:使用远程SMTP服务器,在localhost下工作,远程服务器上的Connection refused(111)

问题描述 投票:4回答:2

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

  1. 如果我在localhost服务器上执行我的PHP文件,它可以工作。
  2. 如果我在GoDaddy的服务器上执行我的PHP文件,它不起作用。

我得到的错误信息是:

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

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

这是有问题的代码:

index.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();
?>
php email smtp phpmailer
2个回答
6
投票

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

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...

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


2
投票

如果您的主机拥有自己的电子邮件服务器,则服务器将使用以下端口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;

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

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

//$mail->SMTPSecure = 'tls'; 
//$mail->Port = 587;
© www.soinside.com 2019 - 2024. All rights reserved.