Solution to wordpress SMTP plug-in failure to send emails on HiChina hosts

Source: Internet
Author: User
Tags php file socket port number
The SMTP sending method of wordpress uses steam_connect_client, while the HiChina host provides fsockopen, so to send the mail smoothly, you also need to modify the source file class-smtp.php of the wordpress program, change the SMTP sending method of wordpres to fsockopen to cater to HiChina hosts.

 

1. The fsockopen function of the HiChina host is disabled by default. Enable the fsockopen function on the HiChina host management panel:

 

 

Fsockopen function description

Fsockopen-open a network connection or a Unix socket connection

Description

Resource fsockopen (string $ hostname [, int $ port =-1 [, int & $ errno [, string & $ errstr [, float $ timeout = ini_get ("default_socket_timeout")])
Initialize a socket to connect to the specified host (hostname ).

Parameters

Hostname
If OpenSSL is installed, you may need to add the access protocol ssl: // or tls: // before your host name address ://, therefore, you can use an SSL or TLS client based on the TCP/IP protocol to connect to a remote host.

Port
The port number. If you pass a-1 parameter, the port is not used, for example, unix ://.

Errno
If this parameter is passed in, holds the system level error number that occurred in the system-level connect () call.

If the returned value of errno is 0 and the returned value of this function is FALSE, this indicates that the error occurred before the socket connection (connect () call, the biggest cause of connection failure is that an error occurs during socket initialization.

Errstr
The error message is returned as a string.

Timeout
Sets the connection time limit, in seconds.

2. Edit the class-smtp.php file under the wp-include/directory and find the following code:


$ Socket_context = stream_context_create ($ options );
$ This-> smtp_conn = @ stream_socket_client (
$ Host. ":". $ port,
$ Errno,
$ Errstr,
$ Timeout,
STREAM_CLIENT_CONNECT,
$ Socket_context
);

Replace with the following code:

$ This-> smtp_conn = @ fsockopen ($ host, $ port, $ errno, $ errstr, $ timeout );

Tip: The QQ mailbox still cannot send emails occasionally. There is no problem in the 163 mailbox test.

 

 

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.