在php中发送多封邮件,用户必须输入他必须与之交互的特定电子邮件ID

问题描述 投票:0回答:2

在php中发送多封邮件,用户必须输入他必须与之交互的特定电子邮件ID。

从下面的代码中,我创建了两个电子邮件字段,其中一个电子邮件被触发(第一个),但不是第二个。

任何人都可以帮我解决吗?

<!DOCTYPE html>
<html>
<head>
    <title>testing mail</title>

</head>
<body>

    <h1 class="text-center">Sending Emails</h1>

    <?php
    if (isset($_POST['sendmail'])) {
        if (mail($_POST['email'], $_POST['email1'], $_POST['subject'], $_POST['message'])) 
        {
            echo "Mail sent";
        }else {
            echo "Failed";
        }   
    }
    ?>


            <form role="form" method="post" enctype="multipart/form-data">

                        <label for="email">To Email:</label>
                        <input type="email" class="form-control" id="email" name="email" maxlength="500">

                        <label for="email1">To Email:</label>
                        <input type="email1" class="form-control" id="email1" name="email1" maxlength="500">

                        <label for="subject">Subject:</label>
                        <input type="text" class="form-control" id="subject" name="subject" maxlength="50">

                        <label for="name">Message:</label>
                        <textarea class="form-control" type="textarea" id="message" name="message" placeholder="Your Message Here" maxlength="6000" rows="5"></textarea>

                    <button type="submit" name="sendmail" class="btn btn-lg btn-sucess btn-block">Send</button>

    </form>

</body>
</html>
html-email form-submit html-form
2个回答
0
投票

你比较字符串:

emailall = $_POST['email']. ",".$_POST['email1'];
mail(emailall, $_POST['subject'], $_POST['message'])

这样的事情。


0
投票

成功工作!!!! ....集中电子邮件触发多个电子邮件收件人!!!!!! (不需要默认硬编码)我们可以手动输入特定电子邮件收件人,同时发送整个表单。

<!--index.html-->

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Feedback Form</title>
  <style type="text/css" media="screen">
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: helvetica;
    }
    body{
      background-color: #ffffff;
    }
    .main{
      width: 500px;
      margin: 50px auto;
      border-radius: 10px;
      border: 5px solid #0C3D6E;
      border-left: 40px solid #0C3D6E;
      box-shadow: 1px 2px 10px #555;
    }
    .info{
      width: 100%;
      background-color: #0C3D6E;
      padding: 7px;
      text-shadow: 1px 1px 1px #222;
      color: #fff;
      font-size: 20px;
    }
    .form-box{
      padding: 20px;
      background-color: #eee;
    }
    label{
      color: navy;
      font-size: 18px;
    }
    .inp,.msg-box{
      width: 100%;
      padding: 10px;
      margin-top: 4px;
      margin-bottom: 5px;
      border-radius: 5px;
      border: 2px solid #0C3D6E;
      font-weight: bold;
      color: #0C3D6E;
      border-right: 15px solid #0C3D6E;
      border-left: 15px solid #0C3D6E;
      resize: none;
    }
    .msg-box{
      height: 80px;
    }
    .inp:focus,.msg-box:focus{
      outline: none;
      border: 2px solid navy;
      border-right: 15px solid navy;
      border-left: 15px solid navy;
    }
    .sub-btn{
      width: 100%;
      padding: 10px;
      border-radius: 5px;
      margin-top: 5px;
      border: none;
      background: linear-gradient(#0C3D6E,#0C3D6E);
      cursor: pointer;
      color: #fff;
      font-size: 20px;
      text-shadow: 1px 1px 1px #444;
    }
    .sub-btn:hover{
      background: linear-gradient(#0C3D6E,#0C3D6E);
      opacity: 0;
      transition: all ease-out 0.2s;
    }
    .sub-btn:focus{
      outline: none;
    }
    @media(max-width: 720px){
      .main{
        width: 90%;
      }
    }
  </style>
</head>
<body>
  <div class="main">
    <div class="info">Give Your Feedback!</div>
    <form action="mail_handler.php" method="post" name="form" class="form-box">
      <label for="name">Name</label><br>
      <input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>

      <label for="phone">Phone</label><br>
      <input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>

      <label for="email">Email ID1</label><br>
      <input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>

      <label for="email">Email ID2</label><br>
      <input type="email" name="email1" class="inp" placeholder="Enter Your Email" required>
      <br>

      <label for="email">Email ID3</label><br>
      <input type="email" name="email2" class="inp" placeholder="Enter Your Email" required>
      <br>

      <label for="email">Email ID4</label><br>
      <input type="email" name="email3" class="inp" placeholder="Enter Your Email" required>
      <br>

      <label for="email">Email ID5</label><br>
      <input type="email" name="email4" class="inp" placeholder="Enter Your Email" required>
      <br>

      <label for="message">Message</label><br>
      <textarea name="msg" class="msg-box" placeholder="Enter Your Message Here..." required></textarea><br>
      <input type="submit" name="submit" value="Send" class="sub-btn">
    </form>
  </div>
</body>
</html>

**<!--mail_handler.php(php file)-->**

<?php
  if(isset($_POST['submit'])){
    $name=$_POST['name'];
    $email=$_POST['email'];
    $email1=$_POST['email1'];
    $email2=$_POST['email2'];
     $email3=$_POST['email3'];
      $email4=$_POST['email4'];
    $phone=$_POST['phone'];
    $msg=$_POST['msg'];

    $to="$email, $email1, $email2, $email3, $email4"; // Receiver Email ID, Replace with your email ID
    $subject='Form Submission';
    $message="Name :".$name."\n"."Phone :".$phone."\n"."Wrote the following :"."\n\n".$msg;
    $headers="From: [email protected]";

    if(mail($to, $subject, $message, $headers)){
      echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly!</h1>";
    }
    else{
      echo "Something went wrong!";
    }
  }
?>
© www.soinside.com 2019 - 2024. All rights reserved.