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 <> 0 and
to_timestamp(created) < (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' => array($viewer_id)));
$gender = $result->fetchField();
if ('Robot' == $gender) {
....
}
2) And I probably should provide a hook_mail_alter
in my custom module:
function MY_CUSTOM_MODULE_mail_alter(&$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.
hook_mail_alter
?$message
contain a reference to the related user account?dpm($message);
to the mail alter hook. Then invoke the email you're trying to catch into sending, and a message will appear on screen containing all the contents of$message