Friday 13 September 2013

sending message to multiple users using php and mysql

sending message to multiple users using php and mysql

I need help. I'm trying to send a message to multiple users or you might
call recipients. So far the code below works to send a message to one
recipients only. I want to use a regular form where the usernames name can
be separated by a comma and than a message or messages can be sent to all
the users while being stored in a mysql database. Its a database based
email system and not a send to a different e-mail address system.
I have gotten commas to separate the usernames inside the username field
using jquery but than i get stuck after that.
<?php
include('connector.php');
?>
<!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'];
//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
;
include_once('connector.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="dddd.php">List of my Personal messages</a></div>
<div class="content">
<form action="importantnotice.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($orecip, ENT_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.add.com/">Webestools</a></div>
</body>
</html>

No comments:

Post a Comment