Filter out subscription email address

Hi,

I am a freelance website creator and am working on a website for a client’s company. I added a newsletter signup form feature using Mailchimp on the website however my client wants the following things in addition which I can’t figure how to put into place:

  1. The newsletter signup form must accept only official/business email addresses and no personal mail address such as gmail, yahoo etc.

While searching I came across this ‘blacklist’ ‘grey list’ concept but I am not fully aware how to utilize it on the site to allow only official email registrants to subscribe.

I am fine with not using mailchimp sign up form if required but if someone could please help me out here with the script/code required to make the subscription form workable with the specific requirement!

Thank you so much in advance!

Regards,

Maybe something like this would work.

<?php
//build list of not allowed providers as lowercase
$NotAllowedClients = array("aol","applemail","comcast","entourage","gmail","hotmail","outlook","iphone","thunderbird","yahoo");

//test email
$email = "MyAddress@Gmail.com";   
 
preg_match_all('/\\@(.*?)\\./',$email,$clientarr);            
$client = strtolower($clientarr[1][0]);            

if(!in_array($client,$NotAllowedClients)){
	//Passed
	echo "Passed";
}else{
	//Failed
	echo "Failed";
}
?>

Hi Drummin,

Thank you for your reply. I will try this code and see if it works else i’ll come back here again… Tc.

Hi Drummin,

I tried to edit the code a bit to suit my needs however the form isn’t working as expected still. I am getting this error “Parse error: syntax error, unexpected ‘else’ (T_ELSE) in /home4/thecafecircle/public_html/company/subscribe.php on line 39”

Here’s my php code for your reference:

<?php

/* Configuration */
$subject = 'Please subscribe me to your Risk Alerts'; // Set email subject line here
$mailto  = '<my email address>'; // Email address to send form submission to
/* END Configuration */

$FName      = $_POST['FName'];
$LName       = $_POST['LName'];
$Email          = $_POST['Email'];

// HTML for email to send submission details
$body = "
<br>
<p>The following information was submitted through the contact form on your website:</p>
<p><b>Name</b>: $FName $LName<br>
<b>Email</b>: $Email<br>
";


$headers = "From: $FName $LName <$email> \\r\
";
$headers .= "Reply-To: $Email \\r\
";
$headers .= "MIME-Version: 1.0\\r\
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\\r\
";
$message = "<html><body>$body</body></html>";

//build list of not allowed providers as lowercase
$NotAllowedClients = array("aol","applemail","comcast","entourage","gmail","hotmail","outlook","iphone","thunderbird","yahoo");

//test email
$Email = "MyAddress@Gmail.com";

preg_match_all('/\\@(.*?)\\./',$Email,$clientarr);
$client = strtolower($clientarr[1][0]);

if(!in_array($client,$NotAllowedClients)){
    //Failed
    echo "$failed";
else{
    //Passed
    echo "$success";
}

// Success Message
$success = "
<div class=\\"row-fluid\\">
    <div class=\\"span12\\">
        <h3>Subscription successful!</h3>
        <p>Thank you for taking the time to subscribe to our weekly Risk Alerts.</p>
    </div>
</div>
";

// Failure Message
$failed = "
<div class=\\"row-fluid\\">
	<div class=\\"span12\\">
		<h3>Subscription Failed!</h3>
		<p>Please use an official/company email address to subscribe.</p>
	</div>
</div>
";

?>

Thank you in advance!

Missing that end bracket before }else{

if(!in_array($client,$NotAllowedClients)){
    //Failed
    echo "$failed";
}else{
    //Passed
    echo "$success";
}

Move your success and failure messages to top of your page before they are called by the code posted here.