1

I would like to block temp mail when registering on my site. I try this:

$email = htmlspecialchars($_POST['email']);

    $tempmail = array("@4tmail.com", "@mail3.top", "@mail3plus.net", "@mailfile.org", "@themail3.net", "@mail3tech.com", "@tmailer.org", "@mail3x.net", "@tmails.top", "@tmail2.com");

    $iftmp = strpos($email, $tempmail);
    if ($iftmp == true){
        die("Bad Email");
    }

but don't work

BXEE
  • 29
  • 1
  • 1
  • 7
  • Hello! Does this answer your question?https://stackoverflow.com/questions/10976706/how-to-block-disposable-email-addresses-in-your-websites-registration-form –  Dec 16 '19 at 10:58
  • `if ( preg_match( '/' . implode('|', $tempmail) . '$/i', strtolower($email)) ) { die('bad email'); }` – Wizard Dec 16 '19 at 11:18

2 Answers2

2

You can use the function in_array instead of strpos

$iftmp = in_array($email, $tempmail);
pivox
  • 51
  • 3
0

You can use in_array because in_array search an string in array however the strpos search an string in an string.


in_array take two parameter one that you are finding and second the array.

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

if (in_array("Glenn", $people))
  {
  echo "Match found";
  }
else
  {
  echo "Match not found";
  }

?>
Ahmed Ali
  • 1,908
  • 14
  • 28