How can a PHP mailer be used to embed an image directly in an email?

To embed an image directly in an email using a PHP mailer, you can use the `addEmbeddedImage` method provided by the PHP mailer library. This method allows you to attach an image and reference it within the email's HTML content using a unique identifier.

// Include the PHPMailer library
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// Create a new PHPMailer instance
$mail = new PHPMailer();

// Add the image as an embedded attachment
$mail->addEmbeddedImage('path/to/image.jpg', 'logo', 'logo.jpg');

// Set the HTML content of the email with the image embedded
$mail->Body = '<html><body><img src="cid:logo" /></body></html>';

// Send the email
if($mail->send()) {
    echo 'Email sent successfully';
} else {
    echo 'Email could not be sent';
}