Trying to disable mail on contact form, but it's still required on submit I am trying to make optional the mail field from the contact form. I manage to remove the asterisk by implementing the hook_form_alter:

function contact_field_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    $form['mail']['#required'] = FALSE;
}


However on form submission, I get the message "You must enter a valid e-mail address". I seems that, although the field is optional on the form, it still tries to validate it. Can somebody tell me how to make it really optional?

Thanks in advance
Are you talking about the site wide contact form or the personal contact forms that each user can have? I'll talk about the site wide form, but the following roughly applies to the personal one as well.

The email validation is hard wired in contact_site_form_validate, and the $mail is also needed in the submission handler, so there is no nice way around it.

Easy way: Set the default value for the mail field to an address that you own and then disable access to the field like this:

function contact_field_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'contact_site_form') {
    $form['mail']['#required'] = FALSE;
    $form['mail']['#default_value'] = 'me@my-site.com';
    $form['mail']['#access'] = FALSE;
  }
}


This will completely hide the mail field.

Hardcore way: In your form alter you could overwrite the default validation and submission callbacks (using $form['#validate'] and $form['#submit']) and replace them with your custom ones. This does not come without the risk of side effects. If you have other modules that want to add custom stuff and logic for contact forms, then this will probably break them. 

As an alternative, you could use the webform module. It gives you a lot more flexibility concerning the information that you want to request and having an optional email field in there is very easy to do.

Update: You can also try the following (untested):

function contact_field_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'contact_site_form') {
    $form['mail']['#required'] = FALSE;
    $form['mail']['#default_value'] = '';
    // This makes our custom validation come first.
    array_unshift($form['#validate'], 'my_custom_validation');
  }
}

function my_custom_validation($form, &amp;$form_state) {
  // This fills an empty mail value with a default one.
  if (empty($form_state['values']['mail']) {
    form_set_value($form['mail'], 'me@my-site.com', $form_state);
  }
  // After this the default validation will run.
}


This will remove the asterisk, hide any preset value and in the validation handler a default value for the mail field is set if none has been submitted by the user. That way the hard wired validation shouldn't have a reason to complain.