Link to home
Start Free TrialLog in
Avatar of Jim Z
Jim ZFlag for United States of America

asked on

PEAR Mail authentication failure

We are writing a PHP program that needs to email out a confirmation. In testing we discovered that many email servers (such as Comcast) will not deliver un-authenticated emails that come from a PHP program. So to get around this we installed PEAR Mail and tried to mail using SMTP user id and password provided by our staff. We are getting the error:

authentication failure [SMTP: No supported authentication methods (code: 250, response: xxx.mailserver.com Hello [192.168.41.71] SIZE 37748736 PIPELINING DSN ENHANCEDSTATUSCODES STARTTLS X-ANONYMOUSTLS AUTH NTLM X-EXPS GSSAPI NTLM 8BITMIME BINARYMIME CHUNKING XRDST)]
Sql add failed

In doing further research it sounds like IIS needs to have a connector configured to work with Pear’s smtp.

Research notes:
It's the mail server (exchange) the one that doesn't support Digest-MD5, CRAMMD5, LOGIN or PLAIN authentication options. Those are the only authentication options that PHP supports.
You don't need to change anything on PHP, because it will automatically choose one of the authentication option on that list (Digest-MD5, CRAMMD5, LOGIN or PLAIN), the first one that your mail server supports.
You have to enable at least one of those authentication mechanisms on MS Exchange to be able to send emails from PHP using that exchange server. Otherwise you'll have to use another mail server like gmail.

The email portion of our php program:

//////////////////////////////////////////////////////////////////////////////////////////////
// Send Email to User Notifying that they downloaded the Handbook - PEAR mail SMTP Authentication
//////////////////////////////////////////////////////////////////////////////////////////////

require_once  ('C:/wamp/bin/php/php5.4.16/pear/Mail.php');
  require_once ('C:/wamp/bin/php/php5.4.16/pear/Mail/mime.php');


 $from = "Sender <user@mailserver.com>";
$to = " Recipient <xxx@comcast.net>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

 $host = "xxx.mailserver.com";
$username = "user@mailserver.com"; // edited out for this  helpdesk email only
$password = "xxxxxxx"; // edited out for this helpdesk email only

 $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, $body);

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

//////////////////////////////////////////////////////////////////////////////////////////////
// End of PEAR mail
//////////////////////////////////////////////////////////////////////////////////////////////

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dave Baldwin
You might want to take a look at PHPMailer instead of PEAR Mail.  This https://github.com/PHPMailer/PHPMailer is the current version.