www.webdeveloper.com
Results 1 to 3 of 3

Thread: Very Basic PHP Contact Form Issues

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    Very Basic PHP Contact Form Issues

    Hey everyone,

    I'm using a free template for a site I have set up. This template didn't come with any php or any code at all to make the contact form work. I've been trying to make it work with a VERY BASIC php submit file I have from an old site.

    However, it's been years since I've worked with php and I'm sure many things have changed as well as the fact that I'm working from the ground up with this html because it didn't come with a matching php form of it's own.

    Here's the html for the contact section:

    HTML Code:
    <article id="main">
    <div id="contact"></div>
    				<header class="special container">
    					<span class="icon fa-comments-o"></span>
    					<h2>Send me a Message</h2>
    					<p>Use the form below if you have any questions, or you just want to get in touch!</p>
    				</header>
    					
    				<!-- One -->
    					<section class="wrapper style4 special container small">
    					
    						<!-- Content -->
    							<div class="content">
    								<form>
    									<div class="row half no-collapse-1">
    										<div class="6u">
    											<input type="text" name="name" placeholder="Name" />
    										</div>
    										<div class="6u">
    											<input type="text" name="email" placeholder="Email" />
    										</div>
    									</div>
    									<div class="row half">
    										<div class="12u">
    											<input type="text" name="subject" placeholder="Subject" />
    										</div>
    									</div>
    									<div class="row half">
    										<div class="12u">
    											<textarea name="message" placeholder="Message" rows="7"></textarea>
    										</div>
    									</div>
    									<div class="row">
    										<div class="12u">
    											<ul class="buttons">
    												<li><a href="/send.php" class="button special">Send Message</a></li>
    											</ul>
    										</div>
    									</div>
    								</form>
    							</div>
    							
    					</section>
    				
    			</article>
    And here's the php I'm using:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    <?php

    $email_to 
    "yogawjess@gmail.com";

    $name $_POST["name"];

    $email $_POST["email"];

    $subject $_POST["subject"];

    $message $_POST["message"];

    $text "Name: $name<br>

             Email: 
    $email<br>

             Subject: 
    $subject<br>         

             Message: 
    $message";

    $headers "MIME-Version: 1.0" "\r\n"

    $headers .= "Content-type:text/html; charset=utf-8" "\r\n"

    $headers .= "From: <$email>" "\r\n";

    mail($email_to"Message from Yoga Website"$text$headers);

    ?>

    </body>

    </html>
    The form will submit, but the email I receive doesn't contain any of the inputted info, just the labels from the php form. Also, I would like the form to redirect to the homepage after submission.

    I would really appreciate any help, it's been so long since I worked on this stuff that I've totally forgotten everything!!

    Thanks,
    -Jess

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    562
    Are your html skills that rusty?

    Your form tag has no attributes, such as Method= or action= which will trigger the correct script to be run upon submission as well as the correct Array to use to retrieve data. By default the method will be GET,meaning that you need to either change it to POST or alter all of your php code to reference the $_GET array
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Jun 2014
    Location
    North Carolina, USA
    Posts
    8
    Your form tag should be like this.

    <form action="phppagehere.php" method="POST">

    This is how your php code gets all of its information to send to you. I hope this helps, if not let me know!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles