Jump to content

send email with fetched data information to different user after selecting checkbox


Swapnil_0226

Recommended Posts

<script type="text/javascript">

   function send_email(){

   var persons_names;

   persons_names = $('#send_mail_persons input:checked');

   var persons_names_Str='',coma='';

   if(persons_names.length != 0)

   {

      persons_names.each(function(){

      persons_names_Str += coma+$(this).val();

      coma = ',';

     })

    }

    alert(persons_names_Str);

    //    console.log(" persons_names_Str: "+persons_names_Str);

    ajax_call_to_send_values_to(persons_names_Str);

    }

 

 

     function ajax_call_to_send_values_to(persons_names_Str){

     $.ajax({

                  url: 'http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?>',

                type: 'POST',

                  data: { persons_names_Str: persons_names_Str            

                           },  

                  success: function(data, textStatus, xhr) {

                         

                  },

                //called when successful

                    

                  error: function(xhr, textStatus, errorThrown) {

                //called when there is an error

                      }

        });

      }

      </script>

      

 

     <div id="send_mail_persons">

     <?php

      $sql = "SELECT * FROM lawyer_details WHERE city LIKE :city AND speciality LIKE :speciality";

      $result = db_query($sql,array(':city' => '%'. db_like($_SESSION['selected_county']).'%' ,    ':speciality' => '%'.db_like($_SESSION['lawarea']).'%'));

      $rows_count=$result->rowCount();

      if($result && $rows_count>0) 

      { 

      while($row = $result->fetchAssoc()) 

      {

      ?>

      <div class="result">

       <div class="resultPadder">

           <div class="resultLeft">

              <div id="fav">

             <div><input type="checkbox" name="checkbox[]" id="email1" value=<?php echo $row['email_id'];?> /><a class="b ui-link" href="" onclick=""><?php echo $row['first_name'].' '.$row['middle_name'].' '.$row['last_name'];?></a>  

              </div>

           <div class="p-t-2"><?php echo $row['street_address'];?></div>

           </div>

           </div>

<?php

      if( isset($_POST['persons_names_Str']) && !empty($_POST['persons_names_Str']) )

      {

       $list = $_POST['persons_names_Str'];

//print_r($list);

//$to_arr = explode(",", $list);

//$to = array_filter($to_arr);

//echo $to;

//print_r($to);

       $to = $list;

       $subject = "Test Subject";

       $message = "Dear attorney ".<?php echo $row['first_name'].' '.$row['middle_name'].' '.$row['last_name'];?>:."

 

If you decide you do not want your name listed, please e-mail us and we will delete your name from our listing.\r\n";

     $headers = "From: no-reply@xyz.com\r\n" .

     "X-Mailer: php";

     $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

     $to =  "no-reply@xyz.com";

     $headerFields = array('BCC: '.$list.', "From: no-reply@lxyz.com" ."X-Mailer: php"');

     if (mail($to, $subject, $message, implode("\r\n", $headerFields))) {

     //if (mail($to, $subject, $body, $headers)) {

     echo("<p>Message sent successfully! our lawyer will contact you as soon as possible</p>");

     } else {

     echo("<p>Message delivery failed...</p>");

     }

     exit();

     } ?>

<div class="resultRight">

 

 

</div></div><div class="clear"></div>

       

 

 <?php 

     

    }

 }

else

{

 echo "No Result Found";

}

?>

<a href="javascript:void(0);"  onClick="javascript:send_email();"><span>Send Email</span></a>

 

</div>

     </div>

     <div>

Link to comment
Share on other sites

You are already providing the user's name, from the database, in your email.

here

 

$message = "Dear attorney ".<?php echo $row['first_name'].' '.$row['middle_name'].' '.$row['last_name'];?>:."

 

or, else I am mis-understanding your question.

 

also, please use the [ code ][ /code ] blocks to post your code. <> on the editor,  It makes it easier to read.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.