Which example from the PHPMailer GitHub repository is recommended for securely sending emails?

To securely send emails using PHPMailer, it is recommended to use the example provided in the PHPMailer GitHub repository called "examples/gmail.phps". This example demonstrates how to send emails securely using SMTP authentication with a Gmail account. By following this example, you can ensure that your emails are sent securely and reliably.

// Include PHPMailer autoload file
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

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

// Set SMTP settings for Gmail
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'your@gmail.com';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

// Set email content and recipient
$mail->setFrom('your@gmail.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');
$mail->Subject = 'Subject of the email';
$mail->Body = 'Body of the email';

// Send the email
if($mail->send()) {
    echo 'Email sent successfully';
} else {
    echo 'Error sending email: ' . $mail->ErrorInfo;
}