Hi everyone,
I have been recently working on a PHP script that e-mails form data to a specific user. The script works fine, although I have a question. Below is what is e-mailed to me upon completion of the form:
A customer has submitted a New Unit Warranty Registration. The details can be found below.
Array
(
[Customer_Name] => bulio
[E-Mail] => sampleemail@domain.com
[Model] => SB-III SR+
[Serial_Number] => 4564045542
[Engine_Hours] => 4664
[Part_that_Caused_Failure] => Alternator
[Repair_Order] => 533-511
[Cause_of_Claim_Code] => Unknown
[Cause_of_Failure_Code] => Unknown
[Correction_Code] => 5463-354
[Job_Code] => 2883116
[body] => Alternator stopped working.
)
My question is, how do I remove the Array () and the [] which is around the Model etc. fields? I assume I need to use a parser, but I haven't seen any examples of how this would be done. I use print_r to pass the form data on to the email script.
Below is my code:
form.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thermo King New Unit Warranty Registration</title>
</head>
<body>
<h1>Thermo King New Unit Warranty Registration</h1>
<p><strong>Unit Information:</strong></p>
<form action='mail.php' method='post'>
<p>Name:
<input type='text' name='name'>
</p>
<p>E-Mail:
<input type='text' name='email'>
</p>
<p>Model and Type:
<input type='text' name='model'>
<br>
</p>
<p>Serial Number:
<input type='text' name='serialnum'>
<br>
</p>
<p>Engine hours:
<input type='text' name='enginehrs'>
</p>
<p>Part that caused failure:
<input type='text' name='failedpart'>
</p>
<p>Repair order:
<input type='text' name='repairorder'>
</p>
<p>Cause of claim code:
<input type='text' name='causeclaimcode'>
</p>
<p>Cause of failure code:
<input type='text' name='causefailcode'>
</p>
<p>Correction code:
<input type='text' name='correctioncode'>
</p>
<p>Job code:
<input type='text' name='jobcode'>
</p>
<p>
Written detail of cause of failure: <textarea name='body'></textarea><br>
</p>
<p><br>
<input type='submit' value='Submit'>
</p>
</form>
</body>
</html>
mail.php
<?php
$to = "person@domain.com.com";
$subject = "New Unit Warranty Registration";
$message = print_r($_POST, true);
$headers = "From: $email";
$from = "warranty@domain.ca\nX-Mailer: PHP 4.x"
mail($to, $subject, $message, $headers, $from);
echo "Thanks for submitting."
?>