0

我目前正在处理的联系表格发送到 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 />&nbsp;<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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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=&#39;&#39;}" onblur="if (this.value == &#39;&#39;) {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>&nbsp;</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 &amp; Leasing"<? if($_POST['services2']=="Rentals &amp; Leasing") { echo " checked"; } ?> /> Rentals &amp; Leasing
</label>
<!-- <label>
<span>&nbsp;</span>           
<input type="checkbox" name="services2" value="Rentals &amp; Leasing"< ? if($_POST['services2']=="Rentals &amp; Leasing") { echo " checked"; } ?> /> Rentals &amp; Leasing
</label> -->
 <label>
<span>&nbsp;</span>           
<input type="checkbox" name="services3" value="Parts"<? if($_POST['services3']=="Parts") { echo " checked"; } ?> /> Parts
<input type="checkbox" name="services4" value="Service &amp; Repair"<? if($_POST['services4']=="Service &amp; Repair") { echo " checked"; } ?> /> Service &amp; Repair
</label>
<!-- <label>
<span>&nbsp;</span>
<input type="checkbox" name="services4" value="Service &amp; Repair"< ? if($_POST['services4']=="Service &amp; Repair") { echo " checked"; } ?> /> Service &amp; Repair
</label> -->
 <label>
<span>&nbsp;</span>           
<input type="checkbox" name="services5" value="Fleet Maintenance Management"<? if($_POST['services5']=="Fleet Maintenance Management") { echo " checked"; } ?> /> Fleet Maintenance Management&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="services6" value="Other"<? if($_POST['services6']=="Other") { echo " checked"; } ?> /> Other
</label>
<!-- <label>
<span>&nbsp;</span>           
<input type="checkbox" name="services6" value="Other"< ? if($_POST['services6']=="Other") { echo " checked"; } ?> /> Other
</label> -->
 <label>
<span>&nbsp;</span> 
          <strong>Message/Comments</strong>
           <br />  
           <textarea cols="80" rows="8" name="details"><? echo $_POST['details']; ?></textarea></label>
  <label>
<span>&nbsp;</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>&nbsp;</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");

?>
4

1 回答 1

0

您应该设置$to变量,而不是$my_email.

于 2013-08-29T16:36:41.447 回答