我嘗試過在StackOverflow和其他網站上發佈的每個單獨的腳本/代碼/方法,但沒有運氣。我在GoDaddy上託管。我已經設置了一個Google App帳戶,設置了MX記錄所需的所有內容(使用GoDaddy工具),甚至嘗試從我的網站的GMAIL界面發送一些電子郵件,以及通過我的一個unix的終端中的SMTP發送一些電子郵件機器。這一切都奏效了。但是,當我嘗試使用PHP時,它不會!它是否像GoDaddy以某種方式阻止它?GoDaddy Linux上的PHP共享嘗試通過GMAIL發送SMTP
我總是收到:
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>
謝謝!
簡單的方法來測試,如果你有外殼訪問:登錄到服務器,並嘗試「telnet smtp.gmail.com 465」。你將無法完成SSL的工作,但是如果出現防火牆問題,你也會在那裏「拒絕連接」。如果它連接,然後掛起輸入,它不是防火牆,並與您的代碼。 – 2011-03-26 02:52:28
我沒有在此服務器上啓用SHELL,需要48小時才能激活它;需要在幾個小時內解決。還有其他建議嗎? – johnshaddad 2011-03-26 03:17:44
我刪除了godaddy標記,因爲它正從網站中刪除。 – 2016-08-13 05:24:10