Php 根据用户从选择列表中的选择选择变量

Php 根据用户从选择列表中的选择选择变量,php,forms,variables,Php,Forms,Variables,我有这张表格。基本上,我想要的是根据用户在attn选择列表中选择的内容,使用不同的URL发送自动响应。我一直在想,对于每个下拉值,我可以有一个不同的变量。然后,它会将此变量传递给邮件脚本,该脚本将选择在发送的自动响应中插入哪个URL。有时候一想到它我就头疼。最简单的方法是什么 我在为自己做更多的工作吗?我真的不知道,因为我不是程序员。提前谢谢 表格如下: <form name="contact_form" method="post" action="sendemail_reports.ph

我有这张表格。基本上,我想要的是根据用户在attn选择列表中选择的内容,使用不同的URL发送自动响应。我一直在想,对于每个下拉值,我可以有一个不同的变量。然后,它会将此变量传递给邮件脚本,该脚本将选择在发送的自动响应中插入哪个URL。有时候一想到它我就头疼。最简单的方法是什么

我在为自己做更多的工作吗?我真的不知道,因为我不是程序员。提前谢谢

表格如下:

<form name="contact_form" method="post" action="sendemail_reports.php" onsubmit="return validate_form ( );">
      <div id='zohoWebToLead' align=center>
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="txt_body">
      <table border=0 cellspacing=0 cellpadding=5 width=480 style='border-bottom-color: #999999; border-top-color: #999999; border-bottom-style: none; border-top-style: none; border-bottom-width: 1px; border-top-width: 2px; background-color:transparent;'>
        <tr>
          <td width='75%'><table width=480 border=0 cellpadding=5 cellspacing=0 style='border-bottom-color: #999999; border-top-color: #999999; border-bottom-style: none; border-top-style: none; border-bottom-width: 1px; border-top-width: 2px; background-color:transparent;'>
            <input type="hidden" name="ip" value="'.$ipi.'" />
            <input type="hidden" name="httpref" value="'.$httprefi.'" />
            <input type="hidden" name="httpagent" value="'.$httpagenti.'" />
            <tr></tr>
            <tr>
              <td colspan='2' align='left' style='border-bottom-color: #dadada; border-bottom-style: none; border-bottom-width: 2px; color:#000000; font-family:sans-serif; font-size:14px;'><strong>Send us an Email</strong></td>
            </tr>
            <tr>
              <td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold' align='right' width='25%'> First Name   : </td>
              <td width='75%'><input name='visitorf' type='text' size="48" maxlength='40' /></td>
            </tr>
            <tr>
              <td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold' align='right' width='25%'>Last Name   :</td>
              <td width='75%'><input name='visitorfl' type='text' size="48" maxlength='80' /></td>
            </tr>
            <tr>
              <td nowrap style=
        'font-family:sans-serif;font-size:12px;font-weight:bold' align='right' width='25%'> Email Adress  : </td>
              <td width='75%'><input name='visitormail' type='text' size="48" maxlength='100' /></td>
            </tr>
            <tr>
              <td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold' align='right' width='25%'> Phone   : </td>
              <td width='75%'><input name='visitorphone' type='text' size="48" maxlength='30' /></td>
            </tr>
            <td nowrap style='font-family:sans-serif;font-size:12px;font-weight:bold' align='right' width='25%'> Subject   : </td>
              <td width='75%'><select name="attn" size="1">
                <option value=" Investment Opportunities ">Investment Opportunities </option>
                <option value=" Vacation Rentals ">Vacation Rentals </option>
                <option value=" Real Estate Offerings ">Real Estate Offerings </option>
                <option value=" Gatherings ">Gatherings </option>
                <option value=" General ">General </option>
              </select></td>
            <tr>
              <td nowrap style=
        'font-family:sans-serif;font-size:12px;font-weight:bold' align='right' width='25%'> Message   :<br />
                <em>(max 5000 char)</em></td>
              <td width='75%'><textarea name='notes' maxlength='5000' cols="48" rows="3"></textarea></td>
            </tr>
            <tr>
              <td colspan=2 align=center style=''><input name='save' type='submit' class="boton" value=Send mail />
                &nbsp; &nbsp;
                <input type='reset' name='reset' value=Reset class="boton" /></td>
            </tr>
          </table></td>
        </tr>
      </table>
      </div>
    </form>
以下是邮件脚本:

    <?php
//the 3 variables below were changed to use the SERVER variable  
$ip = $_SERVER['REMOTE_ADDR'];  
$httpref = $_SERVER['HTTP_REFERER'];   
$httpagent = $_SERVER['HTTP_USER_AGENT'];   

$visitorf = $_POST['visitorf'];   
$visitorl = $_POST['visitorl'];   
$visitormail = $_POST['visitormail'];   
$visitorphone = $_POST['visitorphone'];   
$notes = $_POST['notes'];  
$attn = $_POST['attn'];   

//additional headers   
$headers = 'From: Me <myemail@domain.com>' . "\n" ;  
$headers = 'Bcc: myemail@domain.com' . "\n";  


if (eregi('http:', $notes)) {
    die ("Do NOT try that! ! ");
}

if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))  
{  
    echo "<h2>Use Back - Enter valid e-mail</h2>\n";  
    $badinput = "<h2>Feedback was NOT submitted</h2>\n";  
    echo $badinput;  
    die ("Go back! ! ");  
}  

if(empty($visitorf) || empty($visitormail) || empty($notes )) {  
    echo "<h2>Use Back - fill in all fields</h2>\n";  
    die ("Use back! ! ");  
}  

$todayis = date("l, F j, Y, g:i a") ;  
$subject = "I want to download the report about $attn";  
$notes = stripcslashes($notes);  
$message = "$todayis [EST] \nAttention: $attn \nMessage: $notes \nFrom: $visitorf   $visitorl ($visitormail) \nTelephone Number: $visitorphone \nAdditional Info : IP = $ip   \nBrowser Info: $httpagent \nReferral : $httpref\n";  

//check if the function even exists  
if(function_exists("mail"))  
{  
    //send the email  
    mail($_SESSION['email'], $subject, $message, $headers) or die("could not send   email");  
} else {  
    die("mail function not enabled");  
}  

header( "Location: http://www.domain.com/thanks.php" );  
?>  

我不能完全肯定我是否正确理解了你的要求。 让我直截了当地说:你想根据用户从下拉菜单中选择的内容在邮件中写入特定的url吗? 如果是这样的话,我会用这样的方法:

$lookup = array(
    'Investment Opportunities' => 'http://someurl.com/',
    'Vacation Rentals' => 'http://someotherurl.com/',
    // et cetera for your other values
);

$attn = trim($_POST['attn']);
$url = $lookup[$attn];

在此之后,您可以在邮件中使用$url,它将根据用户提供的下拉值而有所不同。

要根据“attn”字段将用户重定向到不同的url,请替换php文件中的以下行:

header( "Location: http://www.domain.com/thanks.php" );  
使用以下switch语句:

Switch ($_POST['attn']){
Case  " Investment Opportunities ":
    header( "Location: http://www.domain.com/thanks1.php" ); 
    break;
Case  " Vacation Rentals ":
    header( "Location: http://www.domain.com/thanks2.php" ); 
    break;
Case  " Real Estate Offerings ":
    header( "Location: http://www.domain.com/thanks3.php" ); 
    break;
Case  " Gatherings ":
    header( "Location: http://www.domain.com/thanks4.php" ); 
    break;
Case  " General ":
    header( "Location: http://www.domain.com/thanks5.php" ); 
    break;

}

那么我上面的代码应该可以工作了。只需在邮件文本中使用$url,用户将根据下拉列表中选择的值接收不同的url。如果这能解决你的问题,你介意挂断电话吗?对不起,我在别的事情上偏离了方向。我已经做了你建议的改变。邮件脚本完成,邮件中的$url没有显示相应的url。好的,基本调试:在$url=$lookup[$attn]行之后;,请加上一行:echo“attn:”好吗$收件人:,网址:‘$网址;死亡然后在这里发布结果?我添加了你要求的行,它进入sendmail_reports.php页面并显示了收件人和URL。因此,我删除了该行并重试,它成功了。我承认,当我回到家时,我又按照你的指示做了。所以早些时候我犯了个错误。非常感谢。没问题,很高兴我能帮忙D