Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Key for API at apilayer.net
- define('ACCESS_KEY', 'dcbd625c3505e499416fbaf36ba9a087');
- // Here we will store an errors
- $errors = array();
- // https://pastebin.com/1TGZ4fB5
- // Check email with regex
- function validEmail($str) {
- return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
- }
- /**
- * @param $email
- * @return bool
- */
- function scoringEmail($email){
- $params = array(
- 'access_key' => ACCESS_KEY,
- 'email' => $email,
- 'smtp' => '1',
- 'format' => '1',
- );
- $url = "http://apilayer.net/api/check?".http_build_query($params);
- $response = file_get_contents($url);
- if($response === false){
- return false;
- }
- // If we are here - we have response!
- $response = json_decode($response, true);
- //var_dump($response); exit;
- if(isset($response['smtp_check'])){
- return (bool)$response['smtp_check'];
- }
- return false;
- }
- /**
- * Get subscriber email
- */
- if(isset($_POST['email'])){
- // It means that we have at least the field
- // But we don't know if it is real and OK
- $email = strtolower(trim($_POST['email']));
- // Is syntax not correct?
- if (!validEmail($email)){
- $errors[] = 'Your email is not valid!';
- } elseif(!scoringEmail($email)) {
- $errors[] = 'Your email has low score!';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement