2015-11-19 23 views
1

當前正在嘗試修改PHP聯繫人表單插件。我需要用戶能夠選擇他們想要發送電子郵件的辦公室部門,並獲得聯繫信息。去那個特定的電子郵件地址。根據用戶選擇將PHP表單信息發送到不同的電子郵件地址

這個插件在PHP中有一個允許發送聯繫人表單信息的數組。多個電子郵件地址。問題是它發送信息。到數組中的每個電子郵件地址,並且我需要用戶能夠僅選擇陣列中的一個地址來發送信息。至。

這裏是在PHP中的數組:

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

     'Select department you are trying to reach*' => '', 
     "[email protected]" => "Parts", 
     "[email protected]" => "Sales", 
     "[email protected]" => "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> 

我怎麼會一個下拉的形式添加到該聯繫人的形式,所以有人可以專門選擇部門(和陣列中的電子郵件地址一致)他們想要發送電子郵件給?

非常感謝幫助。我完全不知道如何做到這一點。對於任何好奇的人來說,我使用的插件名爲「Smart Forms」,他們在這裏有一個演示:http://codecanyon.net/item/smart-forms/full_screen_preview/7254656

回答

2

遍歷窗體這樣您可能收件人:

<?php 
$recipients = array(
     '' => 'Select department you are trying to reach*', 
     "[email protected]" => "Parts", 
     "[email protected]" => "Sales", 
     "[email protected]" => "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> 

然後在提交腳本smartprocess.php檢查並查看所提交的電子郵件地址相匹配的收件人之一:

<?php 
    $recipients = array(
      '' => 'Select department you are trying to reach*', 
      "[email protected]" => "Parts", 
      "[email protected]" => "Sales", 
      "[email protected]" => "Service", 
    ); 
    if($_POST['to-emailaddress'] && $recipients[$_POST['to-emailaddress']]){ 
     $name = $recipients[$_POST['to-emailaddress']]; 
     $email = $_POST['to-emailaddress']; 
     $mail->AddBCC($email, $name); 
    } 
?> 
+0

哦,天啊,謝謝你,你是個天才!我一直在想這個問題好幾天,你在5分鐘內解決了我的問題:) – KateG

相關問題