www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: [RESOLVED] Send form details to specific recipient dependant on list selection

  1. #1
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14

    resolved [RESOLVED] Send form details to specific recipient dependant on list selection

    Hello everyone,

    This is my first post to this forum (and my first attempt at PHP), so I am hoping someone can assist me with a problem I cannot get my head around.

    I am a retired old git with no real IT training, but I have created a website for our small village, which includes an online form for people to contact us.

    Currently the form works fine(ish) and sends the relevant details filled out on the form to me.

    Within the form is a "Please select" list box with various village functions. i.e. Village Hall, Parish Council, Marquee Hire & etc. I am trying to get it to send the form information to different people in the village, depending on which village function is selected. This is where I am coming unstuck, and I simply do not understand what or why, so I hope someone can show me the error of my ways (other than don't mess with what you don't understand )

    My php code is:
    PHP Code:
    <?php

     
    /* Email Variables */
    $emailSubject 'website_enquiry'
    $recipients = array(
    'recipient_1' => 'recipient1@example.com'
    'recipient_2' => 'recipient2@example.com'
    'recipient_3' => 'recipient3@example.com',
    'recipient_4' => 'recipient4@example.com',
    'recipient_5' => 'recipient5@example.com',
    'recipient_6' => 'recipient6@example.com',
    'recipient_7' => 'recipient7@example.com'
    );
    $my_email $recipients[$_REQUEST['Nature']];

    /* Data Variables */
    $Name $_POST['Name'];
    $Telephone $_POST['Telephone'];
    $Email $_POST['Email'];
    $Nature $_POST['Nature'];
    $Questions $_POST['Questions'];

    $body = <<<EOD
    <br><hr><br>
    Name: 
    $Name <br>
    Telephone: 
    $Telephone <br>
    Email: 
    $Email <br>
    recipient: 
    $recipient <br>
    Questions: 
    $Questions <br>
    EOD;
    $headers "From: $Email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success mail($my_email$emailSubject$body,
    $headers);

    /* Results */
    $theResults = <<<EOD
    <html>
    <head>
    <title>sent message</title>
    <meta http-equiv="refresh" content="3;URL=http://example.com/index.html">
    <style type="text/css">
    <!--
    body {
    background-color: #444;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 20px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #fec001;
    text-decoration: none;
    padding-top: 200px;
    margin-left: 150px;
    width: 800px;
    }
    -->
    </style>
    </head>
    <div align="center">Thank you for your enquiry. Your message has been sent and we will respond as soon as possible</div>
    </div>
    </body>
    </html>
    EOD;
    echo 
    "$theResults";
    ?>
    and the relevant part of the html within the contact form is:
    HTML Code:
    <td width="50%" height="56"><div align="center">Nature of your Enquiry ?</div></td>
          <td width="50%"><div align="center"> 
              <select name="Nature" size="1" id="Nature">
    		  <option>Please Select</option>
    <option value="recipient_1">General Enquiries</option>		  
    <option value="recipient_2">Hall Hire</option>
    <option value="recipient_3">Marquee Hire</option>
    <option value="recipient_4">Parish Church</option>
    <option value="recipient_5">Parish Council</option>
    <option value="recipient_6">Recreation Area</option>
    <option value="recipient_7">Other</option>
    </select> 
            </div></td>
    I am pretty sure I have done something simple but stupid, so any guidance to help sort this out would be much appreciated.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    You told us your aim, but you didn't tell us what was not happening. I'm guessing that the mail is not being sent, correct? Why don't you put in a test of your $success var since you have stored the result of the call to mail() in it? Also, echo out your values that are being used in the call to mail so you can confirm that much is correct. And most importantly, turn on php error checking until this whole thing is working 100%.
    Put the following at the top of your script.
    PHP Code:
        error_reporting(E_ALL E_NOTICE);
        
    ini_set('display_errors''1'); 
    Also - why are you commenting out your css code?

    There's a few other things wrong here but let's get the thing working before you do the necessary cleanup, like validating your inputs and making sure you have the proper ones.

  3. #3
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    Thanks ginerjm, my apologies. The problem is that when I complete the form in this iteration, I get an http 500 error "website cannot display the page.

    In its existing, working, iteration, I complete the form & click submit. It sends me the email of whatever I have put in the form including the selected village function, the "Thank you for your enquiry etc" message pops up for 3 seconds and then it returns me to the website home page.

    The only difference between the 2 iterations is that in the original I have
    PHP Code:
     $emailto 'kim@example.com'
    and in the second one I have changed that to
    PHP Code:
    $recipients = array( 
    'recipient_1' => 'recipient1@example.com',  
    'recipient_2' => 'recipient2@example.com',  
    'recipient_3' => 'recipient3@example.com'
    'recipient_4' => 'recipient4@example.com'
    'recipient_5' => 'recipient5@example.com'
    'recipient_6' => 'recipient6@example.com'
    'recipient_7' => 'recipient7@example.com' 
    ); 
    $my_email $recipients[$_REQUEST['Nature']]; 
    As I amended the "mailto" from $emailto to $my_email in the 2 iterations, I have also changed that, but otherwise it is exactly the same.

    I really appreciate your recommendations and will work on them and come back to this as soon as possible, but in the meanwhile, could I ask you to clarify what you mean by commenting out my CSS code ? I'm afraid I don't see it as it seems to work fine in its current basic iteration. Anyhow, many thanks for your guidance so far.

    Rgds Kim.

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    You have an html comment tag in your style tag.

    Perhaps you could show us the entire form code?

    What is causing these 2 iterations you refer to? I see no looping going on, so I don't understand what you mean by iterations. Clarify please?

    I don't see anything here that would cause your 'thank you...' message to be overwritten by some other output after 3 seconds. Perhaps you can show us that too?

  5. #5
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    The html comment at the beginning of the style tag is to bring up the 'thank you' etc as a full page html message which then closes again with a second html comment at the end.

    The 'thank you ' message refreshes back to the home page by code:
    PHP Code:
     <meta http-equiv="refresh" content="3;URL=http://example.com/index.html"
    which is the fourth row within "the results" section of my code above.

    What I mean by iteration is that I have already created an online form and a php script which works, but was only designed to send the form content to me. I am now trying to get it to send to specific recipients which is where I am having my problems.

    This is my original working full form code:
    HTML Code:
    <html>
    <head>
    <title>Welcome to Example - Contact Us</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" background="goldmold.jpg">
    <div id="Layer1" style="position:absolute; width:207px; height:42px; z-index:3; left: 10px; top: 19px;"><font size="6" face="Calligraph421 BT"><strong>Welcome 
      to <font size="7">example</font></strong></font></div>
    <h1>&nbsp;</h1>
    <p align="center"><font size="+4"><strong>Contact Us</strong></font></p>
    <hr>
    <div align="right"><font size="-1"><strong><a href="index.html" style="text-decoration = None"><font color="#000000" face="Calligraph421 BT">Return 
      to Home Page</font></a></strong></font></div>
    <blockquote> 
      <blockquote> 
        <blockquote>
          <p align="center"><font size="+1" face="Calligraph421 BT"><strong>For any 
            enquiries relating to the Village Hall, please either telephone the Bookings 
            Secretary between 08:00 and 20:00 Monday to Friday on 0845-643-0000, or 
            <a href="mailto:bookings.secretary@example.com"><font color="#0000FF">Email</font></a> 
            her with any questions.</strong></font></p>
        </blockquote>
      </blockquote>
    </blockquote>
    <p align="center"><strong><font size="+1" face="Calligraph421 BT">Alternatively, 
      or for other village matters, please complete and submit the short form below, 
      and we will respond as soon as possible</font></strong></p>
    <form action="website_enquiry.php" method="post" enctype="multipart/form-data" name="Contact" id="Contact">
      <table width="50%" border="1" align="center">
        <tr> 
          <td width="50%" height="64"><div align="center">Full Name:</div></td>
          <td width="50%"><div align="center"> 
              <input name="Name" type="text" id="Name" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="64"><div align="center">Telephone No.</div></td>
          <td width="50%"><div align="center"> 
              <input name="Telephone" type="text" id="Telephone" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="67"><div align="center">Email:</div></td>
          <td width="50%"><div align="center"> 
              <input name="Email" type="text" id="Email" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="56"><div align="center">Nature of your Enquiry ?</div></td>
          <td width="50%"><div align="center"> 
              <select name="Nature" size="1" id="Nature">
                <option selected>Please Select</option>
                <option>Hall Hire</option>
                <option>Marquee Hire</option>
                <option>Recreation Area</option>
                <option>Social Club</option>
                <option>Parish Church</option>
                <option>Other</option>
              </select>
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="127"><div align="center">Enquiry Details:</div></td>
          <td width="50%"><div align="center"> 
              <textarea name="Questions" cols="40%" rows="4" id="Questions"></textarea>
            </div></td>
        </tr>
        <tr> 
          <td width="50%"><div align="center"> 
              <input name="contactSubmit" type="submit" id="contactSubmit" onClick="MM_validateForm('Name','','R','Telephone','','RisNum','Email','','NisEmail','Questions','','R');return document.MM_returnValue" value="Submit">
            </div></td>
          <td width="50%"><div align="center"> 
              <input name="ContactReset" type="reset" id="ContactReset" value="Reset">
            </div></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p>&nbsp; </p>
      </form>
    <p align="center">&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>
    and here is the original full php:
    PHP Code:
    <?php
    /* Contact Enquiry Form PHP */
     
    /* Email Variables */
    $emailSubject 'website_enquiry'
    $emailto 'kim@homeinsomerset.co.uk';


    /* Data Variables */
    $Name $_POST['Name'];
    $Telephone $_POST['Telephone'];
    $Email $_POST['Email'];
    $Nature $_POST['Nature'];
    $Questions $_POST['Questions'];


    $body = <<<EOD
    <br><hr><br>
    Name: 
    $Name <br>
    Telephone: 
    $Telephone <br>
    Email: 
    $Email <br>
    Nature: 
    $Nature <br>
    Questions: 
    $Questions <br>
    EOD;
    $headers "From: $Email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success mail($emailto$emailSubject$body,
    $headers);

    /* Results*/
    $theResults = <<<EOD
    <html>
    <head>
    <title>sent message</title>
    <meta http-equiv="refresh" content="3;URL=http://Donyatt.com/index.html">
    <style type="text/css">
    <!--
    body {
    background-color: #444;
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 20px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #fec001;
    text-decoration: none;
    padding-top: 200px;
    margin-left: 150px;
    width: 800px;
    }
    -->
    </style>
    </head>
    <div align="center">Thank you for your enquiry. Your message has been sent and we will respond as soon as possible</div>
    </div>
    </body>
    </html>
    EOD;
    echo 
    "$theResults";
    ?>
    So, having got this working, I stupidly started tinkering to try the selected recipient bit.

    Putting the amended code here makes the post too long, so I will send immediately after this post. Kim

  6. #6
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    Part 2 of the reply....

    This is my amended contact form code:
    HTML Code:
     <html>
    <head>
    <title>Welcome to Example - Contact Us</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" background="goldmold.jpg">
    <div id="Layer1" style="position:absolute; width:207px; height:42px; z-index:3; left: 10px; top: 19px;"><font size="6" face="Calligraph421 BT"><strong>Welcome 
      to <font size="7">Example</font></strong></font></div>
    <h1>&nbsp;</h1>
    <p align="center"><font size="+4"><strong>Contact Us</strong></font></p>
    <hr>
    <div align="right"><font size="-1"><strong><a href="index.html" style="text-decoration = None"><font color="#000000" face="Calligraph421 BT">Return 
      to Home Page</font></a></strong></font></div>
    <blockquote> 
      <blockquote> 
        <blockquote> 
          <p align="center"><font size="+1" face="Calligraph421 BT"><strong>For any 
            enquiries relating to the Village Hall, please either telephone the Bookings 
            Secretary between 08:00 and 20:00 Monday to Friday on 0845-643-0000, or 
            <a href="mailto:bookings.secretary@example.com"><img src="emailbutton.jpg" width="70" height="20" border="0"></a> 
            her with any questions.</strong></font></p>
        </blockquote>
      </blockquote>
    </blockquote>
    <p align="center"><strong><font size="+1" face="Calligraph421 BT">Alternatively, 
      or for other village matters, please complete and submit the short form below, 
      and we will respond as soon as possible</font></strong></p>
    <form action="website_enquiry_process.php" method="post" enctype="multipart/form-data" name="Contactform" id="Contactform">
      <table width="50%" border="1" align="center">
        <tr> 
          <td width="50%" height="64"><div align="center">Full Name:</div></td>
          <td width="50%"><div align="center"> 
              <input name="Name" type="text" id="Name" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="64"><div align="center">Telephone No.</div></td>
          <td width="50%"><div align="center"> 
              <input name="Telephone" type="text" id="Telephone" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="67"><div align="center">Email:</div></td>
          <td width="50%"><div align="center"> 
              <input name="Email" type="text" id="Email" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="56"><div align="center">Nature of your Enquiry ?</div></td>
          <td width="50%"><div align="center"> 
              <select name="Nature" size="1" id="Nature">
    		  <option>Please Select</option>
    <option value="recipient_1">General Enquiries</option>		  
    <option value="recipient_2">Hall Hire</option>
    <option value="recipient_3">Marquee Hire</option>
    <option value="recipient_4">Parish Church</option>
    <option value="recipient_5">Parish Council</option>
    <option value="recipient_6">Recreation Area</option>
    <option value="recipient_7">Other</option>
    </select> 
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="127"><div align="center">Enquiry Details:</div></td>
          <td width="50%"><div align="center"> 
              <textarea name="Questions" cols="40%" rows="4" id="Questions"></textarea>
            </div></td>
        </tr>
        <tr> 
          <td width="50%"><div align="center"> 
              <input name="contactSubmit" type="submit" id="contactSubmit" onClick="MM_validateForm('Name','','R','Telephone','','RisNum','Email','','NisEmail','Questions','','R');return document.MM_returnValue" value="Submit">
            </div></td>
          <td width="50%"><div align="center"> 
              <input name="ContactReset" type="reset" id="ContactReset" value="Reset">
            </div></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p>&nbsp; </p>
      </form>
    <p align="center">&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>


    As you can see, there is very little change between the two html forms, just the bit referring to recipients.

    The amended php code is the code in my first post above.

    Having looked at it again, could it be something to do with the
    PHP Code:
     $my_email $recipients[$_REQUEST['Nature']]; 
    not finding where it should be looking ?

    Regards

    Kim

  7. #7
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    1 - The use of a comment tag in the style section for whatever purpose you are describing is something I have never heard of. I always thought that anything inside a pair of comment tags was just that - a comment not to be interpreted by the browser, and hence, not 'code'. Therefore you have no css code in this page.

    2 - echo out the pieces of your mail call as I suggested earlier and confirm that they are what you expect.

    3 - is error checking turned on for php?

    4 - I notice that you have two different layouts for your Nature select tag. One has value attributes, one does not. What's that?

  8. #8
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    1. Being seriously brand new to this type of thing, I'm afraid I'm not sure how to reply. I cannibalised some code I found on the web to make it fit & do what I needed. When I read through it and tested it, I assumed (probably wrongly) that the html tags were to make the 'thank you' screen a full html page, given that it is a full page message on the original, working version. However, I am more than happy to concede that I don't really know what I am talking about.

    2. will do - as soon as I work out how.

    3. No. Not yet. again, I need to work out how.

    4. I changed the layout to include value attributes i.e 'recipient 1' so that I did not have the email addresses in the html code, but rather have them in the php, as I read that it was bad practice to have email addresses in ones html because it is attractive to spammers.

    I really do appreciate your help ginerjm, and will pick up on this again tomorrow evening as I am out all day.

    Regards

  9. #9
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    1 - the <!-- and the following --> are html comment tags wrapping (in this case) your entire css code for the body of the html page. Remove them and that css will then be functioning. Or just delete the whole style section if you are happy with the current presentation.

    2 - an echo statement simply displays whatever you provide. In this case where you were calling:

    $success = mail($my_email, $emailSubject, $body, $headers);

    I want you to add the following just prior to your call to mail() do this:

    Code:
    echo "my email is $my_email<br>";
    echo "subject is $emailSubject<br>";
    echo "body is $body<br>";
    echo "headers are $headers<br>";

    3 - at the beginning of your php code add these lines (in this script and in EVERY SCRIPT YOU ARE DEVELOPING):

    Code:
    error_reporting(E_ALL | E_NOTICE);  // Kinds of errors to show
    ini_set('display_errors', '1');    // turn on display at the client to display the messages
    4 - My point was that in one place you have absolutely NO VALUES and in the other you DO have values, not that they weren't addresses. I don't care what you use for the value=, but if you don't use anything then what will your select tag return?

  10. #10
    Join Date
    Oct 2013
    Posts
    598
    HTML comment tags (<!-- comment/code -->) were once required inside <script> tags to prevent old browsers from displaying the code on the page. That hasn't been the case in 15 years though. HTML comments were never part of <style> coding. They aren't necessary and are just taking up room in your code. The comment tags for CSS are /* comment here */, so your comment tags aren't working no matter what. Junk -- get rid of them.

    Code:
    font-style: normal; 
    line-height: normal; 
    font-weight: normal;
    You never have to specify "normal". Normal is ... well ... normal -- the default behavior. You should only have to specify something if it is not normal, e.g. font-weight: bold;. Again, this is code that does nothing for you, get rid of it.

    In addition, align="left|center|right" has been deprecated for many years now. Time to update that as well. You already have part of what you need in your CSS -- a specified width.

    All that being stated, here is an updated, cleaned up, and corrected (no <body> tag in your code) version of the HTML "Results" part of your code:
    HTML Code:
    <html> 
    <head> 
    <title>sent message</title> 
    <meta http-equiv="refresh" content="3;URL=http://example.com/index.html"> 
    <style type="text/css">
    body { 
    background-color: #444; 
    font-family: Verdana, Arial, Helvetica, sans-serif; 
    font-size: 20px;
    color: #fec001; 
    padding-top: 200px; 
    width: 800px; 
    margin: auto;
    text-align: center;
    }
    </style> 
    </head> 
    <body>
    <div>Thank you for your enquiry. Your message has been sent and we will respond as soon as possible.</div> 
    </body> 
    </html>

  11. #11
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    Hello Ginerjm & Kevin2.

    Thank you both for your assistance, ginerjm for explaining the echo statement and error reporting, and Kevin2 for the cleaned up 'results' code. I think I follow most if not all. Kevin2 - your identification of my html code being outdated (a bit like me) is spot on. I am using Dreamweaver MX, and it put in a lot of the tags automatically when I designed the form. Not knowing anything much about html or current conventions, I just left them there.

    I have take on board both your suggestions and have amended my code to reflect the suggested changes, but when testing, I get the same http 500 'cant display the webpage' error after I click submit, so cannot even test the errors or echos. I guess there is either something it doesn't like in the code somewhere, or I am testing it incorrectly. I have "put" the html & php code to the website but not linked to any live pages, and opened the test form page by typing in the full address in the top box.

    1. Is this the correct way to test ?
    2. Can either of you (or anyone else) see anything in either the html or php which is clearly a programming error and which would generate the page error I get, as I cannot ?

    Regards & thanks in anticipation.

    Kim

  12. #12
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    Can you post your revised code now?

  13. #13
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    Hi,

    html code is:
    HTML Code:
    <html>
    <head>
    <title>Welcome to Example - Contact Us</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_validateForm() { //v4.0
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" background="goldmold.jpg">
    <div id="Layer1" style="position:absolute; width:207px; height:42px; z-index:3; left: 10px; top: 19px;"><font size="6" face="Calligraph421 BT"><strong>Welcome 
      to <font size="7">Example</font></strong></font></div>
    <h1>&nbsp;</h1>
    <p align="center"><font size="+4"><strong>Contact Us</strong></font></p>
    <hr>
    <div align="right"><font size="-1"><strong><a href="index.html" style="text-decoration = None"><font color="#000000" face="Calligraph421 BT">Return 
      to Home Page</font></a></strong></font></div>
    <blockquote> 
      <blockquote> 
        <blockquote> 
          <p align="center"><font size="+1" face="Calligraph421 BT"><strong>For any 
            enquiries relating to the Village Hall, please either telephone the Bookings 
            Secretary between 08:00 and 20:00 Monday to Friday on 0845-643-0000, or 
            <a href="mailto:bookings.secretary@example.com"><img src="emailbutton.jpg" width="70" height="20" border="0"></a> 
            her with any questions.</strong></font></p>
        </blockquote>
      </blockquote>
    </blockquote>
    <p align="center"><strong><font size="+1" face="Calligraph421 BT">Alternatively, 
      or for other village matters, please complete and submit the short form below, 
      and we will respond as soon as possible</font></strong></p>
    <form action="website_process.php" method="post" enctype="multipart/form-data" name="Contactform" id="Contactform">
      <table width="50%" border="1" align="center">
        <tr> 
          <td width="50%" height="64"><div align="center">Full Name:</div></td>
          <td width="50%"><div align="center"> 
              <input name="Name" type="text" id="Name" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="64"><div align="center">Telephone No.</div></td>
          <td width="50%"><div align="center"> 
              <input name="Telephone" type="text" id="Telephone" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="67"><div align="center">Email:</div></td>
          <td width="50%"><div align="center"> 
              <input name="Email" type="text" id="Email" size="48%">
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="56"><div align="center">Nature of your Enquiry ?</div></td>
          <td width="50%"><div align="center"> 
              <select name="Nature" size="1" id="Nature">
    		    <option>Please Select</option>
    <option value="recipient_1">General Enquiries</option>		  
    <option value="recipient_2">Hall Hire</option>
    <option value="recipient_3">Marquee Hire</option>
    <option value="recipient_4">Parish Church</option>
    <option value="recipient_5">Parish Council</option>
    <option value="recipient_6">Recreation Area</option>
    <option value="recipient_7">Other</option>
    </select> 
    		 <?-- <option>Please Select</option>
    <option value =>General Enquiries</option>		  
    <option>Hall Hire</option>
    <option>Marquee Hire</option>
    <option>Parish Church</option>
    <option>Parish Council</option>
    <option>Recreation Area</option>
    <option>Other</option>
    </select> //-->
    
    
            </div></td>
        </tr>
        <tr> 
          <td width="50%" height="127"><div align="center">Enquiry Details:</div></td>
          <td width="50%"><div align="center"> 
              <textarea name="Questions" cols="40%" rows="4" id="Questions"></textarea>
            </div></td>
        </tr>
        <tr> 
          <td width="50%"><div align="center"> 
              <input name="contactSubmit" type="submit" id="contactSubmit" onClick="MM_validateForm('Name','','R','Telephone','','RisNum','Email','','NisEmail','Questions','','R');return document.MM_returnValue" value="Submit">
            </div></td>
          <td width="50%"><div align="center"> 
              <input name="ContactReset" type="reset" id="ContactReset" value="Reset">
            </div></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p>&nbsp; </p>
      </form>
    <p align="center">&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    </body>
    </html>
    and php is:
    PHP Code:
    <?php

    /* Error Checking */
    error_reporting(E_ALL E_NOTICE);  // Kinds of errors to show
    ini_set('display_errors''1');    // turn on display at the client to display the messages
        
     /* Email Variables */
    $emailSubject 'website_process'
    $recipients = array(

    'recipient_1' => 'kim1@example.co.uk'
    'recipient_2' => 'kim2@example.co.uk'
    'recipient_3' => 'kms3@example.com'
    'recipient_4' 
    => 'kim4@example.net',
    'recipient_5' => 'kim5@example.com',
    'recipient_6' => 'kim6@example.com',
    'recipient_7' => 'enquiries@example.com'

    /*General Enquiries => 'kim1@example.co.uk', 
    Hall Hire => 'kim2@example.co.uk', 
    Marquee Hire => 'kms3@example.com'
    Parish Church => 'kim4@example.net',
    Parish Council => 'kim5@example.com',
    Recreation Area => 'kim6@example.com',
    Other => 'enquiries@example.com'*/
    );
    $my_email $recipients[$_REQUEST['Nature']];

    /* Data Variables */
    $Name $_POST['Name'];
    $Telephone $_POST['Telephone'];
    $Email $_POST['Email'];
    $Nature $_POST['Nature'];
    $Questions $_POST['Questions'];

    /* Email Content*/
    $body = <<<EOD
    <br><hr><br>
    Name: 
    $Name <br>
    Telephone: 
    $Telephone <br>
    Email: 
    $Email <br>
    recipient: 
    $recipient <br>
    Questions: 
    $Questions <br>
    EOD;
    $headers "From: $Email\r\n";
    $headers .= "Content-type: text/html\r\n";
    echo 
    "my email is $my_email<br>";
    echo 
    "subject is $emailSubject<br>";
    echo 
    "body is $body<br>";
    echo 
    "headers are $headers<br>";
    $success mail($my_email$emailSubject$body,
    $headers);

    /* Results HTML */
    $theResults = <<<EOD
    <html> 
    <head> 
    <title>sent message</title> 
    <meta http-equiv="refresh" content="3;URL=http://example.com/index.html"> 
    <style type="text/css">
    body { 
    background-color: #444; 
    font-family: Verdana, Arial, Helvetica, sans-serif; 
    font-size: 20px;
    color: #fec001; 
    padding-top: 200px; 
    width: 800px; 
    margin: auto;
    text-align: center;
    }
    </style> 
    </head> 
    <body>
    <div>Thank you for your enquiry. Your message has been sent and we will respond as soon as possible.</div> 
    </body> 
    </html>
    EOD;
    echo 
    "$theResults";
    ?>
    As you can see from the codes, I have been messing with the recipients part to see if that was the problem, but no joy

    Regards

    Kim

  14. #14
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    Did you write this html? I don't believe so because it is rather comprehensive yet stupid. YOu are using a table for layout yet adding div tags inside td elements to do formatting. Ridiculous!! Really - you should re-do it. Simplify it. Make it modern.

    Looking thru this I see a) html that displays a page and b) php that reads your input from a) and sends an email.

    1 - Don't use $_REQUEST. You know for a fact that you are processing a POST so why are you using the middle-ground that can leave you open to hacking. Never use REQUEST.

    2 - your email is referencing a field $recipient which does not exist.

    3 - you have an error in recipient emails #3

    4 - take out the refresh until you get it all debugged. I did and things are a bit easier to see now.

    So - what is the relation of these two modules? You call up the html file and get a page for input? Then you hit submit and the php module is called to process it? And what exactly happens now? Are you seeing any of your debugging on the screen? YOu have to give me a picture of what you are doing and what you are seeing.
    Last edited by ginerjm; 06-26-2014 at 02:03 PM.

  15. #15
    Join Date
    Jun 2014
    Location
    Somerset, UK
    Posts
    14
    The html was created automatically when I designed the form in Dreamweaver MX, which although old is the only software I have for this sort of thing. From the original form, which worked in sending the form content to my email address, the only thing I tried to change was the recipient part. All of the tags elements validation etc were created by Dreamweaver.

    Yes - What you looked through is what I am trying to achieve, but the email to go to a selected recipient.

    1. Noted.
    2. Oops - my bad. I must have deleted the comma by mistake when amending the code in order to post it here. The comma is there on my development copy.
    3. Will do.


    OK. Action and events.
    I load up my form page, fill in the text boxes for name, telephone, email and comments, click the please select list box and select my required recipient, and hit the submit button.

    Then I get this:

    Info icon
    The website cannot display the page

    HTTP 500

    Most likely causes:
    •The website is under maintenance.
    •The website has a programming error.
    What you can try:
    Refresh the page.
    Go back to the previous page.
    More information More information

    I don't get any debugging, or anything else, just this error screen.

    I will go away and start again with the php and amending the html, and see how far I get.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles