我目前正在处理的联系表单发送到3个电子邮件地址。我希望仅在选择那不勒斯位置选项时才将表单发送到另一个电子邮件地址。其他位置目前不需要单独的电子邮件地址。我试过加入
switch($_POST['location'])
{
case “naples″: $my_email = ‘naples@email.com’; break;
}
我认为这有效但在提交时没有发送电子邮件,我无法区分错误。是否可以在选择时允许一个位置选项将另一个电子邮件地址添加到原始3个收件人?谢谢你们提前下载的代码。
<?
ob_start();
if(isset($_POST['registersubmit']))
{
unset($badcaptcha);
require_once('captcha.php');
$privatekey = "....";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);
if (!$resp->is_valid)
{
$badcaptcha=true;
}
else
{
//Send email
//foo@alpha.com
$to = "foo@alpha.com\r\n";
$from = "foo@alpha.com <foo@alpha.com>";
$subject = "Contact Foo\r\n";
$body = "Contact Foo\r\n\n";
$body .= "Full Name: ".$_POST['Fname']."\r\n\n";
$body .= "Business Name: ".$_POST['Bname']."\r\n\n";
$body .= "Email: ".$_POST['email']."\r\n\n";
$body .= "Address: ".$_POST['address']."\r\n\n";
$body .= "City: ".$_POST['city']."\r\n\n";
$body .= "State: ".$_POST['state']."\r\n\n";
$body .= "Zip Code: ".$_POST['zipcode']."\r\n\n";
$body .= "Phone: ".$_POST['phone']."\r\n\n";
$body .= "Location: ".$_POST['location']."\r\n\n";
$body .= "Interests: \r\n\n";
$body .= "*".$_POST['services1']."*".$_POST['services2']."*".$_POST['services3']."*".$_POST['services4']."*".$_POST['services5']."*".$_POST['services6']."*".$_POST['services7']."*".$_POST['services8']."*".$_POST['services9']."\r\n\n";
$body .= "Comments/Message: ".$_POST['details']."\r\n\n";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
mail($to, $subject, $body, "From: ".$from."\r\n".$headers);
//Send copy beta@foo.com
$to = "beta@foo.com\r\n";
mail($to, $subject, $body, "From: ".$from."\r\n".$headers);
$to = "tom@foo.com\r\n";
mail($to, $subject, $body, "From: ".$from."\r\n".$headers);
header("Location:thankyou_contact2.php");
}
}
$linkname="contact";
if(empty($id)) { $id = 10; $showplus = "Y"; }
include("includes/header.php");
?>
<div id="main"><table width="621" cellspacing="0" cellpadding="0">
<h1>CONTACT US</h1>
<br />
Use Our Online Form (below) or Contact Your Nearest Location
<?
if(isset($badcaptcha))
{
?>
<b><font color="red">INCORRECT SECURITY CODE, PLEASE TRY AGAIN</font></b><br /> <br />
<?
}
?>
<br />
<br />
<div id="contact_form"> <!--onsubmit="return validate2()" -->
<form method="post" name="contact_form" onsubmit="return validate3()" >
<label>
<span>Full Name<font color="#FF0000">*</font></span>
<input size="31" name="Fname" value="<? if(!empty($_POST['Fname'])) { echo $_POST['Fname']; } else { echo "Full Name"; } ?>" class="input-text" maxlength="100" OnFocus="if (this.value == 'Full Name') {this.value=''}" onblur="if (this.value == '') {this.value='Full Name'}"/>
</label>
<label>
<span>Business Name<font color="#FF0000">*</font></span>
<input size="31" name="Bname" value="<? if(!empty($_POST['Bname'])) { echo $_POST['Bname']; } else { echo "Business Name"; } ?>" class="input-text" maxlength="100" OnFocus="if (this.value == 'Business Name') {this.value=''}" onblur="if (this.value == '') {this.value='Business Name'}"/>
</label>
<label>
<span>Email Address<font color="#FF0000">*</font></span>
<input size="31" name="email" value="<? if(!empty($_POST['email'])) { echo $_POST['email']; } else { echo "Email Address"; } ?>" class="input-text" maxlength="100" onfocus="if (this.value == 'Email Address') {this.value=''}" onblur="if (this.value == '') {this.value='Email Address'}" />
</label>
<label>
<span>Address</span>
<input size="31" name="address" value="<? if(!empty($_POST['address'])) { echo $_POST['address']; } else { echo "Address"; } ?>" class="input-text" maxlength="100" OnFocus="if (this.value == 'Address') {this.value=''}" onblur="if (this.value == '') {this.value='Address'}" />
</label>
<label>
<span>City</span>
<input size="31" name="city" value="<? if(!empty($_POST['city'])) { echo $_POST['city']; } else { echo "City"; } ?>" class="input-text" maxlength="100" OnFocus="if (this.value == 'City') {this.value=''}" onblur="if (this.value == '') {this.value='City'}" />
</label>
<label> <span>State</span><select name="state" id="state">
<option value="State">State</option>
<option value="AK">Alaska</option>
<option value="AL">Alabama</option>
</select> </label>
<label>
<span>Zip Code</span>
<input size="31" name="zipcode" value="<? if(!empty($_POST['zipcode'])) { echo $_POST['zipcode']; } else { echo "Zip Code"; } ?>" class="input-text" maxlength="10" OnFocus="if (this.value == 'Zip Code') {this.value=''}" onblur="if (this.value == '') {this.value='Zip Code'}" />
</label>
<label>
<span>Phone<font color="#FF0000">*</font></span>
<input size="31" name="phone" value="<? if(!empty($_POST['phone'])) { echo $_POST['phone']; } else { echo "Phone"; } ?>" class="input-text" maxlength="30" OnFocus="if (this.value == 'Phone') {this.value=''}" onblur="if (this.value == '') {this.value='Phone'}" />
</label>
<label> <span>Location<font color="#FF0000">*</font></span> <select name="location" id="location">
<option value="location">Nearest Location</option>
<option value="Naples">Naples</option>
<option value="Cherokee">Cherokee</option>
</select> </label>
<label>
<span> </span>
<strong>Interests</strong> <br />
<input type="checkbox" name="services1" value="Trucks Sales"<? if($_POST['services1']=="Trucks Sales") { echo " checked"; } ?> /> Trucks Sales
<input type="checkbox" name="services2" value="Rentals & Leasing"<? if($_POST['services2']=="Rentals & Leasing") { echo " checked"; } ?> /> Rentals & Leasing
</label>
<!-- <label>
<span> </span>
<input type="checkbox" name="services2" value="Rentals & Leasing"< ? if($_POST['services2']=="Rentals & Leasing") { echo " checked"; } ?> /> Rentals & Leasing
</label> -->
<label>
<span> </span>
<input type="checkbox" name="services3" value="Parts"<? if($_POST['services3']=="Parts") { echo " checked"; } ?> /> Parts
<input type="checkbox" name="services4" value="Service & Repair"<? if($_POST['services4']=="Service & Repair") { echo " checked"; } ?> /> Service & Repair
</label>
<!-- <label>
<span> </span>
<input type="checkbox" name="services4" value="Service & Repair"< ? if($_POST['services4']=="Service & Repair") { echo " checked"; } ?> /> Service & Repair
</label> -->
<label>
<span> </span>
<input type="checkbox" name="services5" value="Fleet Maintenance Management"<? if($_POST['services5']=="Fleet Maintenance Management") { echo " checked"; } ?> /> Fleet Maintenance Management
<input type="checkbox" name="services6" value="Other"<? if($_POST['services6']=="Other") { echo " checked"; } ?> /> Other
</label>
<!-- <label>
<span> </span>
<input type="checkbox" name="services6" value="Other"< ? if($_POST['services6']=="Other") { echo " checked"; } ?> /> Other
</label> -->
<label>
<span> </span>
<strong>Message/Comments</strong>
<br />
<textarea cols="80" rows="8" name="details"><? echo $_POST['details']; ?></textarea></label>
<label>
<span> </span>
<script type="text/javascript">
var RecaptchaOptions = { theme : 'clean' };
</script>
<?php
require_once('captch.php');
$publickey = "..."; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</label>
<label>
<span> </span>
<input type="submit" name="registersubmit" value="Submit" /></label>
</form></div>
<? includecontent($id); ?>
</td>
<!-- new --></tr>
</table>
</td>
</tr>
<tr>
<td width="581" align="right" valign="top" colspan="2"><img src="pictures/spacer.gif" border="0" width="10" height="10"></td>
</tr>
</table>
</td>
</tr>
</table><br />
<img src="pictures/spacer.gif" border="0" width="3" height="3" /></td>
</tr>
</table>
</div><!-- main -->
</div><!-- content -->
<?
include("includes/footer.php");
?>
答案 0 :(得分:0)
您应该设置$to
变量,而不是$my_email
。