-1
我從下面創建了此聯繫表單。一切都很好,直到我試圖在電子郵件表單中添加另一節到「body」。第一條消息可以附加到主體,但我無法說明HTML表單中的另一部分可以工作。聯繫表單工作,發送電子郵件,信息丟失
這種形式有什麼問題?感謝您的幫助。
<form method="post" action="emailform.php">
<fieldset>
<ul>
<li>
<label for="name">Your Name:</label>
<input type="text" name="name" id="name"class="large" required="required" placeholder="Enter your name"/></li><!--Basically gave a name here-->
<li>
<label for="idlabel">Your Email:</label>
<input type="email" name="email" placeholder="Enter your email"/></li><!--Basically gave a name here-->
<label for="message2"> <textarea name="message2" maxlength="800" rows="6"
cols="23"></textarea></li></ul>
<li><label for="message">Enter Your Message Below</label>
<textarea name="message" maxlength="800" rows="6"
cols="23"></textarea></li></ul><!--Basically gave a name here and removed label as name-->
<input type="submit" value="Submit"/>
</fieldset>
</form>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Emailing Form Data</title>
<style type="text/css">
body {
font-size: 100%;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<?php
if (empty($_POST)) {
print "<p>No data was submitted.</p>";
print "</body></html>";
exit();
}
/* Creates function that removes magic escaping, if it's been applied, from values and then removes extra newlines and returns to foil spammers. Thanks Larry Ullman! */
function clear_user_input($value) {
if (get_magic_quotes_gpc()) $value=stripslashes($value);
$value= str_replace("\n", '', trim($value));
$value= str_replace("\r", '', $value);
return $value;
}
/* Create body of email message by cleaning each field and then appending each name and value to it. */
$body ="Here is the data that was submitted:\n";
//Fetching the form fields here
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$message2 = $_REQUEST['message2'];
$message = $_REQUEST['message'];
/* Removes newlines and returns from $email and $name so they can't smuggle extra email addresses for spammers */
$email = clear_user_input($email);
$name = clear_user_input($name);
$body .= clear_user_input($message); + clear_user_input($message2); //Appending the message to the body of the email
/* Create header that puts email in From box along with name in parentheses and sends Bcc to alternate address. Change [email protected] to the Bcc email address you want to include. */
$from='From: '. $email . "(" . $name . ")" . "\r\n" . 'Bcc: [email protected]' . "\r\n";
// Creates intelligible subject line that also shows me where it came from
$subject = 'New User Sign Up!';
/* Sends mail to the address below with the form data submitted above. Replace [email protected] with the email address to which you want the data sent. */
mail ('[email protected]', $subject, $body, $from);
?>
<p>Thank you.</p>
</body>
</html>