SMTP PHP Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aschandra2703
Forum Newbie
Posts: 1
Joined: Tue May 12, 2009 2:39 pm

SMTP PHP Question

Post by aschandra2703 »

Hi Php'ers

i have a question to ask regarding the SMTP. i am about to write a module which sends email using SMTP, the question i have is, right now even if i give some wrong email address like ('asdfa@asdfasd.net') its still sending it and then i am getting an return email from the host saying wrong email address, is there something i can do to check if the email is not sent, show the error then and there on the screen without checking for an email.

regards
Sirish
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: SMTP PHP Question

Post by ldougherty »

Are you using PHP to initiate the SMTP session? If so you could use the RCPT option to see if a 250 code is returned meaning the user has been verified as OK.

Code: Select all

 
 
  // Rcpt to...
  fputs($cp, "RCPT TO: <$host>\r\n");
  $res=fgets($cp,512);
  echo "MAIL TO: $host<br>";
  if(substr($res,0,3) != "250") { 
    echo "[<font color=red><b>FAIL</b></font>] RCPT TO failed<br>$res"; 
    exit();
  } else { echo "[<font color=blue><b>SUCCESS</b></font>] $res<br>"; 
 
 
This is just a small part of the script I use to test email addresses via SMTP to see if they are functioning properly.
Last edited by Benjamin on Tue May 12, 2009 7:42 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Post Reply