我有一个联系表单,只有在完成所有字段后才会提交。我不希望这个,因为许多字段是可选的。我相信它与我的代码的这一部分有关,但我不确定如何更改它并删除它将在页面打开时自动发布表单。
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments']))
对于上下文,这里是代码的其余部分。
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
include_once "/usr/share/pear/Swift/swift_required.php";
// Check if the form has been posted
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments'])) {
// The email address the email will be sent to
$to = 'emailaccount@website.com';
// Set the from address for the email
$from = 'emailaccount@website.com';
$headers = "Reply-To: ".$_POST["email"]."\r\n";
// The email subject
$subject = 'Contact Form Submission';
// Build the body of the email
$mailbody = "The contact form has been filled out.\n\n"
. "first_name: " . $_POST['first_name'] . "\n"
. "last_name: " . $_POST['last_name'] . "\n"
. "address: " . $_POST['address'] . "\n"
. "address_line_2: " . $_POST['address_line_2'] . "\n"
. "city_state_zip: " . $_POST['city_state_zip'] . "\n"
. "phone_number: " . $_POST['phone_number'] . "\n"
. "email_address: " . $_POST['email_address'] . "\n"
. "bedrooms: " . $_POST['bedrooms'] . "\n"
. "baths: " . $_POST['baths'] . "\n"
. "square_feet: " . $_POST['square_feet'] . "\n"
. "basement: " . $_POST['basement'] . "\n"
. "garage: " . $_POST['garage'] . "\n"
. "house_style: " . $_POST['house_style'] . "\n"
. "price_range: " . $_POST['price_range'] . "\n"
. "construction: " . $_POST['construction'] . "\n"
. "heat: " . $_POST['heat'] . "\n"
. "features: " . $_POST['features'] . "\n"
. "comments:\n" . $_POST['comments'];
// Create the mail transport
$transport = Swift_SmtpTransport::newInstance('smtp.domainhere.com', 587);
$transport->setUsername('emailaccount@website.com');
$transport->setPassword('123456');
$swift = Swift_Mailer::newInstance($transport);
// Create the mail
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setTo($to);
$message->setBody($mailbody);
// Send the mail
$result = $swift->send($message);
}
if ($result)
{
header('Location: http://www.domainhere.com/thankyou.html'); }
?>
您的想法将不胜感激。
答案 0 :(得分:0)
这一行:
if (isset($_POST['first_name'], $_POST['last_name'], $_POST['address'], $_POST['address_line_2'], $_POST['city_state_zip'], $_POST['phone_number'], $_POST['email_address'], $_POST['bedrooms'], $_POST['baths'], $_POST['square_feet'], $_POST['basement'], $_POST['garage'], $_POST['house_style'], $_POST['price_range'], $_POST['construction'], $_POST['heat'], $_POST['features'], $_POST['comments']))
要求填写所有内容。