i have a lot of spam users request account with mails on specific domain,i used the User restrictions module to make e-mails on that domains not allowed, but only to the registration .i want to know how can i do the same to the Simplenews module to reject e-mails from specific domains to register in the newsletter. thatnks

  • i think u need to make a rule for this – monymirza Mar 29 '13 at 11:26
  • i have tried to add rule with event as :A user has been subscribed and Conditions as: Execute custom PHP code(strpos("@domain.com",$mail)what i understand is $mail is the mail of the subscribed user and the condition must return aboolean value ,- and action as : "Unsubscribe an e-mail adress from a newslette" with data selector as mail – JokerDev Mar 29 '13 at 13:31

How are users registering their email addresses? For example, we use simplemail on http://goniseko.com in the footer. It's a signup block that anyone can use.

Is this where your spammers are signing up from?

In my opinion, this is super easy to fix, if you aren't afraid of creating a quick and dirty module that uses hook_form_alter.

In the module you would simply create a validation rule that if the form value submitted contained 'baddomainame.com' it would prevent the form from sending.

function mymodule_hook_form_alter(&$form, &$form_state, $form_id){
    if($form_id == 'my_simple_news_form_id'){
        $form[#validate][] = 'check_domain_callback_validate';

function check_domain_callback_validate(&$form, &$form_state){
    if(&$form_state['values']['simple-news-email-value'] == 'baddomainame.com'){
        form_set_error('', 'BAD DOMAINNAME, BAD! YOU NO SIGN UP');

of course all of that is pseudo code, but the structure should get you started. Here is a link to the forms API tutorial that will help if you are not very familiar with FAPI.


  • thanks for reply ,i will try this and i hope i can do it in the right way in order not to affect the newsletter thanks – JokerDev Mar 29 '13 at 13:23
  • sorry for late reply.i followed your suggestions and it works!! i wrote a module,and give it the form name and the field that i want to perform the validate.but if there is more than one field mail in the page all of them will be red.is this have a solution? – JokerDev Apr 2 '13 at 8:22
  • Interesting. the if statement in the first function should validate only if it is for that particular form, but you say all of them are executing? In the 2nd function, you could also verify the formid again in the second function as part of the if statement, ex $form_state[][] == domain && $form['#id']. If you have Devel module installed use DSM($form) in the second function to find the formid. I forget what that is called exactly. Will check. Btw, I made a small error in the example code. You can remove the '&' from the $form_state variable in the if statement. it's not needed. – blue928 Apr 2 '13 at 8:35
  • thanks for your reply again .i will give it a try .and already removed the '&' because i took your suggestions and read the API . – JokerDev Apr 2 '13 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.