I'm including the site contact form on a page with these 2 lines.

  module_load_include('inc', 'contact', 'contact.pages');
  print render(drupal_get_form('contact_site_form'));

The page loads as expected when a user is logged in, but for an anonymous user the page returns a 403.

If I give the "Administer contact forms and contact form settings" permission to anonymous users, then the page will load for anonymous users. I gave the "Use the site-wide contact form" permissions to anonymous users, but they still get an access denied error.

Is there a way to allow the form to load for anonymous uses without giving them admin privileges?

  • 1
    If you go to domain.com/contact as anonymous, can you see the form?
    – rreiss
    Commented Aug 26, 2013 at 6:39
  • Just to be sure - if you disable all modules except contact (on a copy if possible), does it persist? And do Contact form blocks solve your issue? And I second Rotem's question above.
    – Mołot
    Commented Aug 26, 2013 at 6:41

2 Answers 2


The Access Denied error is returned because the following code executed by code_site_form(). (Notice the call to drupal_access_denied().)

  $limit = variable_get('contact_threshold_limit', 5);
  $window = variable_get('contact_threshold_window', 3600);
  if (!flood_is_allowed('contact', $limit, $window) && !user_access('administer contact forms')) {
    drupal_set_message(t("You cannot send more than %limit messages in @interval. Try again later.", array('%limit' => $limit, '@interval' => format_interval($window))), 'error');

Users with the "administer contact forms" permission don't get that error, since the limit for the sent messages doesn't apply to them.

Check those Drupal variables have not been set to different values that lower the number of allowed messages. The default is 5 messages in 1 hour.

As side note, render(drupal_get_form('contact_site_form')) would cause a "call-time pass-by-reference" warning in PHP 5.3, since render() is expecting a variable passed by reference, but drupal_get_form() doesn't return a reference. PHP 5.4 will raise a fatal error for that same code. The code calling render() should always use a variable.

module_load_include('inc', 'contact', 'contact.pages');
$form = drupal_get_form('contact_site_form');
print render($form);
  • Thanks for the clear answer and the bonus info. :) This solved my problem. The epilogue: I ended up needing form customization and swapped out the site wide form with a Webform.
    – nrw
    Commented Aug 30, 2013 at 21:13

The permission you should be looking at is "Use the site-wide contact form"

  • A good thought. I do have "Use the site-wide contact form" checked for anonymous users and still get these symptoms.
    – nrw
    Commented Aug 26, 2013 at 2:02

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.