GoDaddy Linux 上的 PHP 共享尝试通过 GMAIL SMTP 发送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5440026/
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
PHP on GoDaddy Linux Shared trying to send through GMAIL SMTP
提问by raladin
I have tried EVERY single script/code/method posted on StackOverflow and other sites for this, but with no luck. I am hosting on GoDaddy. I have setup a Google App account, set up everything needed for MX Records (using the GoDaddy tool for that), and even tried sending some emails from the GMAIL interface for my site, as well as through SMTP in terminal on one of my unix machines. It all worked.
为此,我尝试了在 StackOverflow 和其他网站上发布的每一个脚本/代码/方法,但没有运气。我在 GoDaddy 上托管。我已经设置了一个 Google App 帐户,设置了 MX 记录所需的一切(为此使用 GoDaddy 工具),甚至尝试从我的站点的 GMAIL 界面发送一些电子邮件,以及通过我的一台 unix 上的终端中的 SMTP机器。这一切都奏效了。
HOWEVER, when I try using PHP, it doesn't! Is it like GoDaddy blocking it somehow?
但是,当我尝试使用 PHP 时,它没有!就像 GoDaddy 以某种方式阻止它一样吗?
I always receive:
我总是收到:
SMTP -> ERROR: Failed to connect to server: Connection refused (111) SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
SMTP -> 错误:无法连接到服务器:连接被拒绝 (111) SMTP 错误:无法连接到 SMTP 主机。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。
Here's the code I am using for PHPMailer:
这是我用于 PHPMailer 的代码:
<html>
<head>
<title>PHPMailer - SMTP (Gmail) advanced test</title>
</head>
<body>
<?php
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "MYFROMADDRESSHERE"; // GMAIL username
$mail->Password = "MYFROMPASSWORDHERE"; // GMAIL password
$mail->AddReplyTo('MYFROMADDRESSHERE', 'Sender Name');
$mail->AddAddress('TESTTOADDRESSHERE', 'Recipient Name');
$mail->SetFrom('MYFROMADDRESSHERE', 'Sender Name');
$mail->AddReplyTo('MYFROMADDRESSHERE', 'Sender Name');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
</html>
Thanks!
谢谢!
回答by Charles
As discussed previously, GoDaddy has been known to block outgoing SSL SMTP connectionsin favor of forcing you to use their own outgoing mail server.
如前所述,众所周知,GoDaddy 会阻止外发 SSL SMTP 连接,以强制您使用他们自己的外发邮件服务器。
This is pretty much the tip of the iceberg, with regard to the immense suckitude of GoDaddy as a company, registrar and web host. Ditch'em.
就 GoDaddy 作为公司、注册商和网络主机的巨大劣势而言,这几乎只是冰山一角。抛弃他们。
回答by ecairol
I had the same problem, and after going through different sites, I found this one and it actually worked!
我遇到了同样的问题,在浏览了不同的网站后,我找到了这个,并且确实有效!
GoDaddy does allowto 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/
回答by Daniel Ramirez
I finally fixed this putting a comment on the //$mail->isSMTP();
line. After that my Gmail account started working fine in Godaddy.
我终于解决了这个问题,并//$mail->isSMTP();
在线上发表了评论。之后,我的 Gmail 帐户开始在 Godaddy 中正常工作。
require 'PHPMailer/class.phpmailer.php';
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = 'Your subject';
$body = "From: $name\n E-Mail: $email\n Comments:\n $message";
//$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'xxxxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port =587;
回答by Wang'l Pakhrin
Use localhost as the host on your hosting goDaddy server. Using the following ports 25,465,587. Settings for GoDaddy:
使用 localhost 作为托管 goDaddy 服务器上的主机。使用以下端口 25,465,587。GoDaddy 的设置:
Answer relates to this link:PHPMailer GoDaddy Server SMTP Connection Refusedby @Nate Bryam
答案与此链接有关: @Nate Bryam拒绝 PHPMailer GoDaddy 服务器 SMTP 连接
$this->mail->Host = 'localhost';
//$this->mail->SMTPAuth = true;
//$this->mail->Username = '[email protected]';
//$this->mail->Password = 'xxx';
//$this->mail->SMTPSecure = 'ssl';
//$this->mail->Port = 465;//25;//587;
There is no need for SMTP Auth.It works perfect!
不需要 SMTP Auth.It 完美运行!
回答by 916 Networks
Unfortunately you can't even use an outbound mail service like DYNDNS with GoDaddy, they only allow you to use their relay server. Limiting.
不幸的是,您甚至不能在 GoDaddy 中使用像 DYNDNS 这样的出站邮件服务,它们只允许您使用他们的中继服务器。限制。
回答by george
The only option they have is to use the domain and use their e-mail service to send mail.
他们唯一的选择是使用域并使用他们的电子邮件服务发送邮件。
回答by chandana
require_once('PHPMailerAutoload.php');
require_once('PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = '[email protected]';
$mail->Password = 'fwxnorhqttkxydr';
$mail->SetFrom($email);
$mail->Subject = 'enquiry from YnRack site';
$mail->Body = 'enquiry from YnRack site' . $message . '"From: \"' . $name . $email;
$mail->IsHTML(true);
$mail->AddAddress('[email protected]');
$mail->Send();
回答by Mauricio Felipe Pacheco Diaz
Is more simple. strangely you need comment line "// $mail->IsSMTP();". Yes, ok, its SMTP, but if you enable this line, you can't send mail. ...don't need more configuration. Only this comment line.
更简单。奇怪的是,您需要注释行“// $mail->IsSMTP();”。是的,好的,它的 SMTP,但是如果您启用此行,则无法发送邮件。...不需要更多配置。仅此注释行。
回答by Chad
I'm not supporting Godaddy, because they generally sucks, but this working for me. They might have updated there systems.
我不支持 Godaddy,因为它们通常很糟糕,但这对我有用。他们可能已经更新了那里的系统。
$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 = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587 or 465
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->setFrom('[email protected]', 'Someone's name');
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress("[email protected]");
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
return false;
} else {
return true;
}
}
Oh I also want to everybody, I don't care about OOP!!!
哦我也想给大家,我不在乎OOP!!!
回答by user49100
you can use your gmail and have Godaddy enable Remote Mail Exchanger in Cpanel. You have to ask them do it because you do not have access to it in cpanel
您可以使用您的 gmail 并让 Godaddy 在 Cpanel 中启用远程邮件交换器。您必须要求他们这样做,因为您无法在 cpanel 中访问它