PHPMailer sends "SMTP error: unable to connect to SMTP host"

Source: Internet
Author: User
Tags server port


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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.