Cause analysis
If this problem occurs, the name of the SMTP host
Solution: It depends on the email payment does not support sending and receiving mails by pop3. This can be viewed officially by email, such as QQ mail.
Phpmailer error SMTP Error: cocould not connect to SMTP host cocould not instantiate mail function
After half a day, it turns out that smtp requests are different for different mail systems, but both are allowed in uppercase, some do not support lowercase, such as NetEase or Tencent's mailbox.
Original settings
$ Mail-> SMTPAuth = true;
$ Mail-> Mailer = "smtp ";
$ Mail-> Host = "smtp.qq.com ";
$ Mail-> Port = 25; // Set the mail server Port. The default value is 25.
$ Mail-> Username = "8515888@qq.com ";
$ Mail-> Password = "xxxxxxxxxx ";
Change smtp to uppercase.
$ Mail-> Mailer = "SMTP ";
Analyze question 2,
In addition, if you use space rather than servers, it may be disabled for fsockopen and pfsockopen, because phpmailer needs to use fsockopen and pfsockopen to send emails, so there will be problems.
Solution
Find the class. smtp. Php file, which is about 128 lines of the file. There is such a piece of code:
// Connect to the smtp server
$ 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
Method 1: replace the fsockopen function with the pfsockopen function.
Because the pfsockopen parameter is basically the same as fsockopen, you only need to replace @ fsockopen with @ pfsockopen.
Method 2: Use the stream_socket_client function
Generally, fsockopen () is disabled, and pfsockopen may also be disabled. So here we will introduce another function stream_socket_client ().
The parameters of stream_socket_client are different from those of fsockopen, so the code should be changed:
$ This-> smtp_conn = stream_socket_client ("tcp: //". $ host. ":". $ port, $ errno, $ errstr, $ tval );
In this way, you can.