Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SMTP ERROR: Failed to connect to server: Permission denied (13) SMTP connect() failed

I don’t undestand why there is the error, maybe i am doing something wrong with the config, maybe with the host. on localhost this config is working, on my online server, with certificate ssl i have this problem

    <?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer();

$mail->SMTPDebug = 1;
$mail->isSMTP();
$mail->Host = 'smtps.aruba.it';
$mail->SMTPAuth = true;
$mail->Username = 'mail@domain.com';
$mail->Password = '********';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$smtp_debug = true;

// genero il codice otp
$randOtp = strval(rand(10000, 99999));

$sender = "mail@domain.com";
$receiver = $_SESSION['receiver'];
$subject = "Codice di sicurezza OTP";
$mailBody = $randOtp . " Questo e' il tuo codice di sicurezza!";


$mail->setFrom($sender);
$mail->addAddress($receiver);
$mail->addReplyTo($sender);

$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $mailBody;


if (!$mail->send()) {
    echo "Errore nell invio dell email";
} else {
    echo "Email inviata con successo";
    // echo '<pre>';
    // var_dump($mail);
    // echo '</pre>';
    // die();
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Maybe you online server has selinux and it’s blocking the communication?

You can check it with the command:

getsebool httpd_can_sendmail

And if you need it, enable with:

setsebool -P httpd_can_sendmail 1

More info:

https://blog.innovsystems.com/php/smtp-error-failed-to-connect-to-server-permission-denied-13/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading