dsjz1119 2015-12-02 23:57
浏览 33

PHP表单提交到错误的电子邮件地址

I have a select field within a form (below) that allows the user to select a specific 'agent' in which they want the form to be emailed to. The code below displays the correct name and email for the agents.

<select name="to" class="select-box">
    <option value="">Send message to</option>
        <?php if(isset($agents) && $agents):
            if(!is_array($agents)) { $agents = array($agents); }
                foreach($agents as $agent):
                    $agent_post = get_post($agent);
                    $email = sanitize_email(get_post_meta( $agent, '_meta_email', true ));
                    $mailto[] = $email;
                    echo '<option value="'.$email.'">'.wp_kses_data($agent_post->post_title).'</option>';
            endforeach;
        endif;
    ?>
</select>

... now is when things start to get tricky. The PHP to actually use the selected email is not working properly.

$to = $_REQUEST['to'];
if(!$to) $to = nt_get_option('property', 'contact_email', get_bloginfo('admin_email'));

The second line acts as a backup plan if no email address is selected, however it's being used even if the user has selected a specific agent. Any suggestions on what I'm missing?

  • 写回答

1条回答 默认 最新

  • drbae3964 2015-12-03 00:38
    关注

    I don't think !$to is what you are looking for. !$to actually means != true which obviously an email address does not equal true, therefore it will always use the default email address.

    I would try

    $to = trim($_REQUEST['to']); // trim whitespace
    
    // Check if $to is empty
    if(empty($to)){
        // If so, set default
        $to = nt_get_option('property', 'contact_email', get_bloginfo('admin_email'));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog