2011-03-26 88 views
8

我嘗試過在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> 

謝謝!

+0

簡單的方法來測試,如果你有外殼訪問:登錄到服務器,並嘗試「telnet smtp.gmail.com 465」。你將無法完成SSL的工作,但是如果出現防火牆問題,你也會在那裏「拒絕連接」。如果它連接,然後掛起輸入,它不是防火牆,並與您的代碼。 – 2011-03-26 02:52:28

+0

我沒有在此服務器上啓用SHELL,需要48小時才能激活它;需要在幾個小時內解決。還有其他建議嗎? – johnshaddad 2011-03-26 03:17:44

+0

我刪除了godaddy標記,因爲它正從網站中刪除。 – 2016-08-13 05:24:10

回答

22

如前所述,GoDaddy has been known to block outgoing SSL SMTP connections支持強制您使用自己的發送郵件服務器。

這幾乎是冰山一角,關於GoDaddy作爲公司,註冊商和虛擬主機的巨大不滿。 Ditch'em。

+0

這是否意味着我要麼轉移到另一個託管或我卡住?! GoDaddy的郵件非常慢!另外,如果GMAIL使用SSL並阻止它,那麼是否還有其他服務可用?我不在乎它是否是GMAIL,只要它從我發送的消息中顯示「@ mydomain.com」,並且只要它們不去用戶JUNK(儘管我爲我的域添加了SPF, GoDaddy的默認郵件仍然發送給我的用戶垃圾) – johnshaddad 2011-03-26 03:54:34

+1

這意味着你應該找到一個好的,有信譽的主機。還有其他的郵件服務,但我不知道一個適合你的郵件服務。 (我喜歡亞馬遜SES,但是有一個巨大的學習曲線,因爲您必須修改代碼才能通過它發送,而不是使用SMTP。) – Charles 2011-03-26 03:59:58

+7

剛剛通過GoDaddy的客戶支持證實了這一點;多麼糟糕的服務。 – johnshaddad 2011-03-26 20:13:00

1

不幸的是,你甚至不能在GoDaddy上使用像DYNDNS這樣的出站郵件服務,它們只允許你使用他們的中繼服務器。限制。

1

他們唯一的選擇是使用域並使用他們的電子郵件服務發送郵件。

7

我有同樣的問題,並經過不同的網站後,我發現這一個和它實際上工作!

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... 

參考(見第一兩個職位) http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

+7

使用*他們* SMTP服務器的定義是**不**使用Gmail的SMTP服務器。作爲您的Gmail地址(或Google Apps地址)發送電子郵件可能會導致嚴重的垃圾郵件問題,因爲它們的服務器*不會被SPF或DKIM清除以用於作爲Gmail用戶帳戶發送。 – Charles 2013-10-15 02:54:04

+0

感謝一堆@ecairol,你的回答也幫助我用快捷的郵件工具來解決它。 – 2014-05-31 07:28:50

+1

用WordPress確認我的GoDaddy問題。我使用了WP-Mail-SMTP並設置了以下內容:「From Email」,「From Name」,「通過SMTP發送所有wordpress郵件」,「設置返回路徑以匹配From電子郵件」,「SMTP主機:relay-hosting.secureserver.net「,」SMTP Port:25「,」No Encryption「,」No SMTP Authentication「 – 2015-06-05 10:46:37

0

我既不支持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; 
    } 
} 

哦,我也想每個人,我不在乎面向對象!

+0

這根本不起作用。不支持在godaddy服務器中使用gmail smtp。 – 2016-09-27 05:23:53

+0

不要對幾乎兩年前提交的答案進行投票。我不知道Godaddy從那以後做了什麼? – Chad 2016-09-28 02:07:40

+1

編輯你的答案給+ – 2016-09-28 03:13:01

0

你可以使用你的Gmail,並讓Godaddy在Cpanel中啓用遠程郵件交換器。你要問他們這樣做,因爲你沒有給它的cPanel

+2

你可以使用建議 – SagarPPanchal 2014-11-13 14:06:08

1

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(); 
0

更簡單。奇怪的是你需要註釋行「// $ mail-> IsSMTP();」。是的,好吧,它的SMTP,但如果你啓用這一行,你不能發送郵件。 ...不需要更多配置。只有這條評論線。

3

我終於解決了這個在//$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; 
+2

這不是一個「修復」;它使您的Gmail帳戶「工作」,而不使用您的Gmail帳戶。 – Synchro 2016-07-28 20:58:36

+0

謝謝,我試着讓phpmailer工作了幾天。我不知道這是如何修復它,但它的工作原理。 – user1017063 2016-09-22 04:25:14

2

使用本地主機作爲您的託管goDaddy服務器上的主機。使用以下端口25,465,587。對於GoDaddy的設置:

答案涉及到這個鏈接:PHPMailer GoDaddy Server SMTP Connection Refused 通過@Nate Bryam

$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; 

沒有必要對SMTP Auth.It完美的作品!

+0

僅當您在MX記錄中使用GoDaddy郵件設置時才起作用(例如,如果您將GSuite MX記錄設置爲使用外部郵件提供程序,那麼它將以靜默方式失敗);當它工作時,它是完美的,只要你不關心所有發送的郵件都會到達用戶的垃圾郵件文件夾;) – guari 2017-03-10 13:32:36

+0

這對我有效...我不需要任何幻想 - 只需發送一封電子郵件,並按照「聯繫我們」表格中指定的收件人進行操作,然後看到這正是我允許的。我沒有設置任何MX記錄(我假設他們是默認的)。我所做的只是創建一個電子郵件帳戶,並將其設置爲FROM地址,同時將replyTO設置爲用戶輸入的電子郵件地址。 – Hylianux 2017-04-24 21:03:37