發送郵件SMTP Error Could not connect to SMTP host. send fail的解決辦法_PHP教程

來源:互聯網
上載者:User
(1)伺服器不能使用smtp的形式發送郵件

解決辦法:很多網站列出的解決辦法說是因為smtp大小寫問題,雖然問題的本質不在這裡,但確實也需要改這個地方,至於為什麼,看下面的操作。

在 class.phpmailer.php 中,將:

function IsSMTP(){$this->Mailer='smtp';}

改成:

function IsSMTP(){$this->Mailer = 'SMTP';}

這個地方的修改不是使用了smtp來發送郵件,而是使用了另外一種方式發送郵件,檢查 class.phpmailer.php 檔案裡面有下面這麼一段:

switch($this->Mailer){case 'sendmail':return $this->SendmailSend($header, $body);case 'smtp'://由於SMTP和smtp不相等 所以選擇的是下面MailSend發送郵件 並不是使用smtp發送郵件return $this->SmtpSend($header, $body);default:return $this->MailSend($header, $body);}

(2)Linux主機禁用了fsockopen()函數

國內有很多空間服務商出於安全考慮會禁用伺服器的fsockopen函數。

解決方案:

用pfsockopen() 函數代替 fsockopen() ,如果 pfsockopen 函數也被禁用的話,還可換其他可以操作Socket函數來代替, 如stream_socket_client()

在 class.smtp.php 中將 @fsockopen 改成 @pfsockopen

$this->smtp_conn = @fsockopen($host,    // the host of the server                                 $port,    // the port to use                                 $errno,   // error number if any                                 $errstr,  // error message if any                                 $tval);   // give up after ? secs

改成:

$this->smtp_conn = @pfsockopen($host,    // the host of the server                                 $port,    // the port to use                                 $errno,   // error number if any                                 $errstr,  // error message if any                                 $tval);   // give up after ? secs

(3)防火牆安全設定規則,如果以上兩種方案都不湊效,那估計是防火牆的規則問題了,可以讓伺服器管理員去掉所有的防火牆規則,然後測試一下,看是否是這個原因。

您可能感興趣的文章

  • Fatal error Call to undefined function date_default_timezone_set()
  • Fatal error Class 'SoapClient' not found in ...錯誤處理辦法
  • Fatal error Class 'ZipArchive' not found ...... 的解決辦法
  • php提示PHP Warning: date(): It is not safe to rely on the......錯誤的解決辦法
  • php提示Maximum execution time of 30 seconds exceeded...錯誤的解決辦法
  • 網頁緩衝控制 Cache-control 常見的取值有private、no-cache、max-age、must-revalidate 介紹
  • 該如何解決php運行出現Call to undefined function curl_init錯誤
  • php Output Control 深入理解 ob_flush 和 flush 的區別

http://www.bkjia.com/PHPjc/764172.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/764172.htmlTechArticle(1)伺服器不能使用smtp的形式發送郵件 解決辦法:很多網站列出的解決辦法說是因為smtp大小寫問題,雖然問題的本質不在這裡,但確實...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.