PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 30, 2022

[FIXED] How to Check for PEAR Mail SMTP Authentication Failure

 August 30, 2022     pear, php, smtp     No comments   

Issue

I'm constructing an SMTP e-mail framework that will have a default username and password for sending e-mails (using PHP's PEAR Mail), but I want to have functionality to provide alternate e-mail account credentials for sending an e-mail.

So, for debugging I need to be able to determine why an e-mail was unable to be sent. Does anyone know of an easy to determine that the failure was due to an authentication issue?

I ran a test case with an invalid password. Obviously to check for errors:

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

With the error message being:

authentication failure [SMTP: Invalid response code received from server (code: 535, response: 5.7.3 Authentication unsuccessful)]

So, I could simply parse this string and determine that it was an "Authentication Failure", but only if I'm confident this will always be the response when there is an authentication failure. My question to everyone is, can I expect this message to always be returned if there is an authentication failure, or does anyone know of an easier solution for verifying login credentials BEFORE or AFTER attempting to send an e-mail?


Solution

A PEAR_Error object has - among others - methods to get the error code and message separately:

  • getCode()
  • getMessage()

In the Mail package case, the error code is an SMTP error code, documented in RFC 5321.



Answered By - cweiske
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing