Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.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_Checkbox_Contact Form - Fatal编程技术网

Php 使用复选框选择联系人表单中的收件人电子邮件地址

Php 使用复选框选择联系人表单中的收件人电子邮件地址,php,checkbox,contact-form,Php,Checkbox,Contact Form,我创建了一个电子邮件表单,根据选中的复选框,该表单应该发送到两个不同的电子邮件地址。但我真的很难让它工作,让我告诉你我要做什么 在我看来,表单确实非常有效,只是通过复选框发送电子邮件让我失望 请帮忙 这是表格部分: <div id="respond"> <?php echo $response; ?> <form id="commentForm" method="post" action="#contact2">

我创建了一个电子邮件表单,根据选中的复选框,该表单应该发送到两个不同的电子邮件地址。但我真的很难让它工作,让我告诉你我要做什么

在我看来,表单确实非常有效,只是通过复选框发送电子邮件让我失望

请帮忙

这是表格部分:

<div id="respond">
            <?php echo $response; ?>
            <form id="commentForm" method="post" action="#contact2">

              <div>
            <small>Name:</small>
                <input type="text" name="message_name" placeholder="Enter you name..." value="<?php echo $_POST['message_name']; ?>">
            <small>Department:</small>
<!-- EDIT || replaced type=checkbox with type=radio -->
                <input type="radio" name="sales" value="sales@h-s-c.co.uk" checked/>
                <input type="radio"name="lettings" value="lettings@h-s-c.co.uk" />
            <small>Email:</small>
                <input type="text" name="message_email" placeholder="somebody@email.co.uk" value="<?php echo $_POST['message_email']; ?>">
            <small>Phone:</small>    
                <input class="" type="tel" name="phone_number" placeholder="07912 208 936" value="<?php echo $_POST['phone_number']; ?>">
              </div>

              <div style="float:right;">
            <small>Message:</small>
                <textarea type="text" name="message_text" placeholder="I would like further information on..."><?php echo $_POST['message_text']; ?></textarea>
               </div>

            <small>Human Verification:</small><br>
                <input type="text" style="width: 60px;" name="message_human" placeholder="2"> + 3 = 5</label>
                 <input type="hidden" name="submitted" value="1">
                <input class="" type="submit" value="submit"/>

            </form>
           </div>

姓名:
人工验证:
+ 3 = 5
然后发送表单的php如下所示:

    <?php
    //Include email and to name
    $admin_email = $_POST[$email_address];//EDIT || changed to new value $email_address
    $block = "Test";

//Remove this section
//foreach($_POST['check'] as $value) {
  //  $checkbox .= "$value\n";
//} 
    ?>
    <?php

      //response generation function

      $response = "";

      //function to generate response
      function generate_response($type, $message){

        global $response;

        if($type == "success") $response = "<div class='success'>{$message}</div>";
        else $response = "<div class='error'>{$message}</div>";

      }

      //response messages
      $not_human       = "Human verification incorrect.";
      $missing_content = "Please supply all information.";
      $email_invalid   = "Email Address Invalid.";
      $message_unsent  = "Message was not sent. Try Again.";
      $message_sent    = "Thanks! Your message has been sent.";

      //user posted variables
      $name = $_POST['message_name'];
      $email = $_POST['message_email'];
      $phone = $_POST['phone_number'];
      $message = $_POST['message_text'];
      $human = $_POST['message_human'];

      //php mailer variables
      $to = $admin_email;
      $subject = "Someone sent a message from {$block}";
      $headers = 'From: '. $email . "\r\n" .
        'Reply-To: ' . $email . "\r\n";
        $tel = 'Contact no: ' . $phone;

      if(!$human == 0){
        if($human != 2) generate_response("error", $not_human); //not human!
        else {

          //validate email
          if(!filter_var($email, FILTER_VALIDATE_EMAIL))
            generate_response("error", $email_invalid);
          else //email is valid
          {
            //validate presence of name and message
            if(empty($name) || empty($message)){
              generate_response("error", $missing_content);
            }
            else //ready to go!
            {
              $sent = mail($to, $subject, $message . $tel , $headers);
              if($sent) generate_response("success", $message_sent); //message sent!
              else generate_response("error", $message_unsent); //message wasn't sent
            }
          }
        }
      } 
      else if ($_POST['submitted']) generate_response("error", $missing_content);

    ?>


提交表单时,复选框不会向服务器提供其值。如果选中复选框,则复选框只有一个值<代码>on
。改用
单选按钮
选择框

复选框不发送字符串值,只发送复选框标识符的布尔值

添加新条件的代码 如果选中此复选框,则对这两个复选框都使用电子邮件或空白。


<?php
//Include email and to name
$admin_email = $_POST[$checkbox];  // no element with name 'checkbox' 
$block = "Test";

// no element with name 'check'
foreach($_POST['check'] as $value) {
$checkbox .= "$value\n";
} 
?>


these are main issue.

If you want to send mail to any one from the two options then use select, and in value of     option provide email id

//HTML CODE
<select name="to_email">
<option value="sales@xxxx">Sales</option>
<option value="lettings@xxxx">Lettings</option>
</select>


PHP CODE

<?php
$admin_email = $_POST['to_email'];  // this will get you the selected email id
?>

let me know if you have any queries.
这些是主要问题。 如果您想从这两个选项中向任何一个发送邮件,请使用select,并在选项的值中提供电子邮件id //HTML代码 销售额 出租 PHP代码 如果您有任何疑问,请告诉我。
*
电子邮件
电话
细节
我们能帮你做什么?
后勤
销售额
顾客
*

Simple。。。谢谢然后php:谢谢你的帮助,我刚刚修复了它。在标题中添加单选按钮可能会更好地为您的答案添加一些描述,以帮助其他人理解。这非常简单,我正在粘贴完整的表单代码。这样每个人都能很容易地理解。
*<form id="requestform" name="requestform" action="enquiry.php" class="col-xs-12" method="post">
            <div class="form-wrapper">
                <div class="col-xs-12">
                    <div class="field col-xs-6">
                        <label class="formlabel"> Email </label> 
                        <input class="textfield"  data-required="true" type="email" name="email" />
                    </div>
                    <div class="field col-xs-6">
                        <label class="formlabel"> Phone </label>
                        <input class="textfield"  data-required="true" type="text" name="phone" />
                    </div>
                </div>
                <div class="clear"></div>
                <div class="col-xs-12">                 
                    <div class="field col-xs-6">
                        <label class="formlabel"> Details </label>
                        <textarea class="textfield textarea" type="textarea"  data-required="true" name="details"/></textarea >
                    </div>
                    <div class="field emailfunc col-xs-6">
                        <label class="formlabel"> What can we help you with ? </label>
                        <span>
                            <input name="interested" id="logistics" value="logistics" onchange="" type="checkbox">
                            <label class="inline" >Logistics</label>
                        </span>
                        <span>
                            <input name="interested" id="sales" value="sales" onchange="" type="checkbox">
                            <label class="inline" >Sales</label>
                        </span>
                        <span>
                            <input name="interested" id="customer" value="customer" onchange="" type="checkbox">
                            <label class="inline" >Customer</label>
                        </span>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
            </div>

            <div class="col-xs-12">                 
                <div class="field col-xs-6">
                    <input class="submit" type="submit" value="<?php echo Mage::helper('contacts')->__('Send Enquiry') ?>" name="submit">
                </div>
            </div>
            <div class="clear"></div>

        </form>


<?php
    //enquiry.php
    $email=$_REQUEST['email'];
    $phone=$_REQUEST['phone'];
    $details=$_REQUEST['details'];
    $interested=$_REQUEST['interested'];

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= "From: \"Request a Quote\" <fakhruddinsouq>\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $message = '<html><head><title>Fakhruddin Souq</title></head><body>
    <div style="color:#006A93; width:auto; height:auto; background-color:#eeeeee; margin:0px auto;">
  <fieldset style=" border-color:#006A93; border-style:double;">
    <legend align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:18px; text-decoration:underline;">Request a Quote</legend>
    <head><title>Fakhruddin Souq</title></head>
    <table border="0" cellpadding="0" cellspacing="4" align="left" width="100%" height="100%" style="color:#006A93; font-weight:bold; font-size:12px; font-family:Arial, Helvetica, sans-serif;">
        <td align="left" valign="top">Email: </td>
        <td align="left" valign="top">'.$email.'</td>
      </tr>
       <tr>
        <td align="left" valign="top">Phone: </td>
        <td align="left" valign="top">'.$phone.'</td>
      </tr>
      <tr>
        <td align="left" valign="top"> Product Details: </td>
        <td align="left" valign="top">'.$details.'</td>
      </tr>
      <tr>
        <td colspan="2" align="left" valign="top" style="font-size:14px;">Regards</td>
      </tr>
    </table>
    <span style="clear:both; float:left; font-size:14px; padding-left:4px; padding-top:10px; font-family:Arial, Helvetica, sans-serif;">Posted Date & Time:'.date('m/d/Y H:i:s').'</span>
  </fieldset>
</div>
        </body>
        </html>';

    if($interested == 'logistics') {
        $to = "abc@email.com";
    }
    else if($interested == 'sales') {
        $to = "def@email.com"; 
    } 
    else if($interested == 'customer') {
        $to = "imemail@email.com"; 
    }
    else if($interested == 'logistics' && $interested == 'sales' && $interested == 'customer'){
        $to = "abc@email.com,def@email.com,imemail@email.com"; 
    }
    else if($interested == 'logistics' && $interested == 'sales'){
        $to = "abc@email.com,def@email.com"; 
    }
    else if($interested == 'logistics' && $interested == 'customer') {
        $to = "abc@email.com,imemail@email.com"; 
    }
    else if($interested == 'sales' && $interested == 'customer') {
        $to = "def@email.com,imemail@email.com"; 
    }
    else {
        $to ="imemail@email.com"; 
    }

    if (mail($to,'Mail From '.$name,$message,$headers)){       
        print json_encode(array('type'=>'done', 'text' => 'Thank You For Your Enquiry'));
        exit;
    }
    else {       
        print json_encode(array('type'=>'done', 'text' => 'Sorry Email is not sent'));
        exit;
    } 
?>*