When attempting to send emails through GMail's SMTP server from a PHP page, you may encounter the error:
authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: mx.google.com at your service, [98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]
This error often arises when the PHP code lacks the correct SSL settings. Here's how to rectify the issue:
Corrected PHP Code:
<br>// Pear Mail Library<br>require_once "Mail.php";</p> <p>$from = '<[email protected]>';<br>$to = '<[email protected]>';<br>$subject = 'Hi!';<br>$body = "Hi,nnHow are you?";</p> <p>$headers = array(</p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">'From' => $from, 'To' => $to, 'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com', 'port' => '465', 'auth' => true, 'username' => '[email protected]', 'password' => 'passwordxxx' ));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
Key Differences:
By implementing these changes, you'll ensure proper SSL encryption and avoid the authentication failure error.
The above is the detailed content of Why Am I Getting an Authentication Failure When Sending Emails via Gmail's SMTP Server from PHP?. For more information, please follow other related articles on the PHP Chinese website!