所以我仍然在學習PHP,並且我有一個有4個數組的表單。我試圖將數組發送到我的電子郵件以及其他一些信息。我收到的電子郵件說「數組,陣列」(然後剩下的信息正確顯示)。我無法弄清楚我錯過了什麼。獲取表單數組併發送到電子郵件
我可以得到正確顯示的父級信息,但我堅持要將子級信息轉換爲電子郵件。
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 . "\n\r";
$to = '[email protected];
$subject = 'Birthday Club Application';
$msg = $msg . "\r\n";
$msg .= "First Name: " . $pFname . "\r\n";
$msg .= "Last Name: " . $pLname . "\r\n";
$msg .= "Email: " . $email . "\r\n";
$msg .= "Street: " . $street . "\r\n";
$msg .= "City: " . $city . "\r\n";
$msg .= "State: " . $state . "\r\n";
$msg .= "Zip: " . $zip . "\r\n";
$headers = 'From: ' . $pEmail . "\r\n";
$headers1 = 'From: mycompany.com';
/*$goto_after_mail = "birthdayClub.php";*/
mail($to, $subject, $msg, $msg1, $headers);
header("Location: " . $goto_after_mail);
}
而這裏的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>
你應該有上線的閉合撇號,上面寫着'$到=「[email protected];'' – Alesana
mysql_escape_string' __escapes string__'$ _POST ['Name']'__not a string__我甚至不知道你爲什麼使用這個函數。 –
準備說同樣的事情@u_mulder – GrumpyCrouton