I have the Mimemail module set up to send HTML mails out, after a form is filled in an email is sent to the user based on a custom template.

But the email should only be sent out if the user has previously filled in another form, if they haven't a message needs to be displayed and the email cancelled.

I'm simply using the following code to check that they have filled in the other form previously:

$query_result = db_query("SELECT MAX(sid) as max_id FROM webform_submitted_data WHERE data = '" . $email . "' AND nid = ###" )->fetchCol();

So if this returns an empty array then a message needs to be displayed and the email cancelled, but I can't seem to stop the email being sent, how do I do this?

1 Answer 1


You can use hook_mail_alter() for that, e.g.

function MYMODULE_mail_alter(&$message) {
  if ($message['id'] == 'MYMODULE_foo' && any_other_condition()) {
    $message['send'] = FALSE;        
  • thank you! One problem, I still get a 'An error occurred and processing did not complete.' message how can I stop this from appearing?
    – user61334
    May 16, 2016 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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