Home >Backend Development >PHP Tutorial >Failed to connect to server about PHPmailer's failure to send emails
I saw a good article, as follows
Using the phpmailer class SMTP to send emails failed; the troubleshooting idea is first in the code, we open SMTPDebug$mail = new PHPMailer();//Create an email sending class
$mail->SMTPDebug = true; connect to server
following From address failedOpen DEBUG prompt: ERROR: Failed to connect to server: (0) Since it cannot be connected, then we will see how to connect. After asking Du Niang, we learned that we are connected to the smtp server. It is connected by fsockopen, so let’s see if this function is disabled Look for 1,allow_url_fopen in PHP.ini = On Check whether the option is On. When it is Off, the function must not be available. Change it to On.
What should I do if it still cannot be used? Because the above configuration means that fopen is open, it does not mean that it can be used if it is opened. To use it, you must allow it to be used. Okay, let’s see if fsockopen is among the disabled methods2, disable_functionsdisable_functions. Behind this, there are many disabled methods, including fsockopen. Congratulations, you found the answer. Remove it, OK, restart apache, still not working? Also in the php.ini file, see if this is open? extension=php_openssl.dllIf it is open, look at the two files in the php directory Have you copied the extension files to c/:windows/System32? libeay32.dll ssleay32.dllIn addition: you can also give it a try if you don’t change the server, but only change the code. Note => I haven’t tried it Method 1: Replace the fsockopen function with the pfsockopen function Because the parameters of pfsockopen are basically the same as fsockopen, so you only need to replace @fsockopen with @pfsockopen. If you are lucky and pfsockopen is not disabled, ok passesMethod 2: Use the stream_socket_client function
Generally fsockopen() is banned, pfsockopen may also be banned, so here is another function stream_socket_client().
stream_socket_client parameters are different from fsockopen, so the code needs to be modified as:
$this->smtp_conn = stream_socket_client("tcp://".$host.":".$port, $ errno, $errstr, $tval);
That’s it.
This article comes from the "909 is a target" blog, please be sure to keep this source
The link is as follows:
The above has introduced the Failed to connect to server failure of PHPmailer to send emails, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.