发送至已选中的复选框,该复选框已关联至电子邮件

时间:2018-03-22 10:53:52

标签: javascript php html html5 forms

所以我对Javascript和PHP这样的编码很新,我需要创建一个表单,该表单将托管在一个站点上,该站点在提交时将根据勾选的复选框发送电子邮件,不同的复选框将转到不同的电子邮件,我需要使用PHP帖子,是否有任何需要Jquery?或者我可以只使用PHP?我会喜欢这个帮助。谢谢

<?php  
    $mail1 = "test@test.com";
    $mail2 = "test2@test.com";
    $mail3 = "test3@test.com";
    if(isset($_POST["MainCB"])) {
        $mail1 = $_POST["MainCB"];
    }
    if(isset($_POST["ITCB"])) {
        $mail2 = $_POST["ITCB"];
    }
    if(isset($_POST["CateCB"])) {
        $mail3 = $_POST["CateCB"];
    }
    if(isset($_POST['submit'])){
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $MainCB = $_POST['MainCB'];
    $ITCB = $_POST['ITCB'];
    $CateCB = $_POST['CateCB'];
    $subject = "Form submission";
    $message = $first_name . " " . $last_name . " " . $MainCB . " " . $ITCB . " " . $CateCB;
    }
?>
<html>
    <head>
        <title>Form submission</title>
    </head>
    <body>
        <form action="" method="post">
            First Name: <input type="text" name="first_name"><br>
            Last Name:  <input type="text" name="last_name"><br>
            Maintenance:<input type="checkbox" id="MainCB"><br>
            IT:         <input type="checkbox" id="ITCB"><br>
            Catering:   <input type="checkbox" id="CateCB"><br>
            <input type="submit" name="submit" value="Submit">
        </form>
    </body>
</html> 

1 个答案:

答案 0 :(得分:0)

您可以创建这样的表单

const Modal = (props) => {
      const modalRoot = document.getElementById('myEle');

      return ReactDOM.createPortal(props.children, modalRoot,);
    }

在邮件脚本中,您可以检索复选框值。

render() {
    const modal = this.state.showModal ? (
      <Modal>
        <Hello/>
        </Modal>
    ) : null;

    return (
      <div>
      <div id="myEle">
        </div>
      </div>
    );
  }