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:
    
```php
$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?