Do not send registration mail to fake users, who haven't specified their gender in registration form Since several years I run a Drupal 7 web site - as a frontend to a multi-player card game.

I have the following SPAM protection at my web site: the new users should specify their gender at the registration (it should be "Male" or "Female", but not the default "Robot") and then they have to play the card game:



Every night I run a cronjob, which deletes users who have wrong gender or who have registered 10 days ago and still haven't played:

delete from drupal_users
where uid &lt;&gt; 0 and
to_timestamp(created) &lt; (now() - interval '10 day') and
uid not in (select distinct id from pref_money); /* haven't played the game */


This does work well, BUT recently the amount of registering fake users has increased to hundreds per hour and my site keeps sending lots of registering mails (which bounce then to my poor mailbox) every minute.

So my question is: how NOT to send the registration mail to users who have their gender set to "Robot"?

Here is what I have found sofar:

1) The gender (an additional field at my reg. form) can be found the following way:

        $result = db_query('select field_gender_value from {field_data_field_gender} where entity_id=:id', array(':id' =&gt; array($viewer_id)));
        $gender = $result-&gt;fetchField();
        if ('Robot' == $gender) {
           ....
        }


2) And I probably should provide a hook_mail_alter in my custom module:

function MY_CUSTOM_MODULE_mail_alter(&amp;$message) {
  # XXX how to find gender here?
  if ('Robot' == $gender) {
      # XXX how to abort mailing for registration only?
      $message['send'] = FALSE;
      return;
  }
}


But in 2) I don't know 2 things - how to find the gender value there and how to cancel the registration mails only?

Any suggestions please?

Please do not suggest the Mollom module or any standard Drupal anti-spam measures, because my question is very specific.
I suggest you implement hook_form_id_alter to either add a new validation function to the registration form, or replace the submit callback.

In a validation function, you have access to the form values, and you can do whatever checks you want, and fail the submission. This will reject the form all together.

If you replace the submit callback instead, you could override only the sending of the e-mail. but otherwise let the form pass through, which seems closer to what is being asked for.