Jump to content

Basic contact form not working :(


BadlyDrawnGirl

Recommended Posts

I am a real novice when it comes to webdesign and thought I properly reproduced the sample code for a basic "contact us" form, but it's not working for some reason. Can someone please, please give me a hand? We are potentially losing business if I can't get this form up and running.

 

Here is the HTML code:

 <form method="post" action="contact.php" id="contactform">

                    <div>
                    <p>Please complete as many fields as possible. Thank you!</p>
                    </div>

                    <div>
                    <label>Name <span class="required">*</span></label>
                    <input name="name" type="text" id="name" value="" />
                    </div>

                    <div>
                    <label>Email <span class="required">*</span></label>
                    <input name="email" type="text" id="email" value="" />
                    </div>

            <div>
                    <label>Cell phone</label>
                    <input name="cell" type="text" id="cell" value="" />
                    </div>

                <div>
                    <label>Home phone</label>
                    <input name="home" type="text" id="home" value="" />
                    </div>

                    <div>
                    <label>How can we help you? <span class="required">*</span></label>
                    <textarea name="message" rows="20" cols="50"  id="message" ></textarea><br /><br />
                    </div>

                    <div>
                    <input type="submit"  value="Submit" class="button">
                     <input type="reset" value="Reset" class="button">
                    </div>


                </form>

And here is the PHP code:

<?php
if(isset($_POST['submit'])) {
$to = "info@eternityglass.com";
$subject = "Question about Eternity Glass";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$cell_field = $_POST['cell'];
$home_field = $_POST['home'];
$message = $_POST['message'];
 
$body = "From: $name_field\n Email: $email_field\n Cell #: $cell_field\n Home: $Home #: $home_field\n Message:\n $message";
 
echo "Thank you, we will get back to you shortly";
mail($to, $subject, $body);
} else {
echo "Error!";
}
?>

Help!

Link to comment
Share on other sites

Emails can be a little tricky at times to make work consistently.  Start by googling about php email headers, that will help your delivery issue some.  Using phpmailer will also help alot cause it's a php class just for emailing things.  It provides all the correct headers and stuff to help with delivery.

Link to comment
Share on other sites

You need to change this 

 <form method="post" action="contact.php" id="contactform">

                    <div>
                    <p>Please complete as many fields as possible. Thank you!</p>
                    </div>

                    <div>
                    <label>Name <span class="required">*</span></label>
                    <input name="name" type="text" id="name" value="" />
                    </div>

                    <div>
                    <label>Email <span class="required">*</span></label>
                    <input name="email" type="text" id="email" value="" />
                    </div>

            <div>
                    <label>Cell phone</label>
                    <input name="cell" type="text" id="cell" value="" />
                    </div>

                <div>
                    <label>Home phone</label>
                    <input name="home" type="text" id="home" value="" />
                    </div>

                    <div>
                    <label>How can we help you? <span class="required">*</span></label>
                    <textarea name="message" rows="20" cols="50"  id="message" ></textarea><br /><br />
                    </div>

                    <div>
                    <input type="submit"  value="Submit" class="button">
                     <input type="reset" value="Reset" class="button">
                    </div>


                </form>

to this

 <form method="post" action="contact.php" id="contactform">

                    <div>
                    <p>Please complete as many fields as possible. Thank you!</p>
                    </div>

                    <div>
                    <label>Name <span class="required">*</span></label>
                    <input name="name" type="text" value="" />
                    </div>

                    <div>
                    <label>Email <span class="required">*</span></label>
                    <input name="email" type="text" value="" />
                    </div>

            <div>
                    <label>Cell phone</label>
                    <input name="cell" type="text" value="" />
                    </div>

                <div>
                    <label>Home phone</label>
                    <input name="home" type="text" value="" />
                    </div>

                    <div>
                    <label>How can we help you? <span class="required">*</span></label>
                    <textarea name="message" rows="20" cols="50"  id="message" ></textarea><br /><br />
                    </div>

                    <div>
                    <input type="submit"  value="Submit" class="button">
                     <input type="reset" value="Reset" class="button">
                    </div>


                </form>
Link to comment
Share on other sites

Is the php in a seperate file or is it above the html code on the same page

This also has nothing to do with the issue of not getting the emails.  Either the email is getting marked as spam when it leaves the server or because there isn't proper header info the receiving email client is marking it as spam.

 

Have you checked your spam box?

 

One thing you could do to verify the mail function isn't failing is this

if(mail($to, $subject, $body)){
echo "Thank you, we will get back to you shortly";
} else {
echo  'mail not sent';
}
Link to comment
Share on other sites

avoiding junk filters all depends on what is in the header.

 

 

 

 
$headers = 'From: YourLogoName info@domain.com' . "\r\n" ;
$headers .='Reply-To: '. $to . "\r\n" ;
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
 
 
if(mail($to,$subject,$body,$headers)) { echo "mail sent"; } else { echo "mail not sent"; } 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.