Send email with phpmailer not using smtp issue not coming through

Hi

I am trying to use phpmailer without the smtp credentials as the client does not know the email password or they don’t have it to hand so trying to use phpmailer without the smtp info, I am trying the following code and not getting any errors and it’s going to the enquiry confirmation page but the email is not coming through

<?php
session_start();

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

// Include PHPMailer 6.x autoloader
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

$name = '';
$phone = '';
$email = '';
$message = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $error='';
if(!$name || !$phone || !$email || !$message){
    $error.="**Please fill the fields.!".'<br>';
}
    
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $error.="**Please enter valid email address.".'<br>';
}
    
    if(!$error){
        // Initialize PHPMailer
        $mail = new PHPMailer(true);
        
        try {

$mail->SMTPDebug = 0;                               // Enable verbose debug output / Enable SMTP debug information (for testing)

//$mail->isSMTP();                                      // Set mailer to use SMTP
//$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
//$mail->SMTPAuth = true;                               // Enable SMTP authentication
//$mail->Username = '';                 // SMTP username
//$mail->Password = '';                           // SMTP password
//$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
//$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('noreply@domain.co.uk', "Company Name");
$mail->addAddress('ian@domainname.co.uk', "Company Name");     // Add a recipient
$mail->addReplyTo($_POST['email'], $_POST['name']);

$mail->isHTML(false);                                  // Set email format to HTML
$mail->Subject = 'New Website Enquiry';
$mail->Body = "A new website enquiry has been made. The enquiry information is below\r\n\r\n"
            . "Name: " . $_POST["name"] . "\r\n"
            . "Phone: " . $_POST["phone"] . "\r\n"
            . "Email: " . $_POST["email"] . "\r\n"
            . "Message: " . $_POST["message"];

            $mail->send();
            
            // Redirect upon successful sending
            header("Location: http://domainname.co.uk/enquiry-confirmation.php");
            exit();
            } catch (Exception $e) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        }
    }
}

?>
<form action="#form-section" method="post">                        
                        <div class="row">
                            <div class="col-sm-6 col-lg-6">
                                <div class="form-group">
                                    <input type="text" value="<?php echo $name; ?>" name="name" id="name" class="form-control" required placeholder="Name">
                                </div>
                            </div>
                            <div class="col-sm-6 col-lg-6">
                                <div class="form-group">
                                    <input type="text" value="<?php echo $phone; ?>" name="phone" id="phone" class="form-control" placeholder="Phone">
                                </div>
                            </div>
                            <div class="col-sm-12 col-lg-12">
                                <div class="form-group">
                                    <input type="email" value="<?php echo $email; ?>" name="email" id="email" class="form-control" required placeholder="Email">
                                </div>
                            </div>
                            <div class="col-md-12 col-lg-12">
                                <div class="form-group">
                                    <textarea name="message" class="form-control" cols="30" rows="8" required placeholder="Message" value="<?php echo $message; ?>"></textarea>
                                </div>
                            </div>
                            <div class="col-md-12 col-lg-12">
                                <button type="submit" id="submit" name="submit" class="contact-btn btn">Send Message</button>                                
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </form>

Can anyone see where I have gone wrong please as been trying for hours and can’t see what the issue is

The code you’ve posted doesn’t seem to specify what SMTP server you are using to send the email. You’ve commented out the gmail settings, but not replaced them with anything else. Do you have something else configured on the server that the code runs on to actually send the emails for you?

If you enable debugging by setting SMTPDebug to one of the non-zero values, does that give you any useful information?

I don’t know any of the smtp info as the client does not know it so was trying to use phpmailer without smtp as I saw on stackoverflow forum that someone did it but their code is not working on hostgator hosting. I enabled smtp debug and was no errors

if phpmailer is using smtp, it needs to know what smtp server to use.

if its not using smtp, (hint: thats what youre doing when you comment out the isSMTP() line) it will default to using the servers mail() command. If that hasnt been set up (or is blocked) on the hosting service, youll need to use smtp.