What is SMTP-Auth and how does it impact sending emails through PHP, especially when using qmail?

SMTP-Auth is a method of authenticating the sender of an email using a username and password. When sending emails through PHP, especially with qmail, SMTP-Auth may be required by the mail server to prevent unauthorized sending of emails. To implement SMTP-Auth in PHP with qmail, you need to include the username and password in the mail settings.

<?php
$to = "recipient@example.com";
$subject = "Test email with SMTP-Auth";
$message = "This is a test email sent using SMTP-Auth.";
$from = "sender@example.com";
$host = "mail.example.com";
$username = "your_username";
$password = "your_password";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password
    ));

$mail = $smtp->send($to, $headers, $message);

if (PEAR::isError($mail)) {
    echo 'Error sending email: ' . $mail->getMessage();
} else {
    echo 'Email sent successfully!';
}
?>