我已尝试在*和其他网站上发布的每个单独的脚本/代码/方法,但没有运气.我在GoDaddy上主持.我已经设置了一个Google App帐户,设置了MX Records所需的一切(使用GoDaddy工具),甚至尝试从我的网站的GMAIL界面发送一些电子邮件,以及通过我的一个unix上的终端中的SMTP发送电子邮件机器.这一切都奏效了.
但是,当我尝试使用PHP时,却没有!难道GoDaddy会以某种方式阻止它吗?
我总是收到:
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.
这是我用于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>
谢谢!
解决方法:
如前所述,GoDaddy has been known to block outgoing SSL SMTP connections赞成强制您使用自己的外发邮件服务器.
对于GoDaddy作为公司,注册商和网站主持人的巨大骄傲,这几乎是冰山一角. Ditch’em.