1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP Help with PHP contact form code

Discussion in 'Web Development' started by beacon, Apr 13, 2011.

  1. beacon

    beacon New Member

    I purchased a web template which had the following code inserted for a contact page but it didnt not come with a PHP file to support it and I would like to avoid a "mailto" solution. Could someone help me with the PHP code?

    <h2 class="title6">feedback</h2>
    <form id="ContactForm" action="contactformprocess.php">
    <div>
    <label><input name="name"<input type="text" value="Your Name:" class="input" onblur="if(this.value=='') this.value='Your Name:'" onfocus="if(this.value =='Your Name:' ) this.value=''" /></label>
    <label><input type="text" value="Company:" class="input" onblur="if(this.value=='') this.value='Company:'" onfocus="if(this.value =='Company:' ) this.value=''" /></label>
    <label><input type="text" value="E-mail:" class="input" onblur="if(this.value=='') this.value='E-mail:'" onfocus="if(this.value =='E-mail:' ) this.value=''" /></label>
    <div class="textarea">
    <textarea cols="" rows="" onblur="if(this.value=='') this.value='Message:'" onfocus="if(this.value =='Message:' ) this.value=''" >Message:</textarea>
    </div>
    </div>
    <div class="alignright">
    <a href="#" class="link" onclick="document.getElementById('ContactForm').reset()">Clear</a><a href="#" class="link" onclick="document.getElementById('ContactForm').submit()">Send</a>
    </div>
    </form>
    </div>


    The file "contactformprocess.php" does not exist yet....thats why I am here:)

    Thanks in advanced
     
  2. tomw

    tomw Member

    Please give this simple script a try and see if it works for you. Note that the script name is contact.php and also make sure to update the send_to email address.

    Code:
    <?php
       $name    = $_POST ['name'];
       $company = $_POST ['company'];
       $email   = $_POST ['email'];
       $message = $_POST ['message'];
       if(!$name || !$company || !$email || !$message)
       {
           echo "
    <h2>Feedback</h2>
    <form method='post' action='contact.php'>
       Name: <br /><input name='name' type='text' value='$name' /><br /><br />
       Company: <br /><input name='company' type='text' value='$company' /><br /><br />
       EMail: <br /><input name='email' type='text' value='$email' /><br /><br />
       Message:<br />
       <textarea name='message' cols='55' rows='8'>$message</textarea><br /><br />
       <input type='submit' value='Send' />
    </form>
    <p>All fields are required</p>
        ";
           exit;
       }
    $send_to = 'your_email@your_domain.com'; // change to your email
    mail($send_to, "Name: $name Company: $company" , $message, "From: $email");
    echo "Thank you for your feedback";
    ?>
     
  3. beacon

    beacon New Member

    Thanks very much for your assistance, Much appreciated.
     
  4. kulugo04

    kulugo04 New Member

    Hi I have the same problem, I downloaded a template but did not come with a .php. Below is my Form code in my contactus.html. I tried all of the codes in this forum but I couldn't get my CSS to work with the codes I tried. I was wondering if someone can could create a .php to link my below code so I don't have to change my css style file as it is so complicated, it's been four days that I've been trying but I can't make it to work. Thanks in advance.


    Code:
    <form action="#">
     
                    <table>
                        <tr>
                            <td><label for="name"><strong>Name:<strong></label></td>
                            <td><input type="text" maxlength="30" id="name" /> </td>
     
                            <td><label class="email" for="email">Email:</label></td>
     
                            <td><input type="text" maxlength="30" id="email" /></td>
     
                        </tr>
                        <tr>
                            <td><label for="subject"><strong>Subject:</strong></label></td>
     
                            <td><input type="text" maxlength="30" id="subject" /></td>
     
                        </tr>
                        <tr>
                            <td class="message"><label for="message"><strong>Message:</strong></label></td>
                            <td colspan="3"><textarea name="message" id="message" cols="30" rows="10"></textarea></td>
                        </tr>
                        <tr>
                            <td>
                            <td>
                            <td><td colspan="1"><input type="submit" value="" id="send" /></td>
                        </tr>
                    </table>
                </form>
     
  5. tomw

    tomw Member

    Hello and welcome to FWT.

    Your code should be something like this:
    Code:
    <?php
      $name    = $_POST ['name'];
      $subject = $_POST ['subject'];
      $email  = $_POST ['email'];
      $message = $_POST ['message'];
      if(!$name || !$subject || !$email || !$message)
      {
          echo"
    <form method='post' action='[SIZE=15px][FONT=Georgia][COLOR=#141414]contactus.php[/COLOR][/FONT][/SIZE]'>
      <table>
          <tr>
        <td><label for='name'><strong>Name:<strong></label></td>
            <td><input type='text' maxlength='30' id='name' value='$name' /> </td>
            <td><label class='email' for='email'>Email:</label></td>
            <td><input type='text' maxlength='30' id='email' value='$email' /></td>
          </tr>
          <tr>
        <td><label for='subject'><strong>Subject:</strong></label></td>
        <td><input type='text' maxlength='30' id='subject' value='$subject' /></td>
          </tr>
          <tr>
        <td class='message'><label for='message'><strong>Message:</strong></label></td>
        <td colspan='3'><textarea name='message' id='message' cols='30' rows='10'>$message</textarea></td>
          </tr>
          <tr>
        <td>
            <td>
              <td><td colspan='1'><input type='submit' value='Send' id='send' /></td>
          </tr>
      </table>
    </form>";
          exit;
      }
      $send_to = 'your_email@your_domain.com'; // change to your email
      mail($send_to, "Name: $name Company: $company" , $message, "From: $email");
      echo "Thank you for contacting us! We will response to you soon.";
    ?>
    Now rename contactus.html to contactus.php and save it.

    Hope this helps. Let us know if you run into any problems.
     
  6. kulugo04

    kulugo04 New Member

    Hi tomw,

    Thanks for your quick response. I was able to add the code above changing below line. I tried it with a document named contactsample.php just to test, but still could not receive any email, I changed "$send_to =" to my email address but did not get any emails back. Am I still missing something? Below is the actual contactsample.php link. Again thank you for your help.

    http://homefairies.com/contactsample.php

    Code:
    <form method='post' action='[SIZE=15px][FONT=Georgia][COLOR=#141414]contactus.php[/COLOR][/FONT][/SIZE]'>
    Code:
    <form method='post' action='contactsample.php'>
     
  7. tomw

    tomw Member

    I made a mistake of copying all your codes. There were some errors I've overlooked. Copy the codes below and your page should work now:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8" />
      <title>Contact Us - Home Fairies LLC</title>
      <link rel="stylesheet" type="text/css" href="http://homefairies.com/css/style.css" />
      <!--[if IE 9]>
      <link rel="stylesheet" type="text/css" href="http://homefairies.com/css/ie9.css" />
      <![endif]-->
      <!--[if IE 8]>
      <link rel="stylesheet" type="text/css" href="http://homefairies.com/css/ie8.css" />
      <![endif]-->
      <!--[if IE 7]>
      <link rel="stylesheet" type="text/css" href="http://homefairies.com/css/ie7.css" />
      <![endif]-->
    </head>
     
    <body>
    <div id="header">
      <div>
          <div id="logo">
        <a href="index.html"><img src="http://homefairies.com/images/homefairieslogo.jpg" alt="Logo" /></a>
          </div>
          <div id="navigation">
        <div>
            <ul>
              <li><a href="#">Home</a></li>
              <li><a href="#">Services</a></li>
              <li><a href="#">FAQs</a></li>
              <li><a href="#">Testimonials</a></li>
              <li><a href="#">Employment</a></li>
              <li class="current"><a href="contactus.php">Contact Us</a></li>
            </ul>
        </div>
          </div>
      </div>
    </div>
    <div id="content">
      <div>
          <h3><center>Call us now for a free, no-obligation consultation</center></h3>
          <center>
        <h2>
            <p>Telephone. : <span>(510) 363-8118</span>
              <br>Fax : <span>(510) 372-0421</span>
              <br>Email : <span><a
              href="mailto:inquiries@homefairies.com?subject=Inquiry"
              title="mailto:inquiries@homefairies.com?subject=Inquiry">inquiries@homefairies.com
              </a></span>
            </p>
        </h2>
          </center>
          <h2 class="title6">Contact Us</h2>
    <?php
      $name    = $_POST ['name'];
      $subject = $_POST ['subject'];
      $email  = $_POST ['email'];
      $message = $_POST ['message'];
      if(!$name || !$subject || !$email || !$message)
      {
          echo"<p>Make sure all the fields below are filled out!</p>
    <form method='post' action='contactus.php'>
      <table>
          <tr>
        <td><label for='name'><strong>Name:<strong></label></td>
            <td><input type='text' maxlength='30' name='name' value='$name' /> </td>
            <td><label class='email' for='email'>Email:</label></td>
            <td><input type='text' maxlength='30' name='email' value='$email' /></td>
          </tr>
          <tr>
        <td><label for='subject'><strong>Subject:</strong></label></td>
        <td><input type='text' maxlength='30' name='subject' value='$subject' /></td>
          </tr>
          <tr>
        <td class='message'><label for='message'><strong>Message:</strong></label></td>
        <td colspan='3'><textarea name='message' name='message' cols='30' rows='10'>$message</textarea></td>
          </tr>
          <tr>
        <td>
            <td>
              <td><td colspan='1'><input type='submit' value='Send' id='send' /></td>
          </tr>
      </table>
    </form>";
          exit;
      }
      $send_to = 'name@your_domain.org'; // change to your email
      mail($send_to, "Name: $name Company: $company" , $message, "From: $email");
      echo "Thank you for contacting us! We will response to you soon.";
    ?>
    </body>
    </html>
    I tested it and it works.
     
  8. tomw

    tomw Member

    Just copy the codes from <?php ... to ?> and replace those in your page.

    Sorry for the confusion.
     
  9. kulugo04

    kulugo04 New Member

    Sweet Thanks tomw! It works, I can now receive messages, but there is a minor aesthetic problem that I could not figure out.

    1. The input box for the Name, Email, Subject is white in color.
    2. The Send radio icon has another "Send".

    http://homefairies.com/contactus.php

    Sorry for all the troubles, rookie here.
     
  10. tomw

    tomw Member

    Ok, one more time:
    Code:
    <?php
      $name    = $_POST ['name'];
      $subject = $_POST ['subject'];
      $email  = $_POST ['email'];
      $message = $_POST ['message'];
      if(!$name || !$subject || !$email || !$message)
      {
          echo"<p>Make sure all the fields below are filled out!</p>
    <form method='post' action='contactus.php'>
      <table>
          <tr>
        <td><label for='name'><strong>Name:<strong></label></td>
            <td><input type='text' maxlength='30' name='name' value='$name' id='name' /> </td>
            <td><label class='email' for='email'>Email:</label></td>
            <td><input type='text' maxlength='30' name='email' value='$email' id='email' /></td>
          </tr>
          <tr>
        <td><label for='subject'><strong>Subject:</strong></label></td>
        <td><input type='text' maxlength='30' name='subject' value='$subject' id='subject' /></td>
          </tr>
          <tr>
        <td class='message'><label for='message'><strong>Message:</strong></label></td>
        <td colspan='3'><textarea name='message' name='message' cols='30' rows='10'>$message</textarea></td>
          </tr>
          <tr>
        <td>
            <td>
              <td><td colspan='1'><input type='submit' value='' id='send' /></td>
          </tr>
      </table>
    </form>";
          exit;
      }
      $send_to = 'name@yourdomain.com'; // change to your email
      mail($send_to, "Name: $name Company: $company" , $message, "From: $email");
      echo "Thank you for contacting us! We will response to you soon.";
    ?>
    Hopefully this will be the last time ;)

    Don't feel sorry. We all were rookies at one time.
     
  11. kulugo04

    kulugo04 New Member

    tomw thank you so much it works perfect!

    I don't know how you did it but it's great! Thanks again :) one happy camper here!
     
  12. Matta

    Matta New Member

    Hi tomw...... i have the same situation as the previous 2 posters you managed to help, i´m completely stumped as to how to activate my contact form from the template i also downloaded, spent the last days lost in tutorials to no avail, perhaps if its not too much trouble, could you generate a php script for me aswell? i would be eternally grateful......


    </div>​
    <h2>Contact Form</h2>​
    <form id="ContactForm">​
    <div>​
    <div class="wrapper">​
    <span>Full Name:</span>​
    <input type="text" class="input" >​
    </div>​
    <div class="wrapper">​
    <span>E-mail:</span>​
    <input type="text" class="input" >​
    </div>​
    <div class="textarea_box">​
    <span>Message:</span>​
    <textarea name="textarea" cols="1" rows="1"></textarea>​
    </div>​
    <div class="wrapper">​
    <span>&nbsp;</span>​
    <a href="#" class="button1" onClick="document.getElementById('ContactForm').reset()"><span></span><strong>Clear</strong></a>​
    <a href="#" class="button1" onClick="document.getElementById('ContactForm').submit()"><span></span><strong>Send</strong></a>​
    </div>​
    </div>​
    </form>​
     
  13. tomw

    tomw Member

    Hi Matta, welcome to FWT.

    Can you let us know which template you downloaded?

    Take a look at this tutorial. It shows you everything you need to know about creating a contact form or mailer.
     
  14. hiba

    hiba New Member

    hi,,

    i have the same problem + a problem on how to receive back the multiple options from a list... will be thankful if someone helped me on it and correct mistakes if there are any..
    thaaaamx alot

    here is the code :

    <form id="contact-form" method="post" action="appoitment.php">
    <fieldset>


    <label for="name">
    <input name="name" type="text" id="name" size="35" value="Your Name" onfocus="if(this.value=='Your Name'){this.value=''}" onblur="if(this.value==''){this.value='Your Name'}" maxlength="90"></label>


    <label for="phone">
    <input type="text" name="phone" id="phone"
    size="15" value="Telephone" onfocus="if(this.value=='Telephone'){this.value=''}" onblur="if(this.value==''){this.value='Telephone'}" maxlength="15">
    </label>

    <label for="email">
    <input type="email" name="email" id="email" value="Email" onfocus="if(this.value=='Email'){this.value=''}" onblur="if(this.value==''){this.value='Email'}" maxlength="50">
    </label>




    <label for="datepicker">
    <input type="text" id="datepicker" value="Date" onfocus="if(this.value=='Date'){this.value=''}" onblur="if(this.value==''){this.value='Date'}" maxlength="10">
    </label>



    <label for="time">Best times:</label>
    <div class="errorGroup">
    <div class="fieldPair">
    <div class="fieldGroup">
    <span id="Times_Spry">
    <span class="selectRequiredMsg">Please select a time </span>
    <select name="time[]" size="1" multiple="multiple" class="formListfield" id="time" tabindex="8">
    <option value="09:00 AM">09:00 AM</option>
    <option value="10:00 AM">10:00 AM</option>
    <option value="11:00 AM">11:00 AM</option>
    <option value="12:00 PM">12:00 PM</option>
    <option value="04:00 PM">04:00 PM</option>
    <option value="05:00 PM">05:00 PM</option>
    <option value="06:00 PM">06:00 PM</option>
    <option value="07:00 PM">07:00 PM</option>
    <option value="08:00 PM">08:00 PM</option>
    </select>
    </span> </div>
    </div>
    </div>

    <div class="btns">
    <a class="button" onClick="document.getElementById('contact-form').reset()">Clear</a>
    <a class="button" onClick= "document.getElementById('contact-form').submit()">Send</a>
    </div>
    </fieldset>
    </form>
     
  15. pambati9

    pambati9 New Member

    i want contact.php file
     
  16. Krockett14

    Krockett14 New Member

    hey good afternoon and thank for having helpful forum but it seems like i keep walking into a brick wall.
    i recently downloaded the Thom Sander Photography Portfolio HTML5/CSS Template
    http://www.html5xcss3.com/2012/05/html5-template-thom-sander.html

    and im trying to get the Contact form to work but i created the Contact.php file in dreamwaver with this in it:
    PHP:
    <?php
      $name    
    $_POST ['name'];
      
    $email  $_POST ['email'];
      
    $message $_POST ['message'];
      if(!
    $name || !$email || !$message)
      {
          echo 
    "
    <h2>Feedback</h2>
    <form method='post' action='contact.php'>
      Name: <br /><input name='name' type='text' value='
    $name' /><br /><br />
      EMail: <br /><input name='email' type='text' value='
    $email' /><br /><br />
      Message:<br />
      <textarea name='message' cols='55' rows='8'>
    $message</textarea><br /><br />
      <input type='submit' value='Send' />
    </form>
    <p>All fields are required</p>
        "
    ;
          exit;
      }
    $send_to 'sean@anstey.com';
    mail($send_to"Name: $name Company: $company$message"From: $email");
    echo 
    "Thank you for your feedback";
    ?>
    and this is in my Source code

    Code:
                                            <h2>Contact Form</h2>
                                            <form id="ContactForm" action="contact.php">
                                                <div>
                                                    <div  class="wrapper">
                                                        <span>Full Name:</span>
                                                        <input type="text" class="input" >
                                                    </div>
                                                    <div  class="wrapper">
                                                        <span>E-mail:</span>
                                                        <input type="text" class="input" >
                                                    </div>
                                                    <div  class="textarea_box">
                                                        <span>Message:</span>
                                                        <textarea name="textarea" cols="1" rows="1"></textarea>
                                                    </div>
                                                    <div class="wrapper">
                                                        <span>&nbsp;</span>
                                                        <a href="#" class="button1" onClick="document.getElementById('ContactForm').reset()"><span></span><strong>Clear</strong></a>
                                                        <a href="#" class="button1" onClick="document.getElementById('ContactForm').submit()"><span></span><strong>Send</strong></a>
                                                    </div>
                                                </div>
                                            </form>
    and when i test the form out it just takes me to another page where the Contact.php code is visible on the browser page.
    i know im doing something wrong but don't know what exactly.
    im sorry to have to make you repeat yourself over and over again. i hope i have come across a different kind of problem to change from your habbits.
    i hope the information i have given you is enough.

    Cheers,
     
  17. Krockett14

    Krockett14 New Member

    small bump still not getting anywhere unfortunately
     
  18. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    take a screen shot of what shows in the browser and post it up.
     
  19. Krockett14

    Krockett14 New Member

    actually i changed a few things and now when i click submit it takes me to another page with another Contact form :S so i think i should start from scratch and forget the .php file and work from the first code i posted to build a .php around that because i would really like to keep to original contact form style in place.
     
  20. Krockett14

    Krockett14 New Member

    thanks for helping me by the way :)