2013-08-29 28 views
0

我目前正在處理的聯繫表格發送到3個電子郵件地址。我希望只有在選擇那不勒斯位置選項時纔會將表格發送到另一個電子郵件地址。其他位置目前不需要單獨的電子郵件地址。我嘗試添加在PHP表單發送到特定的電子郵件選擇選項

switch($_POST['location'])

{ 
case 「naples″: $my_email = ‘[email protected]’; 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 
//[email protected] 
    $to = "[email protected]\r\n"; 
    $from = "[email protected] <[email protected]>"; 
    $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 [email protected] 
    $to = "[email protected]\r\n"; 
    mail($to, $subject, $body, "From: ".$from."\r\n".$headers); 

    $to = "[email protected]\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"); 

?> 
+1

一個switch()來處理一個case?爲什麼不'if($ _POST ['location'] =='那麼'){...}'而不是? –

+0

也許我不明白你的問題,你確定mail()函數適合你嗎?,最好使用SMTP而不是純郵件函數,也可以寫一個函數或類來發送郵件並多次調用它! – Vahid

+0

我是使用php工作的noob。如果您不介意添加更多信息,那麼'if($ _POST ['location'] =='naples'){「[email protected]」}將被放置在代碼中。謝謝 – ac12

回答

0

您應該設置$to變量,而不是$my_email

相關問題