Solution to SMTP Error Could not connect to SMTP host. send fail when sending emails_PHP Tutorial

WBOY
Release: 2016-07-13 10:30:59
Original
2103 people have browsed it

(1) The server cannot use smtp to send emails

Solution: The solutions listed on many websites say that it is because of the SMTP case problem. Although the essence of the problem is not here, it does need to be changed. As for why, see the operation below.

In class.phpmailer.php, place:

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

changed to:

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

The modification here is not to use smtp to send emails, but to use another way to send emails. Check the class.phpmailer.php file for the following paragraph:

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);
}
Copy after login

(2) The Linux host has disabled the fsockopen() function

Many space service providers in China disable the fsockopen function of the server for security reasons.

Solution:

Use the pfsockopen() function instead of fsockopen(). If the pfsockopen function is also disabled, you can also replace it with other functions that can operate Socket, such as stream_socket_client()

Change @fsockopen to @pfsockopen in class.smtp.php

Put

$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
Copy after login

changed to:

$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
Copy after login

(3) Firewall security setting rules. If the above two solutions do not work, it is probably a problem with the firewall rules. You can ask the server administrator to remove all firewall rules and then test it to see if That's the reason.

Articles you may be interested in

  • Fatal error Call to undefined function date_default_timezone_set()
  • Fatal error Class 'SoapClient' not found in .. .Error handling method
  • Fatal error Class 'ZipArchive' not found... Solution
  • php prompt PHP Warning: date(): It is not safe to rely on the ...wrong solution
  • php prompts Maximum execution time of 30 seconds exceeded...wrong solution
  • web page cache control Cache-control common values ​​​​are private , no-cache, max-age, must-revalidate Introduction
  • How to solve the error of Call to undefined function curl_init when running php
  • php Output Control In-depth understanding of the difference between ob_flush and flush

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764172.htmlTechArticle (1) The server cannot use smtp to send emails. Solution: Many websites list solutions that say this is because The problem of SMTP case, although the essence of the problem is not here, but it is indeed...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template