Hi all, I need help. I've designed a contact form with html and php but I get "array" instead of the selected check box option when I receive an email from the site.
Html code:
<!DOCTYPE html>
<html>
<head>
<form action="request_quote.php" method="post">
Your name<br>
<input name="name" type="text" size="40"><br>
Contact number<br>
<input name="contact_number" type="text" size="40"><br>
Email<br>
<input name="email" type="text" size="40"><br><br>
Please select desired insurance below:<br>
<input name="insurance_type[]" type="checkbox" value="Commercial lines" /> Commercial lines<br>
<input name="insurance_type[]" type="checkbox" value="Personal lines" /> Personal lines<br>
<input name="insurance_type[]" type="checkbox" value="Life insurance" /> Life insurance<br>
<input name="insurance_type[]" type="Checkbox" value="Specialised services"/> Specialised services<br>
<br>Additional details<br>
<textarea name="message" cols="40"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
</body>
</html>
PHP code:
<?php
$field_name = $_POST['name'];
$field_contact_number = $_POST['contact_number'];
$field_insurance_type = $_POST['insurance_type'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = '[email protected]';
$subject = 'Request for quotation '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'Contact number: '.$field_contact_number."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Insurance type: '.$field_insurance_type."\n";
$body_message .= 'Message: '.$field_message;
$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 for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to [email protected]');
window.location = 'contact-us.html.html';
</script>
<?php
}
?>
Please assist!
Html code:
<!DOCTYPE html>
<html>
<head>
<form action="request_quote.php" method="post">
Your name<br>
<input name="name" type="text" size="40"><br>
Contact number<br>
<input name="contact_number" type="text" size="40"><br>
Email<br>
<input name="email" type="text" size="40"><br><br>
Please select desired insurance below:<br>
<input name="insurance_type[]" type="checkbox" value="Commercial lines" /> Commercial lines<br>
<input name="insurance_type[]" type="checkbox" value="Personal lines" /> Personal lines<br>
<input name="insurance_type[]" type="checkbox" value="Life insurance" /> Life insurance<br>
<input name="insurance_type[]" type="Checkbox" value="Specialised services"/> Specialised services<br>
<br>Additional details<br>
<textarea name="message" cols="40"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>
</body>
</html>
PHP code:
<?php
$field_name = $_POST['name'];
$field_contact_number = $_POST['contact_number'];
$field_insurance_type = $_POST['insurance_type'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = '[email protected]';
$subject = 'Request for quotation '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'Contact number: '.$field_contact_number."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Insurance type: '.$field_insurance_type."\n";
$body_message .= 'Message: '.$field_message;
$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 for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to [email protected]');
window.location = 'contact-us.html.html';
</script>
<?php
}
?>
Please assist!