Using a function from this answer:
// returns true if $domain_name is valid; false otherwise
function is_valid_domain_name($domain_name) {
return filter_var('abc@' . $domain_name, FILTER_VALIDATE_EMAIL) !== false;
}
// make sure $_POST['domains'] exists and isn't empty
if(isset($_POST['domains']) && $_POST['domains'] != '') {
// split the domains around commas
$domains = explode(',', $_POST['domains']);
foreach($domains as $domain) {
// remove white space from both ends of the string
$domain = trim($domain);
// validate the domain; if it fails, output an error but continue with the rest
if(!is_valid_domain_name($domain)) {
echo $domain, ' is not a valid domain name!', "\n";
}
}
}
else {
$check = 1;
echo 'Error, You didn\'t enter a domain name!';
}