What are the recommended best practices for setting up SMTP parameters in PHPMailer?

When setting up SMTP parameters in PHPMailer, it is recommended to use a secure connection (TLS or SSL) to ensure the security of your email communication. Additionally, make sure to provide the correct SMTP server address, port number, username, and password for authentication. It is also good practice to set the 'From' email address to avoid emails being marked as spam.

// Include the PHPMailer autoloader
require 'vendor/autoload.php';

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

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

// Set sender information
$mail->setFrom('your_email@example.com', 'Your Name');

// Add recipient
$mail->addAddress('recipient@example.com');

// Set email subject and body
$mail->Subject = 'Subject Here';
$mail->Body = 'Email body content';

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