Jump to content

Help With Contact PHP


Recommended Posts

I am really new to creating websites I am trying to create one for a friend.  I attached zip file of site. I used generic photos I will replace soon.  My issue is in the Contact Form when I hit submit button it does not work.  I wanted it to redirect to contact_me.php which is located in mail file.  The structure I am using is for a free form I downloaded.  Thanks everyone for all your help in advance.  I just cannot make the connection occur between the the button and php to work properly ugh!!  I also would really appreciate any directions and comments.  The blog section is not done yet.   

Sweetshoppe.zip

Link to comment
https://forums.phpfreaks.com/topic/297300-help-with-contact-php/
Share on other sites

I hope this is what you meant by relevant code.  Thanks Everyone For all your help and assistance.

 

Contact Form Code Below

 

<div class="container">

        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <p>Want to get in touch with me? Fill out the form below to send me a message and I will try to get back to you within 24 hours!</p>
                <!-- Contact Form - Enter your email address on line 19 of the mail/contact_me.php file to make this form work. -->
                <!-- WARNING: Some web hosts do not allow emails to be sent through forms to common mail hosts like Gmail or Yahoo. It's recommended that you use a private domain email address! -->
                <!-- NOTE: To use the contact form, your site must be on a live web host with PHP! The form will not work locally! -->
                <form name="sentMessage" id="contactForm" novalidate>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Name</label>
                            <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Email Address</label>
                            <input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Phone Number</label>
                            <input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number.">
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <div class="row control-group">
                        <div class="form-group col-xs-12 floating-label-form-group controls">
                            <label>Message</label>
                            <textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
                            <p class="help-block text-danger"></p>
                        </div>
                    </div>
                    <br>
                    <div id="success"></div>
                    <div class="row">
                        <div class="form-group col-xs-12">
                            <a href="index.html">
                            <button type="submit" class="btn btn-default">Send</button>
                        </a>                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
 
 
 
Contact_Me.PHP for form Below (I removed Email Address)
 
<?php
// Check for empty fields
if(empty($_POST['name'])   ||
   empty($_POST['email']) ||
   empty($_POST['phone']) ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
echo "No arguments Provided!";
return false;
   }
 
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
 
// Create the email and send the message
$to = 'MyEmailGoesHere.com'; // Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected].
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
 
 
 
 

You didn't tell your form to use POST.

<form method="POST" name="sentMessage" id="contactForm" novalidate>
Unless your form HTML is on the same script (Contact_Me.PHP), you also need to put an action.

<form method="POST" action="Contact_Me.php" name="sentMessage" id="contactForm" novalidate>
Also, saying return false; in the middle of a script does nothing. Everything underneath that is still going to execute.

Thinking about the problem some more, I have a feeling that there is some JavaScript attached to the form that's adding the action and method attributes for you. Did you make any changes to the open <form> tag after downloading script?

 

When you submit the form, where does it go? Does it go back to the page where your form code is hosted? Or does it go to contact_me.php in the mail folder?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.