我已经尝试过在StackOverflow和其他站点上发布的每个脚本/代码/方法,但是都没有运气。我在GoDaddy上托管。我已经设置了一个Google App帐户,设置了MX记录所需的所有内容(为此使用GoDaddy工具),甚至尝试通过GMAIL界面为我的网站发送一些电子邮件,以及通过UNIX上的一个终端发送SMTP机器。一切正常。
但是,当我尝试使用PHP时,事实并非如此!就像GoDaddy以某种方式阻止它吗?
我总是收到:
SMTP->错误:无法连接到服务器:连接被拒绝(111)SMTP错误:无法连接到SMTP主机。邮件错误:SMTP错误:无法连接到SMTP主机。
这是我用于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会阻止传出SSLSMTP连接,从而迫使您使用他们自己的传出邮件服务器。
关于GoDaddy作为公司,注册商和网络托管商的巨大吸引力,这几乎是冰山一角。Ditch’em。