Can you provide a simple example of sending an email using a Mailer class in PHP for beginners?

Sending an email using a Mailer class in PHP requires setting up the Mailer class with the necessary configurations such as SMTP server details, sender email, recipient email, subject, and message body. Here is a simple example of sending an email using a Mailer class in PHP:

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

require 'vendor/autoload.php';

// Instantiating PHPMailer
$mail = new PHPMailer();

// SMTP Configuration
$mail->isSMTP();
$mail->Host = 'smtp.example.com';
$mail->SMTPAuth = true;
$mail->Username = 'your@example.com';
$mail->Password = 'your_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

// Email Content
$mail->setFrom('your@example.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->Subject = 'Test Email';
$mail->Body = 'This is a test email';

// Sending the email
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}