What are the potential pitfalls of using PHPMailer without SMTP authentication, especially with hosting providers like Strato?

Using PHPMailer without SMTP authentication can lead to your emails being marked as spam or not being delivered at all by certain email providers. This is because sending emails without authentication can be seen as suspicious behavior. To ensure your emails are delivered successfully, it is recommended to use SMTP authentication when sending emails with PHPMailer.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

$mail = new PHPMailer(true);

$mail->isSMTP();
$mail->Host = 'smtp.yourprovider.com';
$mail->SMTPAuth = true;
$mail->Username = 'yourusername@yourprovider.com';
$mail->Password = 'yourpassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->setFrom('from@example.com', 'Your Name');
$mail->addAddress('recipient@example.com', 'Recipient Name');

$mail->isHTML(true);
$mail->Subject = 'Subject';
$mail->Body = 'Email body';

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