How to Add an HTTP Referer URL in Email Notifications in Shack Forms

In some use cases, you may want to add a referer URL in email notifications sent by your Shack Forms module.

You can achieve this in the three following steps:

  1. Create a new empty HTML email template for your Shack Forms module.
  2. Add the required PHP and HTML code in your new template.
  3. Set this new template as a default template for your email notifications for admin and/or users.

Let's get started.


Step #1. Create a new HTML email template for your Shack Forms module

  • Create a new empty HTML email template for your email notifications as discussed in this tutorial. For my example, I created the referer.php template:

my example referer php template

Excellent! You now have a new HTML email template for your Shack Forms module. But it is empty. Let's add some PHP and HTML code to it.


Step #2. Add the required PHP and HTML code in your new template

  • Add to the .PHP file of your new HTML email template the following code:

<p>You arrived to this page from the following URL: <?php echo $_SERVER['HTTP_REFERER'];?></p>

my example code

  • Click Save & Close.

Good job! Your template is ready. You are ready now to set this template as a default HTML template for notifications sent by your Shack Forms module.


Step #3. Set this new template as a default template for your email notifications

  • Open your Shack Forms module for editing.
  • Click the Email Template tab:

click email template tab

On form submissions, Shack Forms sends out email notifications to two types of users:

  • To administrators
  • To users.

Let's assume you want to use your newly created HTML template for email notifications, that Shack Forms module sends to the site administrator. Here is how you would set it:

  • Click inside the Email Sent to Admins field. In the dropdown list of HTML templates, select your newly created template. For my example, I will select Referer:

set the administrator html template

  • Repeat this step for the Email Sent for the Auto-replies field.
  • Click Save or Save & Close.
  • Submit a test form.
  • Check the inbox of the site administrator. You will see the email notification with your new HTML template displaying the HTTP referer URL.

Note: Please, be mindful of the fact that modern browsers allow users to disable HTTP referer. So, there is a likelihood that your email notification will end up with an empty HTTP referer.