PHP and STMP

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

HI all

First I must say that I am not sure how PHP and STMP work together so bear with me.

I want to check whether an email address exists or not using PHP? and to get information about the owner of the email address?

I have read the following:

Let us say I have an email address myname@mydomain.com

Firstly within PHP you can validate an email by using filter_var like so:
Code: [ Select ]
$is_valid = filter_var("myname@mydomain.com",FILTER_VALIDATE_EMAIL);


Secondly you would want to check if the domain runs a email server, to do this you can check the dns records for MX like so:
Code: [ Select ]
$has_dns_mx_record = checkdnsrr("myname@mydomain.com","MX");


I understand the above to some point.

Now this is where I have trouble:

You want to open the port on the domain like so:
Code: [ Select ]
$socket = fsockopen("myname@mydomain.com", 25);
$mail_running = (bool)$socket;
fclose($socket);
  1. $socket = fsockopen("myname@mydomain.com", 25);
  2. $mail_running = (bool)$socket;
  3. fclose($socket);


You can also check to see if the SMTP Server responds with a 550, i.e email does not exist, like so:
Code: [ Select ]
SEND > helo hi
250 myname@mydomain.com

SEND > mail from: <youremail@yoursite.com>
250 2.1.0 Ok

SEND > rcpt to: <myname@mydomain.com>
> 550 5.1.1 <myname@mydomain.com>: Recipient address rejected: User unknown in local recipient table
  1. SEND > helo hi
  2. 250 myname@mydomain.com
  3. SEND > mail from: <youremail@yoursite.com>
  4. 250 2.1.0 Ok
  5. SEND > rcpt to: <myname@mydomain.com>
  6. > 550 5.1.1 <myname@mydomain.com>: Recipient address rejected: User unknown in local recipient table


Looking at the above you can send commands to a valid smtp server such as helo > mail from <...> and check the 550 response.

My question is how do I put this all together with PHP.

Below is a sample I have seen using some online web tools.
Code: [ Select ]
Checking server mx1.megamailservers.com...
Opening up socket to mx1.megamailservers.com... Success!
mx1.megamailservers.com replied: 220 mail3c0.megamailservers.com ESMTP Sendmail 8.13.6/8.13.1; Thu, 16 Aug 2012 03:21:00 -0400

HELO example.com
250 mail3c0.megamailservers.com Hello 009ip.my-addr.com [10.10.10.10], pleased to meet you
(135.70 ms)
MAIL FROM: <example@example.com>
250 2.1.0 <example@example.com>... Sender ok
(189.09 ms)
RCPT TO: <myname@mydomain.com>
250 2.1.5 <myname@mydomain.com>... Recipient ok
(152.57 ms)
QUIT
221 2.0.0 mail3c0.megamailservers.com closing connection
(134.76 ms)
  1. Checking server mx1.megamailservers.com...
  2. Opening up socket to mx1.megamailservers.com... Success!
  3. mx1.megamailservers.com replied: 220 mail3c0.megamailservers.com ESMTP Sendmail 8.13.6/8.13.1; Thu, 16 Aug 2012 03:21:00 -0400
  4. HELO example.com
  5. 250 mail3c0.megamailservers.com Hello 009ip.my-addr.com [10.10.10.10], pleased to meet you
  6. (135.70 ms)
  7. MAIL FROM: <example@example.com>
  8. 250 2.1.0 <example@example.com>... Sender ok
  9. (189.09 ms)
  10. RCPT TO: <myname@mydomain.com>
  11. 250 2.1.5 <myname@mydomain.com>... Recipient ok
  12. (152.57 ms)
  13. QUIT
  14. 221 2.0.0 mail3c0.megamailservers.com closing connection
  15. (134.76 ms)


I am hoping to get a PHP script that will do something similar to the above.

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • weldan
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Malaysia

Post 3+ Months Ago

first of all,

what are you trying to do?

checking unsecured smtp server?

thanks
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

Thanks for your reply weldan

I simply want to talk to the mailserver.

I know this can be done using Telnet.

I want to do it with PHP
  • weldan
  • Newbie
  • Newbie
  • User avatar
  • Posts: 8
  • Loc: Malaysia

Post 3+ Months Ago

I sent you private message. it might help. tq
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 322
  • Loc: Canada

Post 3+ Months Ago

Hi Weldan

I got your message and it did help me out.

Now I got a funny situation.

I use the smtp RCPT TO command to send a valid email address.
The mail server comes back with 250 OK

I then send an invalid email and the server still says 250 OK

I read if the email is invalid that I should have got Unkown.

I went to one of those on-line tools that does testing similar to what I did.
When I put in the same invalid email address it actually came back with Unknown.

I read that RCPT TO is supposed to be able to determine if an email address is valid or not.

I tried using the VRFY (verify) command, but the server tells me it cannot verify and that I should us Finger, whatever that is.

I read that VRFY can sometimes be turned off, but how did the online tool do it.

Would you have any ideas?

Thanks

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 78 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.