This is my first time here and also first time for PHP too. I only have few knowledge about html and zero knowledge about PHP.
I'm trying to set up a website from a free template. Everything is ok except the sending email part in the contact us form.
<form action="send_email.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
The template builder said that I have to create my own send_email.php file and I tried my best to learn about it and this is what I found from google which is a guide of how to create the send_email.php
<?php
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$Name = $_POST['Name'];
$Email = $_POST['Email Address:']; // This is the name= from the form
$Message = $_POST['Write a message:'];
$sendthis="Name ".$Name."// This compiles all info into a single string
Email Address ".$Email."
Write a message: ".$Message."
";
$sendthis = stripslashes($sendthis);
mail("[email protected]","Email sent via www.mywebsite.com",$sendthis,"From: customer");
header("Refresh: 0;url=http://mywebsite.com");
?>
Well, when I tried to test the email. I did got the email, however, there is nothing in it. There is only
Name // This compiles all info into a single string
Email Address
Write a message:
There are no name or anything that I typed in the form.
So, could you please tell me where is the problem of the code? I tried to solve it for hours but nothing works.
Thank you in advance. Now I really have no clue how to fix the problem.
You need to put
name
attributes inside your html :and then you'll get them in your
$_POST
array :As @Dagon said, you can even directly write :
Also just an advice : format correctly your code, especially variable names. It's easier to take good habits when you learn than later :)