1. Explain
After configured $mail->Username
,$mail->password
, the error is reported as follows:
2021-09-01 12:22:37 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Error
2. Solution
1. Ignore SSL authentication (this is my reason)
Add the following code after code: $mail = new PHPMailer();
// Instantiating the PHPMailer core class
$mail = new PHPMailer();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
...
2. Set the port to bit 25, do not use SSL, 465 (other possible reasons)
Change
// Set up ssl encryption for login authentication
$mail->SMTPSecure = 'ssl';
// set the remote server port number for ssl connection to smtp server
$mail->Port = 465;
to
$mail->Port = 25;
Read More:
- [Solved] PHPMailer Failed to Send Email: SMTP Error: Could not connect to SMTP host.
- php Error: mail() Failed to connect to mailserver at “localhost” port 25
- [Solved] WordPress Upgrade PHP 5.6 to 7.x Fatal error: Uncaught Error: Call to undefined function mysql_connect()
- How to solve Magento 500 internal server errors
- [PHP] Solve PHP Call to undefined function ldap_connect()
- [Solved] PHP Error: Warning: file_get_contents(): Failed to enable crypto
- php_network_getaddresses: getaddrinfo failed (How to Fix)
- [Solved] ‘node’ command failed to start the project, with an error: “unknown database’ mydb ‘”
- [Solved] file_get_contents(): SSL operation failed with code 1
- [Solved] Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path:
- [Solved] Laravel Upload Files Verificate Error: The file failed to upload.
- Workman Run Error: stream_socket_server() has been disabled for security reasons
- composer Failed to decode response: zlib_decode(): data error
- /www/server/php/56/sbin/php-fpm:error while loading shared libraries:libssl.so.1.0. 0:cannot open shared object file:No such file or directory
- How to Solve PHP Fatal error: Namespace declaration statement has to be the very first statement
- [Solved] Request exceeded the limit of 10 internal redirects due to possible configuration error
- PHP Error Object of class mysqli could not be converted to string in
- PHP: How to parse MHT file into HTML
- Using $this when not in object context in (How to Fix)
- [PHP] Array to string conversion error when sending data in post