0

I'm making a simple form using HTML, CSS and PHP.

Currently the form sends an email to the identified recipient but does not contain any information from the form, just the headers identified in the $formcontent.

HTML

<form method ="post" action="index.php">      
    <input name="name" type="text" class="feedback-input" placeholder="Name" />   
    <input name="email" type="text" class="feedback-input" placeholder="Email" />
    <textarea name="message" class="feedback-input" placeholder="message"></textarea>
    <input id="submit" name="submit" type="submit" value="SUBMIT"/>
</form>

CSS

form { max-width:455px; margin-right:45px; margin-top:10px; float: right; display: inline; }

.feedback-input {
  color:white;
  font-family: Helvetica, Arial, sans-serif;
  font-weight:500;
  font-size: 18px;
  border-radius: 5px;
  line-height: 22px;
  background-color: transparent;
  border:2px solid #CC6666;
  transition: all 0.3s;
  padding: 13px;
  margin-bottom: 15px;
  width:100%;
  box-sizing: border-box;
  outline:0;
}

.feedback-input:focus { border:2px solid #CC4949; }

textarea {
  height: 60px;
  line-height: 60%;
  resize:vertical;
}

[type="submit"] {
  font-family: 'Montserrat', Arial, Helvetica, sans-serif;
  width: 100%;
  background:#CC6666;
  border-radius:5px;
  border:0;
  cursor:pointer;
  color:white;
  font-size:24px;
  padding-top:10px;
  padding-bottom:10px;
  transition: all 0.3s;
  margin-top:-4px;
  font-weight:700;
}
[type="submit"]:hover { background:#CC4949; }

PHP

<?php
$name = $_post['name'];
$email = $_post['email'];
$message = $_post['message'];
$formcontent = "From: $name \n Message: $message";
$recipient = 'info@beardmore.cc';
$subject = 'Beardmore.cc contact form';
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>
Matt Mills
  • 8,692
  • 6
  • 40
  • 64
stee1e
  • 27
  • 5

1 Answers1

1

As Albzi noted in their comment, In PHP the case is important, you need to edit your code to have $_POST instead of $_post:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \n Message: $message";
$recipient = 'info@beardmore.cc';
$subject = 'Beardmore.cc contact form';
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>

You should also sanitize your variables, in this state your code is unprotected against malicious users. Additionnaly, check if they are set with the isset function.

Community
  • 1
  • 1
Veve
  • 6,643
  • 5
  • 39
  • 58
  • ok that's cool. I din't know that. The name now works but it doesn't send the message. I've checked all my spelling. What else am I missing. Thanks for the help – stee1e Oct 15 '15 at 15:59
  • I suggest you to make another question with this problem, and validate this answer if it helped you ;) For your second problem, try to test your `mail`function alone in another PHP file, to see if you're able to send email. Then, add the code missing. @stee1e – Veve Oct 15 '15 at 16:01