我之前提出过这个问题,但觉得这有点冗长而且不重要。我希望在5个列表中选择一个选择$to =
时向<option value="foo"
添加联系人。我没有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>
答案 0 :(得分:1)
你有这个代码的地方:
$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);
}