Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据用户选择将PHP表单信息发送到不同的电子邮件地址_Php_Arrays_Contact Form - Fatal编程技术网

根据用户选择将PHP表单信息发送到不同的电子邮件地址

根据用户选择将PHP表单信息发送到不同的电子邮件地址,php,arrays,contact-form,Php,Arrays,Contact Form,目前正在尝试修改PHP联系人表单插件。我需要用户能够选择哪个办公室部门,他们想发送他们的电子邮件,并有联系信息。转到特定的电子邮件地址 这个插件在PHP中有一个数组,允许发送联系人表单信息。发送到多个电子邮件地址。问题是它会发送信息。发送到阵列中的每个电子邮件地址,我需要用户能够选择阵列中的一个地址来发送信息。对 以下是PHP中的数组: $recipients = true; if($recipients == true){ $recipients = array(

目前正在尝试修改PHP联系人表单插件。我需要用户能够选择哪个办公室部门,他们想发送他们的电子邮件,并有联系信息。转到特定的电子邮件地址

这个插件在PHP中有一个数组,允许发送联系人表单信息。发送到多个电子邮件地址。问题是它会发送信息。发送到阵列中的每个电子邮件地址,我需要用户能够选择阵列中的一个地址来发送信息。对

以下是PHP中的数组:

$recipients = true;
    if($recipients == true){
        $recipients = array(

        'Select department you are trying to reach*' => '',
        "example1@gmail.com" => "Parts",
        "example2@gmail.com" => "Sales",
        "example3@gmail.com" => "Service",
        );

        foreach($recipients as $email => $name){
            $mail->AddBCC($email, $name);
        }   
    }
以下是联系人表单的设置:

<form method="post" action="php/smartprocess.php" id="smart-form">

    <div class="form-body">


        <label class="field prepend-icon">
            <input type="text" name="sendername" id="sendername" class="gui-input" placeholder="Enter name">
        </label>

        <label class="field prepend-icon">
            <input type="email" name="emailaddress" id="emailaddress" class="gui-input" placeholder="Email address">
        </label>

        <label class="field">
            <input type="text" name="captcha" id="captcha" class="gui-input sfcode" maxlength="6" placeholder="Enter CAPTCHA">
        </label>

        <label class="button captcode">
            <img src="php/captcha/captcha.php?<?php echo time();?>" id="captchax" alt="captcha">
            <span class="refresh-captcha"><i class="fa fa-refresh"></i></span>
       </label>

       <div class="result"></div>

      <button type="submit" data-btntext-sending="Sending..." class="button btn-primary">Submit</button>
      <button type="reset" class="button"> Cancel </button>


</form> 

“id=“captchax”alt=“captcha”>
提交
取消
我如何将下拉表单添加到此联系人表单中,以便有人可以专门选择他们希望将电子邮件发送到的部门(以及阵列中的一致电子邮件地址)


非常感谢您的帮助。我完全不知道如何实现这一点。对于任何好奇的人,我使用的插件称为“智能表单”,他们在这里有一个演示:。

在表单上循环浏览您可能的收件人,如下所示:

<?php 
$recipients = array(
        '' => 'Select department you are trying to reach*',
        "example1@gmail.com" => "Parts",
        "example2@gmail.com" => "Sales",
        "example3@gmail.com" => "Service",
    );
?>

<form method="post" action="php/smartprocess.php" id="smart-form">

    <div class="form-body">


        <label class="field prepend-icon">
            <input type="text" name="sendername" id="sendername" class="gui-input" placeholder="Enter name">
        </label>

        <label class="field prepend-icon">
            <input type="email" name="emailaddress" id="emailaddress" class="gui-input" placeholder="Email address">
        </label>

        <label class="field select-to-email">
            <select name="to-emailaddress" id="toemailaddress" class="gui-input" placeholder="To Email address">
            <?php foreach($recipients as $email => $name) : ?>
                    <option value="<?php echo $email; ?>"><?php echo $name; ?></option>
            <?php endforeach; ?>
            </select>
        </label>

        <label class="field">
            <input type="text" name="captcha" id="captcha" class="gui-input sfcode" maxlength="6" placeholder="Enter CAPTCHA">
        </label>

        <label class="button captcode">
            <img src="php/captcha/captcha.php?<?php echo time();?>" id="captchax" alt="captcha">
            <span class="refresh-captcha"><i class="fa fa-refresh"></i></span>
       </label>

       <div class="result"></div>

      <button type="submit" data-btntext-sending="Sending..." class="button btn-primary">Submit</button>
      <button type="reset" class="button"> Cancel </button>


</form> 


哦,我的上帝,谢谢你,你真是个天才!我已经想了好几天了,你在5分钟内解决了我的问题:)
<?php 
    $recipients = array(
            '' => 'Select department you are trying to reach*',
            "example1@gmail.com" => "Parts",
            "example2@gmail.com" => "Sales",
            "example3@gmail.com" => "Service",
    );
    if( $_POST['to-emailaddress'] && $recipients[$_POST['to-emailaddress']]){
        $name = $recipients[$_POST['to-emailaddress']];
        $email = $_POST['to-emailaddress'];
        $mail->AddBCC($email, $name);
    }
?>