Swapnil_0226 Posted October 9, 2014 Share Posted October 9, 2014 <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> Quote Link to comment Share on other sites More sharing options...
Swapnil_0226 Posted October 9, 2014 Author Share Posted October 9, 2014 This code sends email to different user after selecting checkbox on click of send button. Its work well. here i will send email to different user so in $messege i have to put name of that user so how is it possible. because i m fetching data from database. Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 9, 2014 Share Posted October 9, 2014 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. Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 9, 2014 Share Posted October 9, 2014 Actually, I just looked at the code snippet above, and that is totally wrong. You should change that to: $message = "Dear attorney {$row['first_name']} {$row['middle_name']} {$row['last_name']}:"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.