PHPMailer SMTP connect() failed

Encountered SMTP connect() failed. using PHPmailer. Please enable openssl on my php.ini site

OpenSSL is already enabled on our PHP instance. You can’t edit php.ini on free hosting for that. Also, either try to change port to 465 and protocol to ssl to connect to the SMTP server you’re using or add this inside your PHPMailer configuration file (not recommended for security):

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

so PHPMailer would work on our hosting.

1 Like

Included the given snippet but still unable to send. Below is the code for your reference

Send Email <?php date_default_timezone_set('Asia/Manila'); // Edit this path if PHPMailer is in a different location. require '../PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
	$mail->SMTPOptions = array(
                          'ssl' => array(
                          'verify_peer' => false,
                          'verify_peer_name' => false,
                          'allow_self_signed' => true
                             )
                        );	
	
    /*
    * Server Configuration
    */
    $mail->Host = '****.****.com'; // Which SMTP server to use.
    $mail->Username = "****@****.com"; // Your Gmail address.
    $mail->Password = "********"; // Your Gmail login password or App Specific Password.
    $mail->Port = 465; // Which port to use, 587 is the default port for TLS security.
    $mail->SMTPSecure = 'ssl'; // Which security method to use. TLS is most secure.
    /*
    * Message Configuration
    */
    $mail->setFrom('****@****.com', 'Sender'); // Set the sender of the message.
    $mail->addAddress('*****@****.com', 'No-Reply'); // Set the recipient of the message.
    $mail->Subject = 'Send Email'; // The subject of the message.
    /*
    * Message Content - Choose simple text or HTML email
    */      
    // Choose to send either a simple text email...
    $mail->Body = 'This is a plain-text message body'; // Set a plain text body.

    // ... or send an email with HTML.
    //$mail->msgHTML(file_get_contents('contents.html'));
    // Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
    //$mail->AltBody = 'This is a plain-text message body'; 

    // Optional: attach a file
    //$mail->addAttachment('images/phpmailer_mini.png');

    if ($mail->send()) {
        echo "Your message was sent successfully!";
    } else {
	       var_dump($mail->smtpConnect($mail->SMTPOptions));
           var_dump($mail->smtpClose());		
           var_dump($mail->ErrorInfo);			   

    }
?>

BROWSER OUTPUT (Chrome):
bool(false) NULL string(82) “SMTP connect() failed. Troubleshooting · PHPMailer/PHPMailer Wiki · GitHub

Reference:https://infinityfree.net/support/how-to-send-email-with-gmail-smtp/

OpenSSL is enabled on all accounts by default.

Also, trying @Ergastolator1 is fine for testing, but should never be left in live code. That code effectively disables most security mechanisms of SSL, making it much easier for attackers to intercept your messages, see and edit it’s contents and steal your login details. So don’t do it.

Can you please share the SMTP server host? You’ve blanked it out in your code snippet, but the error here is that you cannot connect to a specific server. If you would like us to check anything, it would help a lot if we knew which server to check.

Also, did you try port 587 with tls security already?

1 Like

On my initial code i used port 587 with tls following the guide posted in the knowledge base . However, it returned an "SMTP connect() failed. " as a recourse used 465 with ssl for testing purpose but still got same error. A step further, using the same code base (with 587,tls and 465,ssl) and test condition on XAMPP gave a positive result sending an email.

Since you didn’t answer my previous question, I would like to repeat it:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.