Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to send message to multiple users inside a input field form

    I've search every where for an answer but can't find it. I have created a personal mail system for a website. A user basically sends another user a message and its stored inside a mysql database and not a url based e-mail system. The code below works fine but it can only sends a message to one user or as you might call recipient but canno't send to multiple users. I wanted to add the user's name inside the input field and seperate each user by a comma so that the message in stored in the mysql database and sent to each user that is typed.




    <?php
    include('connector.php');
    ?>









    PHP Code:










    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>How To Use jQuery Lightbox With A Database</title>
    </head>
    <body>
    <div>You may click the images below.</div>
    <div id="gallery"> <!-- id to detect images for lightbox -->

    <?php
    // if something was posted, start the process... 
    if(isset($_POST['submit'])) 



    // define the posted file into variables 

     
    $message=$_POST['message']; 
     
    $title=$_POST['title']; 
    $recip=$_POST['recip'];
    $username   $_SESSION['username'];
    $id      $_SESSION['id'];
    $who=$_POST['who']; 
    $what=$_POST['what'];


    $name $_FILES['file']['name']; 
    $tmp_name $_FILES['file']['tmp_name']; 
    $type $_FILES['file']['type']; 
    $size $_FILES['file']['size']; 


      
    //We check if the recipient exists
                    
    $dn1 mysql_fetch_array(mysql_query('select count(id) as recip, id as recipid, (select count(*) from pm) as npm from header where username="'.$recip.'"'));
                    if(
    $dn1['recip']==1)
                    
                             echo 
    'recip exists';
                             
                             
                             
                    else
                    {
                            
    //Otherwise, we say the recipient does not exists
                            
    $error 'The recipient does not exists.';
                    
                    }
                    

          
                            
                                    
    //We send the message
                            
                                    // open up the file and extract the data/content from it 
    $extract fopen($tmp_name'r'); 
    $content fread($extract$size); 
    $content addslashes($content); 
    fclose($extract);  

    include_once(
    'connect.php');
    // the query that will add this to the database 

                                    
    mysql_query('insert into pm (id, id2, title, name, size, type, content, who, what,  user1, user2, message, timestamp, user1read, user2read)values("'.$id.'", "1", "'.$title.'", "'.$name.'", "'.$size.'", "'.$type.'", "'.$content.'", "'.$who.'",  "'.$what.'", "'.$_SESSION['id'].'", "'.$dn1['recipid'].'", "'.$message.'", "'.time().'", "yes", "no")')
                            
                    
                         or die (
    mysql_error());        
                                    
                    
                    


    mysql_close();  

    echo 
    "Successfully uploaded your picture to database also!";       
    }

        
                            
    ?>

    <a href="list_pm.php">List of my Personal messages</a></div>


    <div class="content">
          <form action="stn.php" method="post" enctype="multipart/form-data" name="data">  <h1>New Personal Message</h1>
        
                    Please fill the following form to send a Personal message.<br />
            
            <label for="recip">Recipient<span class="small">(Username)</span></label><input type="text" value="<?php echo htmlentities($orecipENT_QUOTES'UTF-8'); ?>" id="recip" name="recip" /><br />
           
            
          
            
            
            
    Upload your file to the database...
           
            
            <tr>
              
              <td><div align="right">when:</div></td>
              <td><input name="message" type="text" id="message"  size="80" maxlength="80" /></td>
              
      </tr>        
            
        <tr>
     <td><div align="right">when:</div></td>
              <td><input name="who" type="text" id="who"  size="80" maxlength="80" /></td>
               
            </tr>
            <tr>
              
               
               <td><div align="right">where:</div></td>
              <td><input name="what" type="text" id="what"  size="80" maxlength="80" /></td>
               
            </tr>
            
         <tr>
             
         <input name="submit" type="submit" id="submit" value="submit">
        
        </tr>

            
            
            
            
            
          
            
            
            
            
            
            
            
            
        </form>




    </div>

                    <div class="foot"><a href="list_pm.php">Go to my Personal messages</a> - <a href="http://www.webestools.com/">Webestools</a></div>
            </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,036
    Thanks
    23
    Thanked 589 Times in 588 Posts
    The way I did this was to have the message table with columns to_id (for the recipient) from_id (the sender) and for_all ( means everyone is the recipient).
    In your search for personal messages you include the 'for_all' and mark that message as such.

    This allows a single row to store a message for all and not have multiple rows or a add column when new people join the system.
    Evolution - The non-random survival of random variants.

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    You can use a separator in the form field, e.g. , : | and explode it at the server to make an array of the entries..
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #4
    New Coder
    Join Date
    May 2012
    Posts
    30
    Thanks
    10
    Thanked 1 Time in 1 Post
    seprate usernames with a special char . and then explode them . then run a for each loop to send ....

    see this example ..
    PHP Code:

    $to 
    "userA,userB,userC,userD";
    $toArr explode(","$to);
    foreach(
    $toArr as $to) {

    YourMessageSendingLogic($to);
        
       } 
    hope this will help .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •