Author Topic: SMTP Error: Could not connect to SMTP host.  (Read 577 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
SMTP Error: Could not connect to SMTP host.
« on: November 07, 2023, 10:25:22 AM »
Hello,
I have a problem connecting to SMTP with PhpMailer. It's throwing me this error:

SMTP Error: Could not connect to SMTP host. Connection failed. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

Link to script: https://yaperfumy.pl/mail.php


Code: [Select]
<?php
use PHPMailer\PHPMailer\PHPMailer;
use 
PHPMailer\PHPMailer\SMTP;
use 
PHPMailer\PHPMailer\Exception;

require_once 
__DIR__ '/vendor/phpmailer/phpmailer/src/Exception.php';
require_once 
__DIR__ '/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require_once 
__DIR__ '/vendor/phpmailer/phpmailer/src/SMTP.php';

$mail = new PHPMailer(true);
$mail->SMTPDebug 1;
$mail->isSMTP();
$mail->Host 'mail.yaperfumy.pl';
$mail->SMTPAuth true;
$mail->Username "test@yaperfumy.pl";
$mail->Password "password";
$mail->SMTPSecure "tls";
$mail->Port 587;

$mail->From "test@yaperfumy.pl";
$mail->FromName "Full Name";

$mail->addAddress("lesniewski.jakub94@gmail.com""recipient name");

$mail->isHTML(true);

$mail->Subject "Mail sent from php send mail script.";
$mail->Body "<i>Text content from send mail.</i>";
$mail->AltBody "This is the plain text version of the email content";

try {
    
$mail->send();
    echo 
"Message has been sent successfully";
} catch (
Exception $e) {
    echo 
"Mailer Error: " $mail->ErrorInfo;
}
?>

Offline
*
Re: SMTP Error: Could not connect to SMTP host.
« Reply #1 on: December 12, 2023, 11:10:41 PM »
Contact your hosting privider

Offline
****
Re: SMTP Error: Could not connect to SMTP host.
« Reply #2 on: December 12, 2023, 11:39:09 PM »
Allot of providers have PHP Mail disabled for security.
(block the users to be able to send spam emails or infected emails from php mail function.)

If you have root access, then you can enable it.

You might have to contact your upstream also to make sure all the SMTP ports are open.