form not posting to php mail
Ive got a form where users report posts
<form method="post" action="sendmail.php" name="Email form">
Message ID <input type="text" name="message id" /><br/><br/>
Aggressive conduct <input type="ra开发者_如何学运维dio" name="option1" value="aggressive contact" /><br/><br/>
Offensive conduct <input type="radio" name="option2" value="offensive conduct" /><br/><br/>
Rasical conduct <input type="radio" name="option3" value="Rasical conduct" /><br/><br/>
Intimidating conduct <input type="radio" name="option4" value="intimidating conduct" /><br/><br/>
<input type="submit" name="submit" value="Send Mail" />
</form>
And then it fires a php mail function which send the report to me
<?php
$to = 'root@localhost';
$subject = 'Report';
$message = 'message id\option1\option2\option3\option4';
$headers = 'From: postmaster@localhost' . "\r\n" .
'Reply-To: postmaster@localhost' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I want it to take the values inputted by users in the form and mail them to me. As it stands its DOES send a mail but it just say in the mail
message id\option1\option2\option3\option4
Now i understand this is what i put in for '$message' but as this is what i called the input in the form i thought this is what it would take! What am i missing to do this?
The php mail function IS working so this is not the problem. Im sure im just missing some code to get it working.
You need to make all your radio buttons the same name (this assumes you only want one to be checked at a time), otherwise use checkboxes with different names. Use $_POST to get the data from the form.
$message = "message {$_POST['id']}\{$_POST['option']}";
Message ID <input type="text" name="message id" /><br/><br/>
the name attribute here is incorrect and will need to be renamed to "message_id" instead.
Your radio buttons should have the same name (eg. "conduct") and then change
$message = 'message id\option1\option2\option3\option4';
to something like this:
$message = "message id: $_POST[message_id]\conduct $_POST[conduct]";
You need to check $_POST-vars in order to get the data that was POSTed.
So, e.g. instead of just putting "message id" in your mail, you need to do something like $_POST['message id'] . '\' . $_POST['option1']...
Read this:
http://php.net/manual/de/reserved.variables.post.php
other hints: I wouldn't use a space in a name ("message id") and if you really want to use radiobuttons that interact (form a group), they need to have the same name
精彩评论