Cancel if condition not met, show status 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(&quot;SELECT MAX(sid) as max_id FROM webform_submitted_data WHERE data = '&quot; . $email . &quot;' AND nid = ###&quot; )-&gt;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?
You can use hook_mail_alter() for that, e.g.

function MYMODULE_mail_alter(&amp;$message) {
  if ($message['id'] == 'MYMODULE_foo' &amp;&amp; any_other_condition()) {
    $message['send'] = FALSE;        
  }
}