PHPMailer SMTP连接失败求助(EasyPHP环境)
Let’s work through the most likely fixes for this issue, since you’ve already checked openssl and switched to TLS/587:
Confirm openssl is actually active
Editingphp.inidoesn’t always take effect right away. First, restart your EasyPHP web server. Then create a quick test file with<?php phpinfo(); ?>, run it in your browser, and search for "openssl" — make sure the "OpenSSL support" line says "enabled". Also, double-check you edited the correctphp.inifile (EasyPHP sometimes has separate configs for web and CLI; use the path shown in phpinfo to confirm).Validate SMTP server credentials and core settings
Even with TLS/587 set, small misconfigs here break connections:- Is your SMTP host correct? (e.g.,
smtp.gmail.comfor Gmail,smtp.office365.comfor Outlook) - Did you enable SMTP authentication? Add
$mail->SMTPAuth = true;to your PHPMailer setup if you haven’t. - Are your username/password accurate? For services like Gmail, if 2FA is enabled, you’ll need an app-specific password instead of your regular account password. Avoid using "allow less secure apps" long-term, but it can help test if auth is the issue.
- Is your SMTP host correct? (e.g.,
Test network access to the SMTP server
Your machine might be blocked from reaching port 587. Open your terminal and run:telnet your-smtp-host.com 587If you get a timeout or "connection refused", check your Windows Firewall or third-party antivirus — they might be blocking outgoing traffic on that port. Temporarily disable the firewall to test, then add an exception for EasyPHP if that fixes it.
Bypass SSL certificate verification (for testing only)
Local environments often don’t trust the SMTP server’s SSL certificate. Add this to your PHPMailer code to rule out certificate issues:$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) );Important: Don’t leave this enabled in production — it’s only for debugging.
Update PHPMailer to the latest version
Older PHPMailer releases can have bugs with TLS connections. Grab the latest stable version and replace your current PHPMailer files in the project.
内容的提问来源于stack exchange,提问作者prapul_143

