I am writing a contact form for a website and am having trouble getting it to send the fields of my form on the actual e-mail.
The e-mails are sent and received successfully though.
Here is my HTML
<form action="mail.php" method="post" style="font-size:12px;">
<p>Name</p> <input type="text" name="name">
<p>Telephone</p><input type="text" name="phone" size="30" />
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="comments" rows="6" cols="25"></textarea><br />
<p>Best time to Contact You</p><input type="text" size="15" name="time" />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
and my PHP
<?php
$to = "myemailaddress";
$subject = "New Website Enquiry";
$message = "You have recieved a new enquiry";
$from = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['comments, phone, time'];
$headers = "From:" . $from;
$url = 'index.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
mail($to,$subject,$message,$headers);
?>
I found an syntax error in your code:
Change
$message = $_POST['comments, phone, time'];
to
$message = $_POST['comments'] . . $_POST['phone'] . $_POST['time'];
What else do you have a problem with?
You need to learn basic PHP syntax.
$message = $_POST['comments, phone, time'];
is outright wrong. You cannot specify multiply array keys in a comma-separated list like that, let along within a STRING. The code should be more like:
$message = $_POST['comments'] . $_POST['phone'] . $_POST['time'];
Note that what you have is NOT a php-level syntax error. You're using a perfectly acceptable array key, which simply happens to not exist.
<?php
$to = "myemailaddress";
$subject = "New Website Enquiry";
$message = "You have recieved a new enquiry";
$from = $_POST['email'];
$name = $_POST['name'];
$headers = "From:" . $from;
$url = 'index.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0;URL='.$url.'">'; mail($to,$subject,$message,$headers);
?>