PHPMailer on Virtualmin gives connection timed out error

SYSTEM INFORMATION
OS type and version: Ubuntu Server 20.04.03 LTS
Webmin version: 1.981
Virtualmin version: 6.17-3
Related products version: Postfix 3.4.13, PHP 7.4.3, PHPMailer 6.5.1

Hopefully someone has experience with this issue, hardly any info online about this specifically. I have a form in a custom PHP website. The form is supposed to send an email with a body to an email the user submits in the form. I created a user ‘info’ on the website domain which will send email to the emails the users submit. The code that sends the email is below, using the correct email credentials. I’ve tried submitting several different emails, all valid formats. The form uses PHPMailer to send the email.

As far as I know I haven’t modified any system settings that would break this fresh Virtualmin install, so I’m at a loss for what to do next. This was working on another system I setup using Modoboa a week ago, but I was hoping to use Virtualmin’s nice interface for a client. This tells me it isn’t my ISP or firewall, and likely not my PHPMailer config, but I’m not sure what Virtualmin may be doing that I don’t know about. Here’s the error I’m getting in the Nginx error log. Please let me know if you need any other info!

My PHPMailer code, replaced real hostname with ‘hostname’:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '/home/hostname/php/PHPMailer/src/Exception.php';
require '/home/hostname/php/PHPMailer/src/PHPMailer.php';
require '/home/hostname/php/PHPMailer/src/SMTP.php';
session_start();
function email($type,$mID,$MailSubject,$MailBody) {
        $trans=array("<p><h"=>"<h","<p><div"=>"<div","<p><ol"=>"<ol","<p><ul"=>"<ul","<p><li"=>"<li","<p><p"=>"<p","<p><p>"=>"<p>","</h1></p>"=>"</h1>","</h2></p>"=>"</h2>","</h3></p>"=>"</h3>","</>
        $MailHost="mail.***.org";
        $MailUsername='info@***.org';
        $MailPassword='<notrealpassword>';
        $MailFromEmail=$MailUsername;
        $MailBody="<p>".$MailBody."</p>";

        error_reporting(E_STRICT | E_ALL);
        date_default_timezone_set('America/Chicago');
        $mail = new PHPMailer(true);
        $mail->isSMTP();
        $mail->Host = $MailHost;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure="tls";
        $mail->SMTPKeepAlive = true;
        $mail->Port = 587;
        $mail->Username = $MailUsername;
        $mail->Password = $MailPassword;
        $mail->setFrom($MailFromEmail,$MailFromName);
        $mail->Subject = $MailSubject;

        require '/home/hostname/php/topBody.php';
        if(!empty($MailBody)) {
                $mail->msgHTML($topBody.strtr(str_replace(array("\r\n","\n\n","\n"), "</p><p>",htmlspecialchars_decode($MailBody)),$trans).(isset($MailFooter) ? $MailFooter : "")."</body></html>");
                $mail->AltBody = strip_tags($MailBody);
                $mail->addAddress('info@***.org');
                        if(!$mail->send()) {
                echo "Mailer Error (" . str_replace("@", "&#64;", "info@***.org") . ') ' . $mail->ErrorInfo . '<br />';
                        }
                        $mail->clearAddresses(); $mail->clearAttachments();
        }
        unset($MailBody); unset($MailSubject); unset($mID); unset($type);
}
?>

Error, removing my IP and website domain:

2021/10/26 19:10:12 [error] 1219166#1219166: *12 upstream timed out (110: Connection timed out) while reading response header from upstream, client: ***.***.***.***, server: ***.org, request: "POST /advertising/ HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/16352861101191818.sock/socket", host: "www.***.org", referrer: "https://www.***.org/advertising/"

2021/10/26 19:11:31 [error] 1219166#1219166: *12 upstream timed out (110: Connection timed out) while reading response header from upstream, client: ***.***.***.***, server: ***.org, request: "POST /advertising/ HTTP/1.1", upstream: "fastcgi://unix:/var/php-nginx/16352861101191818.sock/socket", host: "www.***.org", referrer: "https://www.***.org/advertising/"

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