Blocking certain domains from php mailer process script or form

45 Views Asked by At

I keep getting blasted with emails from certain domains or domain extensions. I would like to add a function to mitigate these emails. If somebody could help me with either adding a function to block the form from sending.

Below is the process script i have tried to add code to unsuccessfully.

<?php

$mail = $_POST['email_quote'];

/*$subject = "".$_POST['subject'];*/
$to = "[email protected]";
$subject = "Online Website Quote Request";
$headers = "From: Website <[email protected]>";

$message = "\nPERSONAL INFO";
$message .= "\nFirst Name: " . $_POST['firstname_quote'];
$message .= "\nLast Name: " . $_POST['lastname_quote'];
$message .= "\nEmail: " . $_POST['email_quote'];
$message .= "\nPhone number: " . $_POST['phone_quote'];

$message .= "\n\nVehicle Details";
$message .= "\nYear: " . $_POST['vehicle_year_quote'];
$message .= "\nMake: " . $_POST['vehicle_make_quote'];
$message .= "\nModel: " . $_POST['vehicle_model_quote'];

$message .= "\n\nADDTIONAL INFO";
$message .= "\nLocked out of your vehicle? " . $_POST['option_1'];
$message .= "\nLost All Your Vehicle Keys? " . $_POST['option_2'];
$message .= "\nPush to start ignition? " . $_POST['option_3'];
$message .= "\nRequire new key(s) made? " . $_POST['option_4'];
$message .= "\nRequire new remote(s) made? " . $_POST['option_5'];
$message .= "\nVehicle has keyless entry? " . $_POST['option_6'];

$message  .= "\n\nADDITIONAL NOTES";
$message .= "\nMessage: " . $_POST['message_quote'];

//Receive Variable
$sentOk = mail($to,$subject,$message,$headers);

//Confirmation page
$user = "$mail";
$usersubject = "Thank You";
$userheaders = "From: [email protected]\n";
/*$usermessage = "Thank you for your time. Your request is successfully submitted.\n"; WITH OUT SUMMARY*/
//Confirmation page WITH  SUMMARY
$usermessage = "Your request has been successfully submitted. One of our staff will contact you shortly. If you require immediate assistance with yo$
mail($user,$usersubject,$usermessage,$userheaders);

?>

Thank you for any and all help with this.

I have seen multiple examples on stackoverflow but have not been able to implement anything that actually works properly. I end up breaking my form or it just says the form was submitted and breaks the mailer.

Here is one i've tried and failed to get properly working. It will still send a success message on the page itself but will not send any email afterwards worst case or will break the page depending on the edits i make.

// You can add as many email addresses as you'd like to this list.
$blacklist = [
    '@mail.ru'
];

// The name of the field representing the email address input
$field_name = 'email_quote';

// The error message to show when an invalid email address is submitted
$error_message = 'This email is not allowed';

// Do not edit below
foreach ($blacklist as $blacklist_email)
{
    if (stripos($post[$field_name], $blacklist_email) !== false)
    {
        throw new Exception($error_message);
    }
}

i also tried the following but failed to implement it correctly or possibly forgot to add other code to enable its function..

private function validEmail($value) {
    if (!$value || !filter_var($value, FILTER_VALIDATE_EMAIL)) return false; 
    if (preg_match('#@example\.org$#uiD', $value) === 1) return false;
    if (preg_match('#@example\.net$#uiD', $value) === 1) return false;
    return true;
}
0

There are 0 best solutions below