doupapin172773 2012-06-05 18:07
浏览 25
已采纳

选择要在php邮件程序中使用的变量

I'm using a simple php mailer for my sites contact form. I have a form asking first for their subject of contact, and if they select a spesific option, then the recipient selection will fade in and you can select the recipient you want to use. BUT. I don't want to write the email addresses in the code, because of spam. So I'm trying to achieve this via php variables.

My mailer looks like this:

<?php
$var1="xxx@gmail.com";
$var2="xxx@gmail.com";
$to = "$_POST[kohde]";
$subject = "$_POST[asia]";
$message = "
$_POST[tiedot]

$_POST[nimi]
$_POST[email]
$_POST[puhelin]
IP-osoite: $_POST[ip] ";
$from = "xxx.fi";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
?>

But using the variable names as is in value wont work. So how would I select the email to use with the option without hard coding the email to the option value?

 <select name="kohde" style="width:233px;" >
    <option value="$var1">xxx.fi</option>
    <option value="$var">Sivun tekijälle</option>
    </select>
  • 写回答

2条回答 默认 最新

  • duanjiushu5063 2012-06-05 18:11
    关注

    I would do it this way...

    Use this PHP to get the $to address:

    $goodAddresses = array(1 => 'a@x.com', 2 => 'b@x.com');
    $to = 'default@x.com';
    if(isset($goodAddresses[$_POST['kohde']])) {
        $to = $goodAddresses[$_POST['kohde']];
    }
    

    And change the values of your select options in our html file to match the array keys in the PHP:

    <select name="kohde" style="width:233px;" >
        <option value="1">xxx.fi</option>
        <option value="2">Sivun tekijälle</option>
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错