Reputation: 467
I have created my page and have incorporated a form. I believe I have set everything up correctly, however when I receive the email, none of the input data is shown?
jsFiddle attached: https://jsfiddle.net/ebw2d9s5/1/
phpcode:
<?php
if(isset($_POST['submit']))
{
echo "Error: You need to Submit the Form!";
}
$to = "[email protected]"; // this is your Email address
$headers = "From:" . $from ;
$name = $_POST['name'];
$from = $_POST['email']; // this is the sender's Email address
$phone = $_POST['phone'];
$address = $_POST['address'];
$message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$subject = "DKS Online Quote Form";
$subject2 = "DKS Electrical and Data";
$response = "Mail Sent. Thank you " . $name . " for contacting us, we will be in contact with you shortly.";
mail($to,$subject,$message,$headers);
mail($from,$subject2,$response);
header('Location: ../index.php');
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
?>
Here is the test site: http://www.hosting-mate.com/dkselectricalanddata/
EDIT - This is all that shows up in my emails: http://www.hosting-mate.com/dkselectricalanddata/_assets/img.png
Thanks in advance! - Jesse
Upvotes: 1
Views: 153
Reputation: 467
After trying many different things to figure out why my data never came up in my emails, I realized that it was actually the HTML file that was not sending the data properly.
For anyone else that may run into this issue with a data form, dont use:
enctype:"text/plain"
Instead, use:
enctype:"multipart/form-data"
This will stop your emails from appearing with just the headings and no input data.
Thank you for everyone that tried helping with this problem.
Upvotes: 1
Reputation: 473
Try This...
<?php
if(isset($_POST['submit']))
{
$to = "[email protected]"; // this is your Email address
$headers = "From:" . $from ;
$name = $_POST['name'];
$from = $_POST['email']; // this is the sender's Email address
$phone = $_POST['phone'];
$address = $_POST['address'];
$message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$subject = "DKS Online Quote Form";
$subject2 = "DKS Electrical and Data";
$response = "Mail Sent. Thank you " . $name . " for contacting us, we will be in contact with you shortly.";
mail($to,$subject,$message,$headers);
mail($from,$subject2,$response);
header('Location: ../index.php');
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
}else {
echo "Error: You need to Submit the Form!";
}
?>
Change this in your HTML Code :
<input type="submit" class="button" id="Button2" value="SEND" style="position:absolute;left:0%;top:640px;width:100%;height:80px;font-family:font_header;font-size:27px;z-index:20">
to
<input type="submit" class="button" name="submit" id="Button2" value="SEND" style="position:absolute;left:0%;top:640px;width:100%;height:80px;font-family:font_header;font-size:27px;z-index:20">
Upvotes: 0