forked from hbattat/verifyEmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,91 @@ | ||
emailVerify | ||
VerifyEmail | ||
========== | ||
Is a PHP function that can be easily used to verify an email address and make sure it is valid and does exist on the mail server. | ||
Is a PHP class that can be easily used to verify an email address and make sure it is valid and does exist on the mail server. | ||
|
||
This function connects to the mail server and checks whether the mailbox exists or not. | ||
This class connects to the mail server and checks whether the mailbox exists or not. | ||
|
||
|
||
How to use: | ||
=========== | ||
Simply call the function: | ||
Initialize the class: | ||
|
||
```PHP | ||
verifyEmail('[email protected]', '[email protected]'); | ||
$ve = new VE\VerifyEmail('[email protected]', '[email protected]'); | ||
``` | ||
The first email address '[email protected]' is the one to be checked, and the second '[email protected]' is an email address to be provided to the server (just for testing, but would be better if it is a valid email) | ||
OR (you can specify other port number than 25) | ||
```PHP | ||
$ve = new VE\VerifyEmail('[email protected]', '[email protected]', 26); | ||
``` | ||
|
||
The first email address '[email protected]' is the one to be checked, and the second '[email protected]' is an email address to be provided to the server. This email needs to be valid and from the same server that the script is running from. To make sure your server is not treated as a spam or gets blacklisted check the score of your server here https://mail-tester.com | ||
|
||
|
||
Then you call the verify function: | ||
|
||
```PHP | ||
var_dump($ve->verify()); | ||
``` | ||
|
||
This will restun a boolean. True if the email is valid, false otherwise. | ||
|
||
|
||
If you want to get any errors, call this function after the verify function: | ||
|
||
```PHP | ||
print_r($ve->get_errors()); | ||
``` | ||
|
||
This will resturn an array of all errors (if any): | ||
|
||
This will restun a string "valid" if the email [email protected] is valid, and "invalid" if the email is invalid | ||
|
||
```HTML | ||
Array | ||
( | ||
[0] => No suitable MX records found. | ||
) | ||
``` | ||
|
||
If you want to get the the actual details of that connection, add another parameter to the function: | ||
|
||
|
||
If you want to get all debug messages of the connection, call this function: | ||
|
||
```PHP | ||
print_r(verifyEmail('[email protected]', '[email protected]', true)); | ||
print_r($ve->get_debug()); | ||
``` | ||
|
||
This will resturn an array that looks like this: | ||
This will return an array of all messages and values that used during the process. | ||
|
||
|
||
|
||
```HTML | ||
Array ( [0] => invalid [1] => 250 mx.google.com at your service 250 2.1.0 OK u4si6155213qat.124 - gsmtp 550-5.1.1 The email account that you tried to reach does not exist. Please try ) | ||
Array | ||
( | ||
[0] => initialized with Email: h*****@gmail.com, Verifier Email: [email protected], Port: 25 | ||
[1] => Verify function was called. | ||
[2] => Finding MX record... | ||
[3] => Found MX: alt4.gmail-smtp-in.l.google.com | ||
[4] => Connecting to the server... | ||
[5] => Connection to server was successful. | ||
[6] => Starting veriffication... | ||
[7] => Got a 220 response. Sending HELO... | ||
[8] => Response: 250 mx.google.com at your service | ||
|
||
[9] => Sending MAIL FROM... | ||
[10] => Response: 250 2.1.0 OK gw8si3985770wjb.84 - gsmtp | ||
|
||
[11] => Sending RCPT TO... | ||
[12] => Response: 250 2.1.5 OK gw8si3985770wjb.84 - gsmtp | ||
|
||
[13] => Sending QUIT... | ||
[14] => Looking for 250 response... | ||
[15] => Found! Email is valid. | ||
) | ||
``` | ||
|
||
|
||
Notes: | ||
====== | ||
- Some mail servers will silentlty reject the test message, to prevent spammers from checking against their users' emails and filter the valid emails, so this function might not work properly with all mail servers. | ||
|
||
- You server must be configured properly as a mail server to avaiod being blocked or blacklisted. This includes things like SSL, SPF records, Domain Keys, DMARC records, etc. To check your server use this tool https://mail-tester.com | ||
|