/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=html]<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>
[/code]

And here’s the php I’m using:

[code=php]<!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 = “[email protected]”;

$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” . “rn”;

$headers .= “Content-type:text/html; charset=utf-8” . “rn”;

$headers .= “From: <$email>” . “rn”;

mail($email_to, “Message from Yoga Website”, $text, $headers);

?>

</body>

</html>[/code]

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

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJun 30.2014 — 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
Copy linkTweet thisAlerts:
@DevenDoesJun 30.2014 — 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!
×

Success!

Help @jmandmdesign spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...