What is the recommended namespace structure for using PHPMailer in a PHP project?

When using PHPMailer in a PHP project, it is recommended to follow a namespace structure to organize your code and prevent naming conflicts with other libraries or classes. This can be achieved by using namespaces to encapsulate your PHPMailer code within a specific namespace.

<?php

namespace MyProject\Mail;

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

require 'vendor/autoload.php';

// Your PHPMailer code goes here

$mail = new PHPMailer(true);

// Set up your email sending logic

try {
    // Send the email
    $mail->send();
    echo 'Email sent successfully';
} catch (Exception $e) {
    echo 'Email could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}