获取表单阵列并发送到电子邮件

So I'm still learning PHP, and I've got a form that has 4 arrays. I'm trying to get the arrays sent to my email along with some other information. The email I keep getting says "array, array" (then the rest of the information shows up correctly). I can't figure out what I'm missing.

I can get the parent info to show up correctly, but I'm stuck on getting the Child Information to translate over to email.

if (isset($_POST['submit'])){
    // Parent Info
    $pFname = mysql_escape_string($_POST['pFname']);
    $pLname = mysql_escape_string($_POST['pLname']);
    $email = mysql_escape_string($_POST['pEmail']);
    $street = mysql_escape_string($_POST['street']);
    $city = mysql_escape_string($_POST['city']);
    $state = mysql_escape_string($_POST['state']);
    $zip = mysql_escape_string($_POST['zip']);

    // Child Info
    $name = mysql_escape_string($_POST['Name']);
    $birthday = mysql_escape_string($_POST['Birthday']);
    $gender = mysql_escape_string($_POST['Gender']);
    $rel = mysql_escape_string($_POST['Rel']);

    $msg1 = "From: " . ' ' . $pFname . ' ' . $pLname  . ' ' . ' ' . $pEmail 
    . ' ' . ' ';

    foreach ($_POST['Name'] as $names){
        $name = $names;
    }

    foreach ($_POST['Birthday'] as $birthdays){
        $birthday = $birthdays;
    }

    foreach ($_POST['Gender'] as $genders){
        $gender = $genders;
    }

    foreach ($_POST['Rel'] as $rels) {
        $rel = $rels;
    }

    $msg = "Name: " . " " . $name . " - " . $gender .  "Birthday: " . 
     $birthday . " " . "Relationship: " . $rel . "
";

    $to = 'joe@joe.com;
    $subject = 'Birthday Club Application';
    $msg = $msg . "
";
    $msg .= "First Name: " . $pFname . "
";
    $msg .= "Last Name: " . $pLname . "
";
    $msg .= "Email: " . $email . "
";
    $msg .= "Street: " . $street . "
";
    $msg .= "City: " . $city . "
";
    $msg .= "State: " . $state . "
";
    $msg .= "Zip: " . $zip . "
";

    $headers = 'From: ' . $pEmail . "
";
    $headers1 = 'From: mycompany.com';
    /*$goto_after_mail = "birthdayClub.php";*/

    mail($to, $subject, $msg, $msg1, $headers);

    header("Location: " . $goto_after_mail);
}

And here's the HTML:

<form id="parent-info" method="post" action="<?php echo 
 htmlspecialchars($_SERVER[" PHP_SELF "])?>">

    <h1>Guardian Information</h1>
    <h4>*All fields required*</h4>

    <input type="text" name="pFname" class="parent-entry" placeholder="First Name:" >

    <input type="text" name="pLname" class="parent-entry" placeholder="Last Name:" >

    <input type="text" name="pEmail" class="parent-entry" placeholder="Email:" >

    <input type="text" name="street" class="parent-entry" placeholder="Street Address:" >

    <input type="text" name="city" class="parent-entry" placeholder="City:" >

    <input type="text" name="state" class="parent-entry" placeholder="State:" >

    <input type="text" name="zip" class="parent-entry" placeholder="Zip Code:" >
    <br>

    <h2>Child Information</h2>
    <h4>*All fields required*</h4>

    <div class="child-form">

        <input type="text" name="Name[]" placeholder="Childs Name:" class="parent-entry" value " "; >

        <input type="text" name="Gender[]" placeholder="Gender:" class="parent-entry" value " ";>

        <input type="text" name="Birthday[]" placeholder="Ex: 1/1/01:" class="parent-entry" value " "; >

        <input type="text" name="Rel[]" placeholder="Relation to child:" class="parent-entry" value " ";>

    </div>
 foreach ($_POST['Name'] as $names)

This line suggests that $_POST['Name'] is an array. If that's the case you will have problems with this line:

$name = mysql_escape_string($_POST['Name']);

That function expects a string. When you feed it an array, it will convert it to the string "Array". The same applies to all the child arrays. You're using mysql_escape_string on arrays.

What you want to do instead, since you seem to have an array of children, is to loop through that array and pick up each child's info to add to the email.

Another alternative, if you don't want to loop through all those arrays, is to use the print_r function with its second optional parameter set to true. This will transform the array into a user-readable string.

Change

$name = mysql_escape_string($_POST['Name']);

To:

$name = print_r($_POST['Name'], true);

Live demo