表单从Option Value添加电子邮件地址


Form add email address from Option Value

我之前问过这个问题,但觉得有点长,没有切中要害。当从5个列表中选择一个选定的<option value="foo"时,我希望将联系人添加到$to =。我对PHP没有什么经验,这是网站上预先存在的表单。我看到的例子描述了为多个电子邮件地址添加一个数组。然而,我只需要在其中一个<option value="foo"上添加一封电子邮件,而不是全部5个选项。我们非常感谢所有的帮助。代码在下面,谢谢。

    <?
ob_start();
if(isset($_POST['registersubmit']))
{
    unset($badcaptcha);
    require_once('/recaptchalib.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@test.com
    $to = "foo@test.com'r'n";
    $from = "test.com <contact@test.com>";
    $subject = "Parts Inquiry test'r'n";
    $body = "Parts Inquiry test'r'n'n";
    //$body .= "Know The Part Number: ".$_POST['ToggleDivs']."'r'n'n";
    if($_POST['ToggleDivs']=="yes")
    { 
    $body .= "Qty: ".$_POST['qty1']." Parts Number: ".$_POST['parts1']."'r'n'n";
    $body .= "Qty: ".$_POST['qty2']." Parts Number: ".$_POST['parts2']."'r'n'n";
    $body .= "Qty: ".$_POST['qty3']." Parts Number: ".$_POST['parts3']."'r'n'n";
    $body .= "Qty: ".$_POST['qty4']." Parts Number: ".$_POST['parts4']."'r'n'n";
    $body .= "Qty: ".$_POST['qty5']." Parts Number: ".$_POST['parts5']."'r'n'n";
    $body .= "Qty: ".$_POST['qty6']." Parts Number: ".$_POST['parts6']."'r'n'n";
    $body .= "Qty: ".$_POST['qty7']." Parts Number: ".$_POST['parts7']."'r'n'n";
    $body .= "Qty: ".$_POST['qty8']." Parts Number: ".$_POST['parts8']."'r'n'n";
    $body .= "Qty: ".$_POST['qty9']." Parts Number: ".$_POST['parts9']."'r'n'n";
    $body .= "Qty: ".$_POST['qty10']." Parts Number: ".$_POST['parts10']."'r'n'n";  
    } 
    else
    {
    $body .= "Make: ".$_POST['Make']."'r'n'n";
    $body .= "Model: ".$_POST['model']."'r'n'n";
    $body .= "VIN: ".$_POST['vin']."'r'n'n";
    $body .= "Category: 'r'n'n";
    $body .= "*".$_POST['category1']."*".$_POST['category2']."*".$_POST['category3']."*".$_POST['category4']."*".$_POST['category5']."*".$_POST['category6']."*".$_POST['category7']."*".$_POST['category8']."*".$_POST['category9']."*".$_POST['category10']."*".$_POST['category11']."*".$_POST['category12']."*".$_POST['category13']."*".$_POST['category14']."*".$_POST['category15']."*".$_POST['category16']."*".$_POST['category17']."'r'n'n";
    $body .= "Describe the part(s) you need: 'r'n'n";
    $body .= "".$_POST['parts_info']."'r'n'n";
    }
    $body .= "'r'n'n";
    $body .= "##############################'r'n'n";
    $body .= "Do you have an account with us? ".$_POST['acct']."'r'n'n";
    if($_POST['acct']=="yes")
    { 
    $body .= "My account number is: ".$_POST['acct_n']."'r'n'n";
    /*$body .= "Do you have an account with us? ".$_POST['acct']."'r'n'n";
    $body .= "If yes, this is the account number: ".$_POST['acct_n']."'r'n'n";*/
    }
    if($_POST['ship_opts']=="Delivery")
    {
        $body .= "Shipping option: ".$_POST['ship_opts']." 'r'n'n";
    }
    else if($_POST['ship_opts']=="Other")
    {
        $body .= "Other shipping option selected: ".$_POST['ship_other']."'r'n'n";
    }
    else 
    {
    $body .= "Will Pick Up at: ".$_POST['ship_opts']." 'r'n'n";
    $body .= "This is the pick up date: ".$_POST['pick_up_date']."'r'n'n";
    //$body .= "Other shipping option selected: ".$_POST['ship_other']."'r'n'n";
    }
    $body .= "'r'n'n";
    $body .= "##############################'r'n'n";
    $body .= "Contact's Information:'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 .= "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  omega@test.com
$to = "omega@test.com'r'n";
    mail($to, $subject, $body, "From: ".$from."'r'n".$headers);
    $to = "alpha@test.com'r'n";
    mail($to, $subject, $body, "From: ".$from."'r'n".$headers);
   $to = "beta@test.com'r'n";
    mail($to, $subject, $body, "From: ".$from."'r'n".$headers);

if ($_POST['ship_opts'] == 'foo') {
    $to = "foo@test.com'r'n";
    mail($to, $subject, $body, "From: ".$from."'r'n".$headers);
}


    header("Location:thankyou_contact2.php");
    }
}
$linkname="parts1";
if(empty($id)) { $id = 23; $showplus = "Y"; }
include("includes/header.php");
?>

下面的HTML;

<div id="pick_up" style="display: none;position:relative;">
<label style="clear:both;"> Do you plan to pick up at one of our locations or have it delivered?<br />
  <select name="ship_opts" id="ship_opts" onchange="Toggle3(this.value);">
    <option value="">Make a Selection</option>
    <option value="PU_C">Pick-Up C</option>
    <option value="PU_D">Pick-Up D</option>
    <option value="Delivery">Delivery</option>
    <option value="foo">Foo</option>
    </select> 
  </label>
</div>

这里有这个代码:

$to = "foo@test.com'r'n";
mail($to, $subject, $body, "From: ".$from."'r'n".$headers);

只需将其更改为:

if ($_POST['ship_opts'] == 'foo') {
    $to = "foo@test.com'r'n";
    mail($to, $subject, $body, "From: ".$from."'r'n".$headers);
}

然后,如果选择了"foo"选项,它将只发送副本。

如果您希望每封电子邮件都被复制到foo@test.com地址,然后更改标题以包含抄送或密件抄送:

if ($_POST['ship_opts'] == 'foo') {
    $headers.= "Cc: foo@test.com'r'n";
    mail($to, $subject, $body, "From: ".$from."'r'n".$headers);
}