Custom PHP endpoint to properly capture a non-cached Referrer URL and Form URL and send an email alert including both, all of your fields, and more!

Scott Freeman

I wanted to share something that I haven't found anywhere else in Act-On Connect (both in the documentation and community posts), and something I couldn't even really find much information anywhere online, specific to Act-On.  So my hope is this helps someone in a similar situation.

Our site is made with WordPress, which is PHP based, and one known issue with capturing the "HTTP_REFERER" is that it caches.  From's documentation, they say:

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

We were utilizing a plugin called Gravity Forms and pointing the confirmation redirect to the Form URL endpoint that you can make in Act-On (via Content > Form Post URLs).  The problem is that our Referral URL was getting cached... and due to our host WPEngine's amazing caching layers... we finally noticed it (after who-knows-how-long...)

At any rate... we had to come up with a solution... and we did!


I did some tests with Act-On's embeddable forms (since, up until now, we were using their Classic Forms).  It turned out... Act-On's embeddable forms are somehow able to capture the Referral URL without caching being an issue.  However, there was still a problem... we use the referring URL on our end to keep track of how our campaigns are doing.  With Gravity Forms, we were able to get this information - albeit, in hindsight, we realize now that it wasn't 100% accurate. But still, the fact remained... we needed to have the Referrer URL (and the URL where the form lived on our site) to be in the alerts we received once a form was submitted.

Unfortunately, Act-On's "Email Alerts" is limited in this regard (and the idea I submitted to the Product Idea board is under consideration). What our solution ended up being was to create a PHP file on our end, and included the link to the PHP file inside of the "External Data Submission" (or in Classic Forms, I think it's called Double Posting... or something to that effect) area, when editing the form.

I wanted to include the most basic PHP file example that would work out-of-the-box for anyone wanting to give it a go.  So, below I've included the code:


$headers = array(
"From" => "",
"Content-Type" => "text/html",
"charset" => "utf-8"

/* exiting double quotes is important instead of using single quotes which cause display issues */

/* table code pulled from Act-On's Email Alerts, to maintain consistency and familiarity for the end-user */
$tableStart = "<table style=\"line-height:1.5\"><tbody>";
$tableRows = ""; //intentionally empty, gets populated via foreach loop
$tableRow1 = "<tr><td valign=\"top\" align=\"right\" style=\"padding-bottom:2px\"><b>"; // add $key
$tableRow2 = "</b></td><td align=\"center\" valign=\"top\">&#58;</td><td valign=\"top\" style=\"padding-bottom:2px\">"; // add $val
$tableRow3 = "</td></tr>";
$tableEnd = "</tbody></table>";

/* this "foreach" loop runs through all of the fields posted, empty or not */
foreach ($_POST as $key => $val) {
$tableRows .= $tableRow1.$key.$tableRow2;
foreach ($val as $vals){
$tableRows .= trim(htmlspecialchars($vals)).", ";
$tableRows .= $tableRow3;
$tableRows .= $tableRow1.trim(htmlspecialchars($key)).$tableRow2.trim(htmlspecialchars($val)).$tableRow3;

/* builds the table w/ all of the fields */
$allFields = $tableStart.$tableRows.$tableEnd;

/* sends the email */
mail("", "All fields for ".$_POST['ao_camp'], $allFields, $headers);


This will basically send an email including every single field posted by the form submission.  There's a lot of really great information to capture!  Here's a full list of the variables you are able to capture:


You can see there is "_REFERRER" but this IS NOT what you want if you're looking to capture the uncached referring URL.  The one you'll want is "ao_refurl".

Another helpful bit of code I want to share is how to actually capture this, and the other listed variables above, to be included in the email - instead of just using the "foreach" loop I have in the code:

if(!empty($_POST['ao_refurl'])) { 
$tableRows .= $tableRow1."Referring URL".$tableRow2.trim(htmlspecialchars($_POST['ao_refurl'])).$tableRow3;

You can replace both instances of 'ao_refurl' with any of the variables listed, and use this technique to build the table HTML within the "$tableRows" variable to capture only a limited number of selected variables.  

The other important thing to know... if you're capturing any sort of Combo Field data (checkboxes, radio buttons, etc) and need to capture multiple fields... then you have to make sure the field name of the combo field ends with [] (opened and closed square brackets).

This way, when they come in, they are automatically able to be handled like an Array.  Act-On submits these variables as duplicates, not Arrays. For example, let's say your field name was "interested_in" - and it was a group of checkboxes to allow the customer to choose what they're interested in.  It gets sent over as the variable "interested_in" multiple times.  But, by adding the [] at the end, and running the code below, you're able to extract which options were submitted - otherwise, it will ONLY capture the LAST checked option.

if(!empty($_POST['interested_in'])) { 

	$msgRows .= $tableRow1."Type of Demo".$tableRow2;
	foreach ($_POST['interested_in'] as $interest) {
		$msgRows .= trim(htmlspecialchars($interest)) . "";


You can see a very similar approach in the very top code I shared (to capture all of the POST values) where there's a check to see if the value is an Array, and - if so - run through it to grab each value.


I hope this is able to give some sort of clarity to anyone who was lacking it before.  If this code could be improved upon, please feel free to contribute!





Please sign in to leave a comment.