Creating Forms


I am a novice web designer on the side. I have always been terrible with forms. At times a client will provide a template they want me to use, which is great but I can never get the forms to work. I have a site now that I need 3 forms. My first question is, is there a site out there where I can create forms for free? If not, how can I go about this? For this particular site the template has a sendemail.php file but when I add my e-mail and test it, it doesn't work. I have that file attached and the form section of the HTML below: I assume with wordpress and other sites so popular a form would be simple to create online for free?

<!--Contact Section-->
    <section class="contact-section no-padd-top">
          <div class="auto-container">
              <div class="row clearfix">
                <!--Form Column-->
                <div class="column form-column col-lg-7 col-md-7 col-sm-6 col-xs-12">
                      <h2>Send Us Message</h2>
                    <!--Default Form-->
                    <div class="default-form style-two">
                          <form method="post" action="sendemail.php" id="contact-form">
                            <div class="row clearfix">
                                <div class="col-md-12 col-sm-12 co-xs-12 form-group">
                                    <input type="text" name="username" value="" placeholder="Full Name">
                                <div class="col-md-12 col-sm-12 co-xs-12 form-group">
                                    <input type="email" name="email" value="" placeholder="Email Address">
                                 <div class="col-md-12 col-sm-12 co-xs-12 form-group">
                                    <input type="text" name="phone" value="" placeholder="Phone">
                                <div class="col-md-12 col-sm-12 co-xs-12 form-group">
                                    <textarea name="message" placeholder="Message"></textarea>
                            <div class="text-left"><button type="submit" class="theme-btn btn-style-one">Send Messgae</button></div>
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EirmanChief Operations ManagerCommented:
I use this dreamweaver addon for complicated multi-question email forms.
It integrates nicely into dreamweaver and is intuitive in use
Dave BaldwinFixer of ProblemsCommented:
There is nothing wrong with that form.  However, for it to work and send email, it must match up with the variables expected by the 'sendemail.php' program.  If it doesn't, there will be an error and no email.

Forms always have two parts.  The HTML form part and the server side script that processes the data.  The variable names have to match for them to work together properly.
WO2015Author Commented:
Thank you, I have filled out the form and hit send. It then goes to my successful page but I never get the e-mail.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Dave BaldwinFixer of ProblemsCommented:
You already said that.  I took your code and tested it and it does exactly what I would expect it to.  

What have you done to make sure the form data and the data expected by the PHP page match up?  Forms do not ever work by themselves.  They do not automatically work.
Julian HansenCommented:
Can you post this file sendemail.php

This is where we should be looking - your form code (as Dave pointed out) is just the bit that captures the data - the sending of the email is done by the above script. We need to make sure the form is sending to the script what the script is expecting to receive.
WO2015Author Commented:
Sorry, I thought it was attached to my first e-mail. Please see below.


// Define some constants
define( "RECIPIENT_NAME", "Peterson & Calunas" );
define( "RECIPIENT_EMAIL", "" );

// Read the form values
$success = false;
$senderName = isset( $_POST['username'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['username'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$phone = isset( $_POST['phone'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['phone'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";

// If all values exist, send the email
if ( $senderName && $senderEmail && $phone && $message) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers = "From: " . $senderName . " <" . $senderEmail . ">";
  $msgBody = " Phone: " . $phone ." Message: " . $message . "";
  $success = mail( $recipient, $headers, $msgBody );

  //Set Location After Successsfull Submission
  header('Location: contact2.html');

      //Set Location After Unsuccesssfull Submission
        header('Location: index.html');      

Julian HansenCommented:
Next question - after submitting do you end up at index.html or contact2.html - this will indicate whether the data you submitted was interpreted as being valid.
WO2015Author Commented:
It goes to my contact2.html which I made for "successful".
Dave BaldwinFixer of ProblemsCommented:
This is wrong:
mail( $recipient, $headers, $msgBody );

Open in new window

Please read the info on this page.  The correct order is:
mail($to, $subject, $message, $headers);

Open in new window

You may also find that your 'headers' are too simple.  Some mail servers will not process emails with incomplete headers.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WO2015Author Commented:
Thank you. I changed it to what you have as the correct order and I get the same result.
Dave BaldwinFixer of ProblemsCommented:
Did you add the $subject variable?  It is required.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.