沃梦达 / 编程问答 / php问题 / 正文

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

PHPMailer: Using remote SMTP server, works under localhost, Connection refused (111) on remote server(PHPMailer:使用远程 SMTP 服务器,在本地主机下工作,远程服务器上的连接被拒绝(111))

本文介绍了PHPMailer:使用远程 SMTP 服务器,在本地主机下工作,远程服务器上的连接被拒绝(111)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

  1. 如果我在本地服务器上执行我的 PHP 文件,它会起作用.
  2. 如果我在 GoDaddy 的服务器上执行我的 PHP 文件,它不起作用.

我得到的错误信息是:

SMTP ->错误:无法连接到服务器:连接被拒绝(111)

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

I checked phpinfo on both localhost and the remote server. Both have smtp_port listed 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).

这里是有问题的代码:

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 = 'username@site.com';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result

$mail->ClearAddresses();
$mail->AddAddress('receiver@hotmail.com', 'Receiver Name');
$mail->From = "username@site.com";
$mail->FromName = "Username";
$mail->Subject = 'Hi there';
$mail->Body = "This is a message";

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

exit();
?>

推荐答案

我觉得你应该分两步1)按照godaddy支持http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-电子邮件帐户2)使用relay-hosting.secureserver.net"作为您的主机,而不是smtpout.secureserver.net"

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-account 2)use "relay-hosting.secureserver.net" as your host instead of "smtpout.secureserver.net"

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

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:

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account@gmail.com";
$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/

这篇关于PHPMailer:使用远程 SMTP 服务器,在本地主机下工作,远程服务器上的连接被拒绝(111)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

基础教程推荐