[Solved] PHPMailer Failed to Send Email: SMTP Error: Could not connect to SMTP host.

1. First step

Open the debugging mode to view the error message

$mail->SMTPDebug = 2;

2. Add the following code to skip validation

Generally, for example, QQ mailbox and 163 mailbox will not fail to connect to the SMTP server. For example, the mail server with its own company domain name is prone to sending failure.

$mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true

The referendum decided:

Link: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

stack overflow: https://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host

Read More: