// Import PHPMailer library require_once 'path/to/PHPMailerAutoload.php'; // Create a new PHPMailer object $mailer = new PHPMailer(); // Set up SMTP settings $mailer->isSMTP(); $mailer->Host = 'smtp.example.com'; $mailer->SMTPAuth = true; $mailer->Username = 'username@example.com'; $mailer->Password = 'password'; $mailer->SMTPSecure = 'tls'; $mailer->Port = 587; // Set up email message $mailer->setFrom('sender@example.com', 'Sender Name'); $mailer->addAddress('recipient@example.com', 'Recipient Name'); $mailer->Subject = 'Test Email'; $mailer->Body = 'Test email message'; // Send the email and close the SMTP connection if ($mailer->send()) { // Email sent successfully $mailer->smtpClose(); } else { // Email failed to send echo 'Error sending email: ' . $mailer->ErrorInfo; }In this example, we create a new PHPMailer object and set up SMTP settings for sending the email. We then set up the email message, call the send() method to send the email, and finally call the SmtpClose() method to close the SMTP connection. The PHPMailer library can be downloaded from their official website or installed using Composer.