我在联系页面1上有2表格正在运行而另一个表现不正常..这里是第二表格的代码。
联系页面上的我有这个代码
<form action="MailHandler1.php" id="ContactForm" method="post">
<div class="success"> Contact form submitted!<br>
<strong>We will be in touch soon.</strong> </div>
<fieldset>
<div class="wrapper">
<span>Owners First & Last Name</span>
<label class="name">
<span class="bg"><input type="text" id="ownername" class="input"></span>
<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Owners Street Address</span>
<label class="name">
<span class="bg"><input type="text" id="streetaddress" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Owners City</span>
<label class="name">
<span class="bg"><input type="text" id="city" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Owners State</span>
<label class="name">
<span class="bg"><input type="text" id="state" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Owners Zip Code</span>
<label class="name">
<span class="bg"><input type="text" id="zip" class="input"></span>
<span class="error">*This is not a valid name.</span><span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Owners Phone Number</span>
<label class="phone">
<span class="bg"><input type="text" id="ownerphone" class="input"></span>
<span class="error">*This is not a valid phone number.</span> <span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Owners Email</span>
<label class="email">
<span class="bg"><input type="text" id="ownersemails"class="input"></span>
<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Tenants First & Last Name</span>
<label class="name">
<span class="bg"><input type="text" id="tenantname" class="input"></span>
<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Tenants Street Address</span>
<label class="name">
<span class="bg"><input type="text" id="teaddress" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Tenants City</span>
<label class="name">
<span class="bg"><input type="text" id="tecity" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Tenants State</span>
<label class="name">
<span class="bg"><input type="text" id="testate" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Tenants Zip Code</span>
<label class="name">
<span class="bg"><input type="text" id="tezip" class="input"></span>
<span class="error">*This is not a valid name.</span><span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Tenants Country</span>
<label class="name">
<span class="bg"><input type="text" id="tecountry" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Date Lease Started</span>
<label class="name">
<span class="bg"><input type="text" id="tedatestarted" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Monthly Rent Amount</span>
<label class="name">
<span class="bg"><input type="text" id="temonthlyrent" class="input"></span>
<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Rent Amount Due Now</span>
<label class="name">
<span class="bg"><input type="text" id="terentamountduenow" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Late Fees Due Now </span>
<label class="name">
<span class="bg"><input type="text" id="latefeedue" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Date Last Paid</span>
<label class="name">
<span class="bg"><input type="text"id="tedatelastpaid" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Is The Property Gated? Code? </span>
<label class="name">
<span class="bg"><input type="text"id="tegated" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="wrapper">
<span>Any Deposits Collected?</span>
<label class="name">
<span class="bg"><input type="text" id="teanydeposite" class="input"></span>
<span class="empty">*This field is required.</span>
</label>
</div>
<div class="btns">
<a href="#" class="link1" data-type="reset">Clear</a>
<a href="#" class="link11" id="SendNotice" data-type="submit">Send</a>
</div>
</fieldset>
</form>
现在在php上我有这个代码:
<?php
$owner_email = "abc@gmail.com";
$headers = 'From:' . $_POST["ownersemails"];
$subject = 'A message from your site visitor ' . $_POST["ownername"];
$messageBody = "";
if($_POST['ownername']!='nope'){
$messageBody .= '<p> Owners First & Last Name : ' . $_POST["ownername"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['streetaddress']!='nope'){
$messageBody .= '<p> Owners Street Address : ' . $_POST['streetaddress'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['city']!='nope'){
$messageBody .= '<p> Owners City : ' . $_POST['city'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['state']!='nope'){
$messageBody .= '<p> Owners State : ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['zip']!='nope'){
$messageBody .= '<p> Owners Zip Code : ' . $_POST['zip'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['ownerphone']!='nope'){
$messageBody .= '<p> Owners Phone Number : ' . $_POST['ownerphone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['ownersemails']!='nope'){
$messageBody .= '<p> Owners Email : ' . $_POST['ownersemails'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tenantname']!='nope'){
$messageBody .= '<p> Tenants First & Last Name : ' . $_POST['tenantname'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['teaddress']!='nope'){
$messageBody .= '<p> Tenants Street Address : ' . $_POST['teaddress'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tecity']!='nope'){
$messageBody .= '<p> Tenants City : ' . $_POST['tecity'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['testate']!='nope'){
$messageBody .= '<p> Tenants State : ' . $_POST['testate'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tezip']!='nope'){
$messageBody .= '<p> Tenants Zip Code : ' . $_POST['tezip'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tecountry']!='nope'){
$messageBody .= '<p> Tenants Country : ' . $_POST['tecountry'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tedatestarted']!='nope'){
$messageBody .= '<p> Date Lease Started : ' . $_POST['tedatestarted'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['temonthlyrent']!='nope'){
$messageBody .= '<p> Monthly Rent Amount : ' . $_POST['temonthlyrent'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['terentamountduenow']!='nope'){
$messageBody .= '<p> Rent Amount Due Now : ' . $_POST['terentamountduenow'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['latefeedue']!='nope'){
$messageBody .= '<p> Late Fees Due Now : ' . $_POST['latefeedue'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tedatelastpaid']!='nope'){
$messageBody .= '<p> Date Last Paid : ' . $_POST['tedatelastpaid'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['tegated']!='nope'){
$messageBody .= '<p> Is The Property Gated? Code? : ' . $_POST['tegated'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['teanydeposite']!='nope'){
$messageBody .= '<p> Any Deposits Collected? : ' . $_POST['teanydeposite'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
/*
if($_POST['message']!='nope'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}
*/
if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}
try{
/* mail($owner_email, "Subject: $subject", $messageBody, $headerjusts ); */
if(!mail($ownersemails, $ownername, $streetaddress, $city, $state, $zip, $ownerphone, $ownersemails, $tenantname, $teaddress, $tecity, $testate, $tezip, $tecountry, $tedatestarted, $temonthlyrent, $terentamountduenow, $latefeedue, $tedatelastpaid, $tegated, $teanydeposite)){
throw new Exception('mail failed');
}else{
echo 'mail sent';
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
&GT;
有人可以检查并告诉我我在哪里犯了错误......它没有给出任何错误。
答案 0 :(得分:0)
确保验证输入表单数据。将提交更改为提交按钮,然后只提交此表单,并将'id'的密钥更改为'name'。
在MailHandler1.php文件中,更改行“if(isset($ _ POST [”ownerphone“]))”而不是“if($ _ POST ['ownername']!='nope')”。 更改后,您将获得'$ messageBody'变量中的值。