fetch data send in email messege part

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swapnil_0226
Forum Newbie
Posts: 2
Joined: Thu Oct 09, 2014 4:50 am

fetch data send in email messege part

Post by swapnil_0226 »

Code: Select all

<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>
swapnil_0226
Forum Newbie
Posts: 2
Joined: Thu Oct 09, 2014 4:50 am

Re: fetch data send in email messege part

Post by swapnil_0226 »

Email send successfully but i want to send user name with email.you can see that in $messege i have to send selected user name, middle name and last name. so how is it possible
borre
Forum Newbie
Posts: 10
Joined: Thu Oct 02, 2014 7:21 am

Re: fetch data send in email messege part

Post by borre »

Hey,

You don't have to use <?php & ?> tags inside PHP.

Try this instead.

Code: Select all

<?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 ".$row['first_name']." ".$row['middle_name']." ".$row['last_name']." \n\n
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();
} ?>
As you see I removed the opening and closing PHP tags inside $message.
Post Reply