Article 6GG9H Issue with PHPMailer for my website

Issue with PHPMailer for my website

by
Bala451987
from LinuxQuestions.org on (#6GG9H)
I'm uncertain if this question aligns with the forum's scope, but I'm eager to ask: I configured PHP Mailer on my website, but I encountered an error:

2023-11-19 09:33:12 SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP Error: Could not connect to SMTP host. Failed to connect to server
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host. Failed to connect to serverSMTP server error: Failed to connect to server SMTP code: 111 Additional SMTP info: Connection refused

I am configured my Email with Zoho.I leave Zoho smtp settings here: https://www.zoho.com/mail/help/zoho-smtp.html

I tried to attach my php file but i can't, so i paste it below here. So please spot me an error:

Code:<?php

// Declare variables
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$subject = $_POST["subject"];
$message = $_POST["message"];

// Validate email address
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'Invalid email address';
exit;
}

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require './PHPMailer-master/src/Exception.php';
require './PHPMailer-master/src/PHPMailer.php';
require './PHPMailer-master/src/SMTP.php';

// Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
// Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtppro.zoho.in'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info@drugvigil.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption, use `PHPMailer::ENCRYPTION_SMTPS` for implicit TLS
$mail->Port = 587; // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

// Recipients
$mail->setFrom('info@drugvigil.com', 'Drug Vigil'); // Use a verified and authenticated email address
$mail->addAddress('info@drugvigil.com'); // Add a recipient

// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

?>
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments