hi all,
i m working on the email validation i ve to check email id either it is correct or not but i cannt send mail on them. ie when i validate all email id client send newsletter and they should not bounce.
thanx in advance
You can validate if an email matches the email syntax according to the SMTP protocol. However, this doensn't mean the email account actually exists on the domain you're trying to send email to.
To make sure the email address exsits, you will have to make an actual SMTP connection to the remote host/domain you want to send email to, and check if the email address is rejected or not. Usually, if it isn't rejected, then it means the email will be received by the server, this still doesn't mean it exists or the email will actually reach its recipient, since it could be routed to a catch all email or just trashed depending on the setup of the remote SMTP server.
It just means that the email you send will not bounce.
Here is an example of an SMTP connection:
http://www.yuki-onna.co.uk/email/smtp.html
In PHP, you'll just have to make a TCP connection to the remove SMTP server, and send it the SMTP commands up to the:
RCPT TO: mail@otherdomain.ext
If the server rejects the email account it will reply with something other then "250 ok".
A simple example:
Lets say the email address is
user@example.com
$email = 'user@example.com';
list($user, $domain) = explode('@', $email);
$port = 25; // default smtp port
$sock = fsockopen($domain, $port);
if ($sock) {
fputs($sock, 'HELO mydomain.com');
$reply = fgets($sock); // not interesting
fputs($sock, 'MAIL FROM: user@mydomain.com');
$reply = fgets($sock); // not interesting
fputs($sock, 'RCPT TO: '.$email);
$reply = fgets($sock); // interesting
list($code, $msg) = explode(' ', $reply);
if ($code == '250') {
// you received 250 so the email address is accepted
} else {
// something went wrong, the email will most likely bounce
}
fclose($sock);
}