Page 1 of 1

SMTP PHP Question

Posted: Tue May 12, 2009 2:41 pm
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

Re: SMTP PHP Question

Posted: Tue May 12, 2009 7:06 pm
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.