如果选中按钮,则发送另一封电子邮件

时间:2013-04-23 19:40:40

标签: php email radio-button

这是我在网站上为表单提供的PHP代码。 “我们可以向您发送有关我们餐厅特殊活动和场合的信息吗?”是表单上的是或否单选按钮。

当表单用户选中“是”按钮时,我希望将其他电子邮件发送给其他人。

如果他们检查不是或留空,我希望电子邮件只能转到主电子邮件地址,而不是其他人。我已经摆弄了好几天,代码完全逃脱了我,我能得到的任何帮助都会非常感激。

<?php
if($_POST){

$p = $_POST["mailer"];
$body = "Email: ".$p['Email']."\n";
$body .= "First Name: ".$p['FirstName']."\n";
$body .= "Last Name: ".$p['LastName']."\n";
$body .= "Address: ".$p['Address']."\n";
$body .= "City: ".$p['City']."\n";
$body .= "State: ".$p['State']."\n";
$body .= "Zip: ".$p['Zip']."\n";
$body .= "Telephone: ".$p['Telephone']."\n";
$body .= "Date/Time: ".$p['Date and Time of Visit']."\n";
$body .= "Occassion: ".$p['Occasion']."\n";
$body .= "Restaurant and Location: ".$p['Restaurant and Location']."\n";
$body .= "Server: ".$p['Server\'s Name']."\n\n";
$body .= "Ratings:\n- Host Greeting: ".$p['Host Greeting']."\n";
$body .= "- Food Quality/Appeal: ".$p['Food Quality/Appeal']."\n";
$body .= "- Menu Selection: ".$p['']."\n";
$body .= "- Service: ".$p['Service']."\n";
$body .= "- Atmosphere: ".$p['Atmosphere']."\n";
$body .= "- Price/Value: ".$p['Price/Value']."\n";
$body .= "- Cleanliness: ".$p['Cleanliness']."\n";
$body .= "- Overall Experience: ".$p['Overall Experience']."\n\n";
$body .= "Questions:\n- - Will you recommend this restaurant to others? ".$p['Will you recommend this restaurant to others?']."\n";
$body .= "- Have you been to a BHG Restaurant before? ".$p['Have you been to a BHG Restaurant before?']."\n";
$body .= "- Would you be interested in receiving information about our private meeting/dining facilities and services? ".$p['']."\n";
$body .= "- May we send you information about special events and occasions at our restaurants? ".$p['May we send you information about special events and occasions at our restaurants?']."\n\n";
$body .= "Comments: \n".$p['How can we serve you better?']."\n";
if(!empty($_POST['url'])){ die('Thankyou'); }
if(isset($_POST['url']) && $_POST['url'] == '')

$to = "emailaddy@emailworld.com";


$subject = "You have a feedback ";

$message = $body;

$from = "blah@blah.com";

$headers = "From:" . $from;

$dbaddress  =   ''; 
$dbuser     =   ''; 
$dbpass     =   ''; 
$dbname     =   '';

    try{
        $dbcnx              =    mysql_connect($dbaddress,$dbuser,$dbpass) or die("Could not connect: " . mysql_error());
        mysql_select_db($dbname, $dbcnx) or die ('Unable to select the database: ' . mysql_error());
        $query              =   mysql_query("insert into feedback (FirstName, LastName, Email, Address, City, State, Zip, Telephone, TimeandDay, Occassion, ResturantAndLocation, ServerName, HostGreeting, FoodQuality, Service, Atmosphere, PriceValue, Clenliness, OverallExperience, QuestionOne, QuestionTwo, QuestionFour, Comments, tstamp, responded) values ('".mysql_real_escape_string($p['FirstName'])."', '".mysql_real_escape_string($p['LastName'])."', '".mysql_real_escape_string($p['Email'])."', '".mysql_real_escape_string($p['Address'])."', '".mysql_real_escape_string($p['City'])."', '".mysql_real_escape_string($p['State'])."', '".mysql_real_escape_string($p['Zip'])."', '".mysql_real_escape_string($p['Telephone'])."', '".mysql_real_escape_string($p['Date and Time of Visit'])."', '".mysql_real_escape_string($p['Occasion'])."', '".mysql_real_escape_string($p['Restaurant and Location'])."', '".mysql_real_escape_string($p['Server\'s Name'])."', '".mysql_real_escape_string($p['Host Greeting'])."', '".mysql_real_escape_string($p['Food Quality/Appeal'])."', '".mysql_real_escape_string($p['Service'])."', '".mysql_real_escape_string($p['Atmosphere'])."', '".mysql_real_escape_string($p['Price/Value'])."', '".mysql_real_escape_string($p['Cleanliness'])."', '".mysql_real_escape_string($p['Overall Experience'])."', '".mysql_real_escape_string($p['Will you recommend this restaurant to others?'])."', '".mysql_real_escape_string($p['Have you been to a BHG Restaurant before?'])."', '".mysql_real_escape_string($p['May we send you information about special events and occasions at our restaurants?'])."', '".mysql_real_escape_string($p['How can we serve you better?'])."', now(), null) ;", $dbcnx) or die("Unable to validate login and password with the database:" . mysql_error());            
    }catch (Excetion $e){}

mail($to,$subject,$message,$headers);

header( 'Location: ' );
} 
else 
{
header( 'Location: ' );
}
?> 

2 个答案:

答案 0 :(得分:0)

当您需要发送到附加地址时,只需将其他地址添加到由分号(;)分隔的$ to变量中。

答案 1 :(得分:0)

if ($_POST['confirm']=='yes'){ //assumes check box name is 'confirm' and value is 'yes'
//new email
}