Solution of phpmailer can't send mail normally on server

  • 2021-07-07 06:51:08
  • OfStack

phpmailer itself is a very good open source mail class, It is also very easy to use and simple, Occasionally, when a program is uploaded to the server and can't send mail, Some students asked me this question before, but I always didn't agree at that time. Today, I finally met it. It was normal to test locally with phpmailer, but it couldn't be uploaded to the server. Of course, it was SMTP, and it was finally determined that fsockopen function caused the disaster. Because of security reasons, fsockopen and pfsockopen were often shut down by the server. The solution is as follows:

Instead, the stream_socket_client () function should be used, but its parameters are different from one point.

The class. stmp. php file for phpmailer should be changed as follows:


$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

Replace with


$this->smtp_conn = @stream_socket_client( $host.':'.$port,  // the host of the server
                 $errno,  // error number if any
                 $errstr, // error message if any
                 $tval);  // give up after ? secs

The version of PHP should be higher than the version of 5.0, because the earlier version did not have the function of stream_socket_client ().
OK, problem solved.


Related articles: