Results 1 to 2 of 2

Thread: [RESOLVED] Email Form

  1. #1

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Resolved [RESOLVED] Email Form

    Hi all,

    Just wondering if someone could guide me on the following:

    I have a Contact Us form on my web page;

    Code:
    <form action="" id="form" style="margin:0; padding:0 ">
    														<table cellpadding="0" cellspacing="0" border="0">
    															<tr>
    																<td valign="top" width="403" height="24">
    																<div style=" margin-left:13px; margin-top:0px "><img src="images/6_w1.gif" alt="" border="0"></div>
    																 
    																</td>
    															</tr>
    															<tr>
    																<td valign="top" width="403" height="127">
    																	<table cellpadding="0" cellspacing="0" border="0">
    																		<tr>
    																			<td valign="top" width="120" height="127">
    																				<div style=" margin-left:32px; margin-top:12px "><a href="#"><img src="images/6_p1.jpg" alt="" border="0"></a></div>
    																			</td>
    																			<td valign="top" width="130" height="127">
    																				<div  style=" margin-left:5px; margin-top:9px; margin-right:0px; line-height:13px " class="b"><span class="green">The Company Name Inc.</span><br>
    9863 - 9867 Mill Road, <br>
    Cambridge, MG09 99HT</div>
    <div  style=" margin-left:5px; margin-top:5px; margin-right:0px; line-height:13px " class="b">Tel:&nbsp;&nbsp;+44 989 998 92 90
    Fax: +44 989 998 92 90</div>
    <div  style=" margin-left:5px; margin-top:5px; margin-right:0px; line-height:13px " class="b">Tel:&nbsp;&nbsp;+44 369 369 36 69
    Fax: +44 369 369 36 69</div>
    																			</td>
    																			<td valign="top" width="153" height="127">
    																				<div  style=" margin-left:9px; margin-top:9px; margin-right:0px; line-height:13px " class="b"><strong>Customer Center:</strong></div>
    <div  style=" margin-left:9px; margin-top:5px; margin-right:0px; line-height:13px " class="b">Phone: +44 369 369 36 69<br>
    
    E-mail: <a href="#" class="green">[email protected]</a></div>
    <div  style=" margin-left:9px; margin-top:9px; margin-right:0px; line-height:13px " class="b"><strong>User Guide:</strong></div>
    <div  style=" margin-left:9px; margin-top:5px; margin-right:0px; line-height:13px " class="b">Phone: +44 369 369 36 69<br>
    
    E-mail: <a href="#" class="green">[email protected]</a></div>
    																			</td>
    																		</tr>
    																	</table>
    																</td>
    															</tr>
    															
    															<tr>
    																<td valign="top" width="403" height="24">
    																	<div style=" margin-left:13px; margin-top:0px "><img src="images/6_w3.gif" alt="" border="0"></div>
    																 
    																</td>
    															</tr>
    															<tr>
    																<td valign="top" width="403" height="61">
    																	<table cellpadding="0" cellspacing="0" border="0">
    																		<tr>
    																			<td valign="top" width="208" height="61">
    																				<div style="margin-left:32px; margin-top:7px;" class="t3"><input type="text"  class="b" style=" width:164px; height:20px " value="&nbsp;Your name: " ></div>
    																				<div style="margin-left:32px; margin-top:5px;" class="t3"><input type="text"  class="b" style=" width:164px; height:20px " value="&nbsp;Phone: " ></div>
    																			</td>
    																			<td valign="top" width="195" height="61">
    																				<div style="margin-left:0px; margin-top:7px;" class="t3"><input type="text"  class="b" style=" width:164px; height:20px " value="&nbsp;Company name: " ></div>
    																				<div style="margin-left:0px; margin-top:5px;" class="t3"><input type="text"  class="b" style=" width:164px; height:20px " value="&nbsp;E-mail: " ></div>
    																			</td>
    																		</tr>
    																	</table>
    																</td>
    															</tr>
    															<tr>
    																<td valign="top" width="403" height="121">
    																	<div style="margin-left:32px; margin-top:0px;" class="t3"><textarea  cols="35" rows="35" style=" width:340px; height:90px;  overflow:hidden " class="b">&nbsp;Message:</textarea></div>
    																	 <div style="margin-left:233px; margin-top:5px; " class="b"><img alt="" style="margin-right:9px; margin-left:0px " src="images/1_z1.gif" border="0"><a href="#" class="b" onClick="document.getElementById('form').reset()"><strong>reset</strong></a><img alt="" style="margin-right:9px; margin-left:40px " src="images/1_z1.gif" border="0"><a href="#" class="b" onClick="document.getElementById('form').reset()"><strong>submit</strong></a></div>
    																				  
    																</td>
    															</tr>
    														</table>
    														</form>
    Now I was just wondering if someone could guide me on how I could make this a live form using embedded PHP?

    Many thanks

    Olly

  2. #2

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Email Form

    Done it and here is how:

    Let's say one of your pages has a code as follows:

    Code:
    <form>
                      <table width="456" border="0" cellpadding="0" cellspacing="0" bgcolor="F7F5F2">
                        <tr>
                          <td height="60"><img src="images/tit_18.gif" width="405" height="23" style="margin-left:24px "></td>
                        </tr>
                        <tr>
                          <td height="28" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="124" align="right" class="text_1">Your name:</td>
                              <td width="26"><img src="images/spacer.gif" width="1" height="1"></td>
                              <td><input name="textfield2" type="text" class="form_1"></td>
                            </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td height="28" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="124" align="right" class="text_1">E-mail address:</td>
                              <td width="26"><img src="images/spacer.gif" width="1" height="1"></td>
                              <td><input name="textfield22" type="text" class="form_1"></td>
                            </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td height="91" valign="top"><table width="456" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="124" align="right" valign="top" class="text_1" style="padding-top:3px ">Message:</td>
                              <td width="26"><img src="images/spacer.gif" width="1" height="1"></td>
                              <td><textarea name="textarea" class="form_2"></textarea></td>
                            </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td valign="top"><input type="image" src="images/reset.gif" style="margin-left:338px "><input type="image" src="images/submit.gif" style="margin-left:29px "></td>
                        </tr>
                      </table><!-- -->
    </form>

    The layout of the contact form can look like this:

    (see attachment)


    A general layout of HTML contact form

    On your server you should have a script that will actually generate and send e-mails to a certain e-mail address. A sample of this script is below. It’s a PHP script which is supported on most hosting servers.
    Our html form has two tags: opening <form> and closing </form>. The opening tag is empty. For the form to pass data to our contact.php we need to specify two attributes within this tag:

    PHP Code:
    <form action="contact.php" method="get"

    The form we are working with has two text input fields and one textarea. Each of them should have an attribute called “ name”. The original contact form already has them: name="textfield2", name="textfield22", name="textarea"
    Let’s rename the values of these attributes to more meaning names:


    PHP Code:
    name="your_name"name="your_email"name="message" 

    The same names are used in the sample of contact.php :


    PHP Code:
    $_GET['your_name'] , $_GET['your_email'] and  $_GET['message'

    It’s very important to have the same names of variables we pass from an .html page and get in contact.php.
    The next step is to make the two buttons Reset and Submit work. In our case these buttons are presented by images: <input type="image"… But they can be also presented by HTML buttons specially designed for this case: <input type="reset"… and <input type="submit"… And the third way is to use common text links for this case.

    First let’s take the image buttons. In order to make the Reset button function we need to insert additional attribute onClick into the <input> tag with the following code:


    PHP Code:
    onClick="reset(); return false;" 


    The reset() function is javascript function that clears the form and return false disables the image button’s default action – passing data to server:


    Code:
    <input type="image" src="images/reset.gif" style="margin-left:338px" onClick="reset(); return false;">

    For the Submit button we simply add the same onClick attribute but with the submit() javascript function as its value:


    Code:
    <input type="image" src="images/submit.gif" style="margin-left:29px;" onClick="submit();">


    Actually that’s all. The last thing to do is to insert your real e-mail address in the contact.php script instead of “ [email protected]
    If you want to use HTML buttons <input type="reset"… and <input type="submit"… you don’t need to insert any additional onClick attributes. These buttons will do what they are supposed to do without extra code:


    Code:
    <input type="reset"> <input type="submit">


    If you want to use text links to clear and submit your form use a code like this:

    Code:
    <a href="javascript:contact_form.reset();">Reset</a> <a href="javascript:contact_form.submit();">Submit</a>

    For this code to work with our form we need to specify the name=”contact_form” attribute for the <form> tag:


    Code:
    <form name="contact_form" action="contact.php" method="get">
    Here is the above mentioned PHP code:

    PHP Code:
    <?
    $subject="from ".$_GET['your_name'];
    $headers= "From: ".$_GET['your_email']."\n";
     $headers.='Content-type: text/html; charset=iso-8859-1';
    mail("[email protected]", $subject,  "
    <html>
    <head>
     <title>Contact letter</title>
    </head>
    <body>

    <br>
      ".$_GET['message']."
    </body>
    </html>" , $headers);
    echo ("Your message was successfully sent!");
    ?>
    <script>
        resizeTo(300, 300)
        //window.close()
    </script>
    Attached Images Attached Images  

Posting Permissions

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



Click Here to Expand Forum to Full Width