PHP › Email Sending in PHP (PHPMailer & SMTP)

What is SMTP authentication, and why is properly configuring it important for ensuring email deliverability?

Intermediate

Answer

SMTP authentication requires your application to provide valid credentials, typically a username and password, when connecting to an SMTP server to send an email, proving to the receiving mail server that the email genuinely originates from an authorized source rather than being potentially spoofed, and properly configuring this authentication, along with using an appropriate secure connection method, significantly improves the likelihood that your emails are trusted and delivered rather than rejected or marked as spam.
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'you@example.com';
$mail->Password = 'app_specific_password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
Real-world example A company configures its application to authenticate with its email provider's SMTP server using a dedicated application specific password rather than the account's actual login password, following the provider's recommended security practice for automated sending.

Common follow-ups: What is the difference between SSL and TLS options for SMTP connections?;Why should application specific passwords be used instead of a real account password?