I am trying to make a contact form and I believe that the only way is through PHP (so I get an e-mail when my client contacts me.) It is really a very straightforward form, but I am cannot get the form to send me the radio button checked status and have no clue how.
This is my HTML:
<form action="contact.php" method="post">
Your name<br>
<input type="text" name="cf_name" ><br>
<br />
Your e-mail<br>
<input type="text" name="cf_email"><br>
<br />
Do you want to join my mailing list?<br>
<input type="radio" name="mail-list" value="yes">Yes<br>
<input type="radio" name="mail-list" value="no">No<br>
<input type="radio" name="mail-list" value="I_am_already_in_it">I am already in it<br>
<br />
Message<br>
<textarea name="cf_message" rows="10" cols="100">
</textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
And this is my PHP:
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$radio_yes = $_POST ['yes'];
$radio_no = $_POST ['no'];
$radio_I_am_already_in_it = $_POST ['I_am_already_in_it'];
$mail_to = 'my-email@my-site.com';
$subject = 'Hello, I am contacting you from your site. My name is '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$body_message .= 'True: '.$radio_yes;
$body_message .= 'True: '.$radio_no;
$body_message .= 'True: '.$radio_I_am_already_in_it;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you very much. I will do my best to reply to you within 24 hours.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('For some reason your message did not send. Please, do send me an e- mail directly to fernando@fernandoalbertmedium.com');
window.location = 'contact.html';
</script>
<?php
}
?>
The form is working fine, but the radio button status does not show up in the e-mail I receive. Also, for some reason, the cursor does not appear at the beginning of the textarea
, but on the second line with some indent. Do you know why?