Jump to content

Contact Form HELP!


samtruss1986

Recommended Posts

Hi all, firstly thank you in advance to anyone who replies to this thread. I'll be honest I'm a newbie when I comes to PHP and really am a long way to mastering it. If someone could have a look at my code and tell me where I'm going wrong here then it would be a great help.

 

The problem here is, when I click on the submit button it sends me to the PHP script page and doesn't actually send a email to the address. 

 

Please Help and again, thank you in advance.

 

Below is the HTML,

 

<section>
    <div class="container">
    <div class="row">
      <div class="col-lg-2 col-lg-offset-5">
        <hr class="marginbot-50">
      </div>
    </div>
    <div class="row">
        <div class="col-lg-8">
            <div class="boxed-grey">
                <form data-toggle="validator" role="form" method="post" action="email/contactus.php">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name">
                                Name</label>
                            <input type="text" class="form-control" name="name" id="name" placeholder="Enter name" required="required" />
                        </div>
                        <div class="form-group">
                            <label for="email">
                                Email Address</label>
                                <div class="clearfix"></div>
                            <div class="input-group">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span>
                                </span>
                                <input type="email" class="form-control" name="email" id="email" placeholder="Enter email" required="required" /></div>
                        </div>
                        <div class="form-group">
                            <label for="contact">
                                Who would you like to contact?</label>
                            <select id="contact" name="contact" class="form-control" required="required">
                                <option value="" selected="">Choose One:</option>
                                <option value="Club Chairman">Club Chairman</option>
                                <option value="Sponsorship Secretary">Sponsorship Secretary</option>
                                <option value="Club Captain">Club Captain</option>
                                <option value="Club Website Administrator">Club Website Administrator</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name">
                                Message</label>
                            <textarea name="message" id="message" class="form-control" rows="9" cols="25" required="required"
                                placeholder="Message"></textarea>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <button type="submit" class="btn btn-skin pull-right" id="btnContactUs">
                            Send Your Message</button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    
    <div class="col-lg-4">
      <div class="widget-contact">
        <h5>Write to us</h5>
        
        <address>
          <strong>Abberton & District Cricket Club</strong><br>
          The Brow<br>Abberton Road<br>Colchester<br>Essex<br>CO5 7AW<br>
          <abbr title="Phone"><span class="glyphicon glyphicon-phone-alt"></span></abbr> (01206) 735244
        </address>
 
        <address>
          <strong>Email</strong><br>
          <a href="mailto:#">info@abbertoncricket.co.uk</a>
        </address>  
        <address>
          <strong>We're on social networks</strong><br>
                        <ul class="company-social">
                            <li class="social-facebook"><a href="#" target="_blank"><i class="fa fa-facebook"></i></a></li>
                            <li class="social-twitter"><a href="#" target="_blank"><i class="fa fa-twitter"></i></a></li>
                        </ul> 
        </address>          
      
      </div>  
    </div>
    </div>  
    </div>
</section>
 
The PHP I have is:
 
<?php
 if(isset($_POST['submit']))
 {
   $name = $_POST['name'];
$email = $_POST['email'];
$person = $_POST['contact'];
$about = $_POST['about'];
$query = $_POST['message'];
$email_from = $name.'<'.$email.'>';
 
 $to="info@abbertoncricket.co.uk";
 $subject="Message from abbertoncricket website";
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= "From: ".$email_from."\r\n";
 $message="
    
  Hi, My name is $name.   
         <br>
         I'm looking to contact the <b>$person</b> for your cricket club.
  <br>
  The subject title for my message is $about   
         <br>
         My message is $query 
         <br>
         If you need to contact me further about this matter then please contact me via my email address below
         $email
         <br>
         Thank you.
         $name
      
   ";
if(mail($to,$subject,$message,$headers))
header("Location:../../index.html?msg=Successful Submission! Thankyou for contacting us.");
else
header("Location:../contact.html?msg=Error To send Email !");
 }
?>
 

Again, thankyou for your help.

 

Sam Truss

Link to comment
Share on other sites

Sorry for the wasted thread, I seem to have sorted the problem out by adding

 

" name="submit"  " to my html mark up,

 

Feel free to use the code as it fully works, just please change the email address to the one you want it sent to and not my one!

 

The incorrect HTML

 <button type="submit" class="btn btn-skin pull-right" id="btnContactUs">
                            Send Your Message</button>
The correct HTML
 <button type="submit" name="submit" class="btn btn-skin pull-right" id="btnContactUs">
                            Send Your Message</button>
 
If anyone can still make the code better or stronger then your help would be appreciated!
 
Cheers
 
Samtruss1986
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.