私はhtml形式で.phpフォーム処理を作成しました。ほとんどのデータは送信されますが、コメントセクションは送信されませんが、htmlの部分は提供されますが、コメントは提供されません。私はそれがセクションのタイトルを与えるが、コメントではない電子メールで私は得る。phpフォーム処理中コメントデータを送信しない
任意の提案ですか?ここで
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>PHP form to email sample form</title>
<!-- define some style elements-->
<style>
label,a
{
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
}
</style>
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js"type="text/javascript"></script>
</head>
<body>
<!-- Start code for the form-->
<form method="post" name="myemailform" action="form-to-email2.php">
<input name="first_name" type="text" tabindex="1" required id="First" placeholder="First Name" title="First and Last Name" size="50"></p>
<p><input name="last_name" type="text" tabindex="2" required id="Last Name" placeholder="Last Name" title="Last Name" size="50"></p>
<p><input name="date" type="text" tabindex="3" required id="Date" placeholder="Date" title="Date" size="50">
</p>
<p><input name="email" type="email" tabindex="4" required id="Email" placeholder="Email" size="50"></p>
<p><input name="day_phone" type="tel" tabindex="5" required id="Day Phone" placeholder="Day Phone" title="Day Phone" size="50"></p>
<p><input name="evening_phone" type="tel" tabindex="5" required id="Evening Phone" placeholder="Evening Day Phone" title="Evening Day Phone" size="50"></p>
<h5>Property:
<select name="property" size="1" tabindex="6" required id="Property" placeholder="Property" title="Property">
<option value="Gan Aden, 441 Ash St. Willimantic">Gan Aden, 441 Ash St. Willimantic</option>
<option value="Gan Aden Too, 306 Ash St. Willimantic">Gan Aden Too, 306 Ash St. Willimantic</option>
<option value="Gan Aden South, 300 Windham Road, Willimantic">Gan Aden South, 300 Windham Road, Willimantic</option>
<option value="Gan Aden of Colchester, 385 South Main, Colchester">Gan Aden of Colchester, 385 South Main, Colchester</option>
<option value="Gan Aden Too of Colchester, Dogwood, Maple Lane, Colchester">Gan Aden Too of Colchester, Dogwood, Maple Lane, Colchester</option>
<option value="Gan Aden at Chestnut, 28 Chestnut Hill Rd, Colchester">Gan Aden at Chestnut, 28 Chestnut Hill Rd, Colchester</option>
<option value="Gan Aden Fields, 564 Norwich Ave, Colchester">Gan Aden Fields, 564 Norwich Ave, Colchester</option>
<option value="Stone Ridge Estates, 12 Dr. Manning Dr.,Lebanon">Stone Ridge Estates, 12 Dr. Manning Dr.,Lebanon</option>
<option value="Indian Ridge , 404 East Main, Jewett City">Indian Ridge , 404 East Main, Jewett City</option>
<option value="Mary Brown, 112 Brown Ave. Jewett City">Mary Brown, 112 Brown Ave. Jewett City</option>
<option value="Shady Lane, Cathcart Lane, Jewett City">Shady Lane, Cathcart Lane, Jewett City</option>
<option value="Pear Tree, 34 Brown Ave, Jewett City">Pear Tree, 34 Brown Ave, Jewett City</option>
<option value="Pleasant House, 260 Pleasant St. Willimantic">Pleasant House, 260 Pleasant St. Willimantic</option>
<option value="Village Heights, 55 Renee Drive, Colchester">Village Heights, 55 Renee Drive, Colchester</option>
<option value="Other Residence">Other Residence</option>
<option value="Commercial">Commercial</option>
</select></h5>
<p><input name="unit" type="text" tabindex="7" required id="Unit" placeholder="Unit" title="Unit" size="50">
</p>
<p><textarea name="comments" tabindex="8" cols="50" rows="10" maxlength="150" form="maintenancefrom2" placeholder="Maintenance Problem"></textarea></p>
<input type="submit" name='submit' value="submit">
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("myemailform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
</body>
は.phpのある
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['first_name'];
$name = $_POST['last_name'];
$name = $_POST['date'];
$visitor_email = $_POST['email'];
$name = $_POST['day_phone'];
$name = $_POST['evening_phone'];
$name = $_POST['property'];
$name = $_POST['unit'];
$message = $_POST['comments'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = '[email protected]';//<== update the email address
$email_subject = "Maintenance Form submission";
$email_body .= "Maintenance Form";
$email_body .= "First Name: " .$_POST['first_name'];
$email_body .= "Last Name: " .$_POST['last_name'];
$email_body .= "Date: " .$_POST['date'];
$email_body .= "Email: ".$_POST['email'];
$email_body .= "Day Phone: " .$_POST['day_phone'];
$email_body .= "Evening Phone: " .$_POST['evening_phone'];
$email_body .= "Property: ".$_POST['property'];
$email_body .= "Unit: ".$_POST['unit'];
$email_body .= "Maintenance Problem: ".$_POST['comments'];
$to = "[email protected]";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: confirmation.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
ここにフォームのマークアップを投稿してください。 –
変数を使用しない場合は、すべてのPOST配列値を変数にキャストするのはなぜですか? –
電子メールに手作りのフィルタを使用するのではなく、['filter_var()'](http://php.net/manual/en/function.filter-var.php)を使用してください。 –