use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'path/to/PHPMailer/src/Exception.php'; require 'path/to/PHPMailer/src/PHPMailer.php'; require 'path/to/PHPMailer/src/SMTP.php'; $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_OFF; // Enable verbose debug output $mail->isSMTP(); // Send using SMTP $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'example@gmail.com'; // SMTP username $mail->Password = 'password'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 465; // TCP port to connect to, use 587 for `PHPMailer::ENCRYPTION_STARTTLS` above //Recipients $mail->setFrom('example@gmail.com', 'John Doe'); $mail->addAddress('recipient@example.com', 'Jane Doe'); $mail->addReplyTo('example@gmail.com', 'Information'); // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Subject of the email'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the plain text version of the email content for non-HTML mail clients'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }In this example, we are sending an email using the Gmail SMTP server with SMTP authentication enabled and TLS encryption. The email has a sender name and address, a recipient name and address, a subject, and a message body in both HTML and plain text format. If the email sending process encounters an error, the error message is displayed.