-
-
Save Workman/6aa6dab1d2a38600df6f9724a1ef3e1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| function smtp_verify_email($email, $mxhost) { | |
| $email_arr = explode('@', $email); | |
| $email_to_basic = preg_replace("/[^A-Za-z0-9]/", '', $email); | |
| $from_email = "reid+".$email_to_basic."@workmangeneral.co"; | |
| $user = implode('@', array_slice($email_arr, 0, -1)); | |
| $messages = array(); | |
| $valid = "unknown"; | |
| $socket = @fsockopen($mxhost, 25); | |
| if ($socket) { | |
| $msg = "HELO $mxhost\r\n"; | |
| fwrite($socket, $msg); | |
| $messages[] = $msg; | |
| $messages[] = fgets($socket, 1024); | |
| $msg = "MAIL FROM:<$from_email>\r\n"; | |
| fwrite($socket, $msg); | |
| $messages[] = $msg; | |
| $messages[] = fgets($socket, 1024); | |
| $msg = "RCPT TO:<$email>\r\n"; | |
| fwrite($socket, $msg); | |
| $messages[] = $msg; | |
| $messages[] = fgets($socket, 1024); | |
| $msg = "QUIT\r\n"; | |
| fwrite($socket, $msg); | |
| $response = fgets($socket, 1024); | |
| $messages[] = $msg; | |
| $messages[] = $response; | |
| fclose($socket); | |
| if ($response[0] == '2') { | |
| $valid = "valid"; | |
| } elseif ($response[0] == '5') { | |
| $valid = "invalid"; | |
| } | |
| } | |
| $response = array( | |
| "email" => $email, | |
| "mxhost" => $mxhost, | |
| "messages" => $messages, | |
| "valid" => $valid | |
| ); | |
| return json_encode($response); | |
| } | |
| if (!empty($_GET["email"])) { | |
| $email = $_GET["email"]; | |
| $mxhost = $_GET["mx"]; | |
| header('Content-Type: application/json'); | |
| die(smtp_verify_email($email, $mxhost)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment