Courier Quote Form


I was just wondering if someone had a minute to cast their eye over this form someones helped me create, it’s meant to be a form on my website where people can get a quote for courier work, It’s meant to use google to look up the start and end locations, work out the distance between and put it all in an email to me.

It’s using google to lookup the address when you type it in but the email it’s sending isn’t containing the addresses. Also it’s not working out the distance either unfortunately, has anyone got experience of a code like this?


Here’s the script:


$apikey = "**key**";

$start_pre = $_POST['start'];
$start = str_replace(' ', '%20', $start_pre);

$end_pre = $_POST['end'];
$end = str_replace(' ', '%20', $end_pre);

$url = "" . $start . "&destinations=" . $end . "&key=" . $apikey;

$json = file_get_contents($url);
$obj = json_decode($json);


<script type="text/javascript" src="<? echo $apikey; ?>&amp;libraries=places"></script>

  <style id="compiled-css" type="text/css">
      .autocomplete {

  <script type="text/javascript">//<![CDATA[

var options = {
   componentRestrictions: {country: 'gb'}

    var VanillaRunOnDomReady = function() {
function initialize() {

    var acInputs = document.getElementsByClassName("autocomplete");

    for (var i = 0; i < acInputs.length; i++) {

        var autocomplete = new google.maps.places.Autocomplete(acInputs[i], options);
        autocomplete.inputId = acInputs[i].id;

        google.maps.event.addListener(autocomplete, 'place_changed', function () {
            document.getElementById("log").innerHTML = 'You used input with id ' + this.inputId;



var alreadyrunflag = 0;

if (document.addEventListener)
    document.addEventListener("DOMContentLoaded", function(){
    }, false);
else if (document.all && !window.opera) {
    document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>');
    var contentloadtag = document.getElementById("contentloadtag")
        if (this.readyState=="complete"){

window.onload = function(){
  setTimeout("if (!alreadyrunflag){VanillaRunOnDomReady}", 0);


<form action="" method="post">

<script type="text/javascript" src="<? echo $apikey; ?>&libraries=places"></script>
<p>Your Name: <input type="text" name="name"></p>
<p>Contact Email: <input type="text" name="email"></p>
<p>Pickup: <input name="start" class="autocomplete" id="ac1" placeholder="Enter pickup address" type="text" value="<? echo $start_pre; ?>"></p>
<p>Drop off: <input name="end" class="autocomplete" id="ac2" placeholder="Enter drop off address" type="text" value="<? echo $end_pre; ?>"></p>
<p>Comments: <textarea name="comments" cols="" rows=""></textarea></p>
<input type="hidden" name="sent" value="1">
<input type="submit"><br><br>

if ($_POST['sent'] == "1") {
$subject = "Skelmersdale Couriers Quote";

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$from = $obj->origin_addresses[0];
$to = $obj->destination_addresses[0];

$message = "
<p>Name: $name</p>
<p>Email: $email</p>
<p>Pickup: $from</p>
<p>Drop Off: $to</p>
<p>Comments: $comments</p>

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: Skelmersdale Couriers <[email protected]>\r\n";
$headers .= "From: Skelmersdale Couriers <[email protected]/>\r\n";

mail($to, $subject, $message, $headers);

Can you place your code between code tags please?

1 Like

first have a look at var_dump($obj); if the data is in there.

This shouldn’t be used. It is a leftover from the old days and will wipeout what you want to be on the DOM. Instead, you want to append the DOM.

var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');

script.type = 'text/javascript';

if (isOpera)
    script.src = "javascript:void(0)";

Sponsor our Newsletter | Privacy Policy | Terms of Service