Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. // Key for API at apilayer.net
  3. define('ACCESS_KEY', 'dcbd625c3505e499416fbaf36ba9a087');
  4. // Here we will store an errors
  5. $errors = array();
  6. // https://pastebin.com/1TGZ4fB5
  7. // Check email with regex
  8. function validEmail($str) {
  9. return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
  10. }
  11.  
  12. /**
  13. * @param $email
  14. * @return bool
  15. */
  16. function scoringEmail($email){
  17. $params = array(
  18. 'access_key' => ACCESS_KEY,
  19. 'email' => $email,
  20. 'smtp' => '1',
  21. 'format' => '1',
  22. );
  23. $url = "http://apilayer.net/api/check?".http_build_query($params);
  24. $response = file_get_contents($url);
  25. if($response === false){
  26. return false;
  27. }
  28. // If we are here - we have response!
  29. $response = json_decode($response, true);
  30. //var_dump($response); exit;
  31. if(isset($response['smtp_check'])){
  32. return (bool)$response['smtp_check'];
  33. }
  34.  
  35. return false;
  36. }
  37.  
  38. /**
  39. * Get subscriber email
  40. */
  41. if(isset($_POST['email'])){
  42. // It means that we have at least the field
  43. // But we don't know if it is real and OK
  44. $email = strtolower(trim($_POST['email']));
  45. // Is syntax not correct?
  46. if (!validEmail($email)){
  47. $errors[] = 'Your email is not valid!';
  48. } elseif(!scoringEmail($email)) {
  49. $errors[] = 'Your email has low score!';
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement