[Solved] Have you an idea to send email in new way?


I don’t know adding another answer is allowed or not but let me try it.
If anything is wrong kindly let me know.

Hello Hope this will help. Ask question if have any confusion.

First file q1.php and code for that

<?php $con = mysqli_connect('localhost','root','','test');  ?>

   <form action='emailScript.php' method='post'>
        <div class="control-group"> 
        <label class="control-label" for="basicinput"> Select Users ID</label> 
         <div class="controls"> 
    <select name="category[]" id="id" class="span8 tip mdb-select colorful-select dropdown-primary" multiple searchable="Search here.." required> 
        <option value=""disabled>Select User Credentials</option> 
        <?php $sql=mysqli_query($con,"select * from Users where Status="1""); 
        while ($rw=mysqli_fetch_array($sql)) { ?> 
            <option value="<?php echo htmlentities($rw['Email']);?>">
                <?php echo htmlentities($rw['Full_Name']);?>

                </option> <?php } ?> 
      </select> 
      </div>

     <textarea name="emailText"></textarea>
      </div>

    <input type="submit" name="submit" value="Send" />
      </form>

Second file emailScript.php code is below

<?php

     //check values are coming here or not
     echo '<pre>';
         print_r($_POST);
      echo '</pre>';

      $emails = $_POST['category'];
      $emailText = $_POST['emailText'];
      foreach($emails as $email){
        //if email sending funciton is set properly then mail will fly
        //:)
         if( mail("$email",'Subject of Email',"$emailText")){
              echo 'Mail Send Successfully';
           }else{
           echo 'ERROR:';
         }
      }

     ?>

I hope at least now you come up with good news. 🙂

I am using xampp with mercury mail server so local meail is sended properly.

enter image description here

enter image description here

Try This with PHPMailer Class

<?php

 //check values are coming here or not
 echo '<pre>';
     print_r($_POST);
  echo '</pre>';

            include_once "PHPMailer/src/PHPMailer.php";

            $emails = $_POST['category'];
            $mail = new PHPMailer();
            $mail->setFrom('[email protected]');
            $mail->Subject = "Please verify email!";
            $mail->isHTML(true);
            $mail->Body = $_POST['emailText'];

            foreach($emails as $email){

                $mail->addAddress( $email );

                if ($mail->send())
                    $msg = "You have been sent your email!";
                else
                    $msg = "Something wrong happened! Please try again!";
            }

  ?>
  <?php if ($msg != "") echo $msg . "<br><br>" ?>
  <?php if ($msg != "") echo $msg . "<br><br>" ?>

16

solved Have you an idea to send email in new way?