Asked  7 Months ago    Answers:  5   Viewed   131 times

I am trying to send an email via GMail's SMTP server from a PHP page, but I get this error:

authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: at your service, [] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]

Can anyone help? Here is my code:

require_once "Mail.php";

$from = "Sandra Sender <>";
$to = "Ramona Recipient <>";
$subject = "Hi!";
$body = "Hi,nnHow are you?";

$host = "";
$port = "587";
$username = "";
$password = "testtest";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

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

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");


// Pear Mail Library
require_once "Mail.php";

$from = '<>';
$to = '<>';
$subject = 'Hi!';
$body = "Hi,nnHow are you?";

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

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://',
        'port' => '465',
        'auth' => true,
        'username' => '',
        'password' => 'passwordxxx'

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

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
Wednesday, March 31, 2021
answered 7 Months ago

I found my answer. in your Gmail go to

setting ->accounts ->Send mail as

click Add another email address you own in new window enter new email address (example if your gmail is you must enter your gmail address have dot you must change position of dot. example if your gmail is you must enter
don't forget uncheck Treat as an alias.
click next step.
enter image description here

go back to setting ->accounts ->Send mail as
make a new email as defult
check Reply from the same address the message was sent to
all done!
i change code use new codes.
enter image description here
now show from my site

enter image description here
now when you click replay botton show replay to user email
enter image description here

include "classes/class.phpmailer.php"; // include the class name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "";
$mail->Port = 587; // or 587
$mail->Username = ""; 
$mail->Password = "xxxxxxxxx";
$mail->SetFrom("","My Site");
$mail->Subject = "Your Gmail SMTP Mail";
$mail->Body = "Hi, your first SMTP mail via gmail server has been received.";
  echo "Mailer Error: " . $mail->ErrorInfo;
    echo "Message has been sent";
Wednesday, March 31, 2021
answered 7 Months ago

The difference between the prefixing the hostname with ssl:// and without it is whether or not the underlying stream will be wrapped through OpenSSL, or speak in plain text.

When you connect to Gmail on port 465, it expects the client will use TLS encryption. Most likely, the error message you were seeing was a general result of connecting to a service expecting an encrypted connection when it was just trying to write and read data in plain text.

PHP does magic for you when you use the ssl:// wrapper to connect to a service that supports TLS or SSL. It allows you to read and write on the stream (using say fread/fwrite) in the same manner you would on an unencrypted connection and all the handshaking, encryption, and decryption is done in the background having to do no more than prefix the host with the ssl wrapper.

As to the second question, it is most likely security related. In order to relay (send mail to another domain) you need to authenticate over SMTP which should NEVER be done in cleartext while you can connect on port 25 using an unencrypted connection and send mail to a Gmail user without authenticating (this is what most outside mail servers do when one of their users which to send mail to Gmail). But technologically, there's nothing preventing them from allowing you to send mail using an unencrypted connection, or even authenticating with Gmail credentials (this is called an open relay and is usually badly abused by spammers).

You can learn more about your first question by just reading about the SMTP protocol, the STARTTLS command, and TLS encryption in general. STARTTLS allows a client to connect to the mail server over an unencrypted connection and then negotiate (upgrade) the connection to use encryption, where on the other hand, connections to port 465 expect a TLS handshake to occur as soon as the connection is established and before any protocol (SMTP) communication occurs.

Friday, May 28, 2021
answered 5 Months ago

Did your php support SSL ?, and check for reference.

Create a page with


Is SSL enabled?

Saturday, May 29, 2021
answered 5 Months ago

Your vps doesn't have rDNS configured and the HELO points to a different ip. inconsistencies in HELO and missing rDNS trigger many spamfilters.

Received: from ([])

Host not found: 3(NXDOMAIN) has address

Set a HELO Hostname whose A-Record points back to your VPS and configure the rDNS (PTR) to the same hostname.


  • Create a new A-Record ''
  • Set the HELO to ''
  • Set the reverse DNS (PTR) for to

Also your senderdomains have somewhat strange "TXT" records:

dig txt +short 
dig txt +short

you may want to change these into correctly formatted SPF records, eg.

v=spf1 ip4: ip4: ~all
Saturday, August 7, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :