WordPress can run on Alibaba Cloud’s ACE without making any modifications. Currently, ACE is free, fast, and stable, and its various advantages have attracted a large number of WordPress users. Currently, this website is running on ACE. After migrating from my own VPS, everything runs fine, except that I cannot send emails. On my own VPS, I have been using the Cimy Swift SMTP plug-in to send emails through SMTP, but when I arrived at Alibaba Cloud, it kept prompting:SMTP connect() failed.It literally means that the mail server cannot be connected at all.
Why WordPress cannot send emails on ACE
I sent a work order in the Alibaba Cloud backend and got the following reply:
PHP applications use protocols such as http/https/smtp (curl/fsockopen) without setting a proxy: The proxy option cannot be set in stream_socket_client. It is recommended to replace it with fsockopen or curl. The parameter $flags in the stream_socket_client function can only be STREAM_CLIENT_CONNECT, where $context will be ignored; parameter: $remote_socket, which can only be tcp or ssl. protocol, others are not supported;
It can be seen from the reply that Alibaba Cloud ACE can send emails, but it is different from the way we usually send emails. According to Alibaba Cloud’s suggestions, we need to replace thestream_socket_clientforfsockopen, since they can be replaced, the functions of these two functions are basically similar.
Modify the Cimy Swift SMTP plug-in so that it can send emails on Alibaba Cloud ACE
I searched for the code of the Cimy Swift SMTP plug-in, and sure enough, there isstream_socket_clientThis function is incimy-swift-smtp/Swift/lib/classes/Swift/Transport/StreamBuffer.phpLine 263 of:
$this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
We just need to replace this line of code with the following line:
$this->_stream = @fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout);
Save it, submit SVN to the repository, wait for about a minute, redeploy the application, and then test it from the Cimy Swift SMTP plug-in settings. We will find that the email is sent out quickly. We can also test the comment reply and password retrieval, and the email can be found quickly.
In order to facilitate everyone’s use, I directly packaged the modified plug-in. Below is the download link. Friends in need can click the button below to download.
If you want to go faster, you have to use ECS cloud server
The speed of ACE is sufficient for websites with a daily PV of no more than 100. If the website traffic is relatively large, the speed of ACE cannot keep up. At this time, you can directly purchase an Alibaba Cloud ECS server based on your website traffic. The data originally placed on OSS and RDS does not need to be touched, and can be directly configured.
2015/05/19 Update: Wanwang’s virtual host also has the same problem as ACE. I don’t know if they use the same system. After testing, the above method can also be used on Wanwang’s virtual host.
