Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Email

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

One-Click Email Survey

One-click surveys are excellent for email — private email, public newsletters, autoresponder messages, any email that can have a clickable link — plain text or HTML.

One-click surveys are easy to use. One click and the survey is done.

To incorporate a one-click survey, the email has two or more links. Each link is a survey response choice. Links may be image or text links. Example:

Should I talk about the weather in the next newsletter?

[Yes]         [No]

When the reader clicks or taps on a survey-response link:

  1. The reader's browser is launched and sent to the One-Click Survey PHP script on your server. (The source code for the PHP script is in this article further below.)

  2. The PHP script appends the answer to a file and/or sends the answer to your email address.

  3. The PHP script then redirects the browser to your thank-you page.

Two things are required before putting the one-click survey into your emails, (1) the installed PHP script and (2) a thank-you page URL.

The Thank-You Page

Create a thank-you page for people who oblige by taking your one-click survey.

Make a note of the thank-you page URL. You'll need it for the One-Click Survey PHP script.

The One-Click Survey PHP Script

Here is the source code for the One-Click Survey PHP script. Notes follow the source code.

<?php
/*
   One-Click Survey
   Version 1.0
   January 2, 2017

   Will Bontrager Software LLC
   https://www.willmaster.com/
   Copyright 2016 Will Bontrager Software LLC

   This software is provided "AS IS," without 
   any warranty of any kind, without even any 
   implied warranty such as merchantability 
   or fitness for a particular purpose.
   Will Bontrager Software LLC grants 
   you a royalty free license to use or 
   modify this software provided this 
   notice appears on all copies. 
   Will Bontrager Software LLC
   https://www.willmaster.com
*/

/***********************/
/* Begin Customization */

// If this software shall send an email to you, provide the 
//   email address to send it to. Otherwise, leave it blank.

$EmailAddress = "name@example.com";

// If an email is sent, you may specify a subject for the email. 
//   If left blank, the default "One-Click Survey Response" will 
//   be used.

$EmailSubject = "One-click survey response!";

// If this software shall record the survey response in a file, 
//   specify the file location and name here. (The file must be 
//   writable.)

$FileForSurveyResponse = "./subdirectory/one-click-response.txt";

// If a file is to be updated with survey responses, shall a time 
//   stamp accompany the response record? Specify "Yes" or "No". 
//   If blank or neither of those is specified, "No" is default.

$TimeStamp = "Yes";

// When the survey response has been processed, what URL shall 
//   the browser be redirected to? (If left blank, redirection 
//   is to domain home/index page.)

$RedirectURL = "https://www.willmaster.com/index.php";

/* End Customization */
/*********************/

if( empty($_SERVER['QUERY_STRING']) )
{
   echo 'Inappropriate access.';
   exit;
}
$To = ( empty($EmailAddress) or strpos($EmailAddress,'@')===false ) ? false : $EmailAddress;
$Subject = empty($EmailSubject) ? 'One-Click Survey Response' : $EmailSubject;
$File = empty($FileForSurveyResponse) ? false : $FileForSurveyResponse;
$Stamp = strtolower($TimeStamp)=='yes' ? date('r') . ' ' : '';
$Redirect = empty($RedirectURL) ? '/' : $RedirectURL;
$Response = urldecode($_SERVER['QUERY_STRING']);
if( $To ) { mail($To,$Subject,$Response,"From: $To"); }
if( $File ) { file_put_contents($File,"$Stamp$Response\n",FILE_APPEND); }
if( headers_sent() ) { echo "<script>location.href='$Redirect'</script>"; }
else { header("Location: $Redirect"); }
exit;
?>

There are five places to customize in the One-Click Survey PHP script. For convenience, variable names are (colored blue) in the source code and their values are (colored red).

  1. $EmailAddress = "name@example.com";

    If One-Click Survey is to send an email to you with each survey response, provide the email address to send it to. Otherwise, leave it blank.

  2. $EmailSubject = "One-click survey response!";

    If an email is sent, you may optionally specify a subject for the email. If left blank, the default is "One-Click Survey Response". This value is unused if no email is to be sent.

  3. $FileForSurveyResponse = "./subdirectory/one-click-response.txt";

    If One-Click Survey is to record the survey response in a file, specify the file location and name here. (The file must be writable.)

    (A writable file is one that PHP can create and update. Depending on your server's PHP configuration, the file's permissions — or the permissions of the directory where the file is at — may need to be changed to 777.)

  4. $TimeStamp = "Yes";

    If a file is to be updated by recording survey responses, shall a time stamp accompany the response record? Specify "Yes" or "No". If blank or neither of those is specified, "No" is default. This value is unused if no record is to be made of survey responses.

  5. $RedirectURL = "https://www.willmaster.com/index.php";

    When the survey response has been processed, what URL shall the browser be redirected to? (If left blank, redirection is to the domain's home/index page.)

Upload the One-Click Survey PHP script to your server and make a note of its URL. You'll use the URL in your emails when offering a one-click survey.

Putting a One-Click Survey in Your Email

To create a link URL for a survey response, append a "?" and the response to the One-Click Survey PHP script URL.

As an example, if the One-Click Survey PHP script URL were http://example.com/survey.php, then the following would be the link URL for survey response "Yes":

http://example.com/survey.php?Yes

And the link would look like this.

<a href="http://example.com/survey.php?Yes">Yes</a>

(An image could be used instead of text for the link.)

Here are links for survey responses "Never", "Maybe, sometime", and "Of course!":

<a href="http://example.com/survey.php?Never">Never</a>
<a href="http://example.com/survey.php?Maybe%2c%20sometime">Maybe, sometime</a>
<a href="http://example.com/survey.php?Of%20course%21">Of course!</a>

Notice that non-alphanumeric characters in the one-click response URL following the "?" are converted to hex. If you need help with that, Character-Hex Conversion in the Willmaster Library has a converter available for use.

Most email readers convert plain text URLs into clickable links. Therefore, assuming your recipients have those types of email readers, you have the option of publishing unlinked one-click response URLs. Perhaps like this:

To vote for weather talk, click http://example.com/survey.php?Of%20course%21

Otherwise, click http://example.com/survey.php?Never

With the PHP script uploaded and a thank-you page ready, it's easy to put one-click surveys in email.

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC