0

I am creating a website and have just put a form into it. I am using html and css. I want to have to info be entered into the form and then sent to my email. When I put in the code, it either doesn't send the email or a HTTP ERROR 500 comes up. Below is the current code that I have. Is there anything wrong?

Here is the form:

<div class="form">
<form action="index.php" method="post" name="emailform">
<label for='firstname'>First Name:</label><br>
<input type="text" name="firstname"><br>
<label for='lastname'>Last Name:</label><br>
<input type="text" name="lastname"><br>
<label for='phonenumber'>Phone Number:</label><br>
<input type="text" name="phonenumber"><br>
<label for='email'>Email:</label><br>
<input type="email" name="email"><br>
<label for='address'>Street Address:</label><br>
<input type="text" name="address"><br>
<label for='city'>City:</label><br>
<input type="text" name="city"><br>
<label for='state'>State:</label><br>
<input type="text" name="state"><br>
<label for='zipcode'>Zip Code:</label><br>
<input type="text" name="zipcode"><br>
<label for='challenge'>Challenge/Contest Completed:</label><br>
<input type="text" name="challenge"><br>
<label for='prizewon'>Prize Won:</label><br>
<input type="text" name="prizewon"><br>
<label for='nextgoal'>Next Goal:</label><br>
<input type="text" name="nextgoal"><br><br>
<input type="submit" value="Submit">
</form>
</div>

And here is the php:

<?php
$first = $_POST["firstname"];
$last = $_POST["lastname"];
$phone = $_POST["phonenumber"];
$email = $_POST["email"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zipcode"];
$challenge = $_POST["challenge"];
$prize = $_POST["prizewon"];
$goal = $_POST["nextgoal"];

$body = "$first $last"\n
    "$phone"\n
    "$email"\n
    "$address $city $state $zip"\n
    "$challenge"\n
    "$prize"\n
    "$goal"\n;

if($_POST["$body"]) {
    mail("myemail@email.com", "New Form Entry", $_POST["$body"], "From: myemail@email.com");
}
?>

Are there any problems?

Lukas
  • 1
  • This is not correct for sure: `$_POST["$body"]` considering the contents of `$body`. I think you are just wanting `$body` only in the mail function. – Rasclatt Aug 27 '17 at 23:30
  • You also need to put `if(!empty($_POST)) {` at the top before everything, just remove anywhere you have `$_POST["$body"]` that is wrong. – Rasclatt Aug 27 '17 at 23:32

0 Answers0