我使用 PHP 和 MySQL 创建了一个个人消息传递系统。系统的一部分允许向适合特定组的人发送组电子邮件。
发送电子邮件的代码是:
session_start();
include_once('../../dbconnect.php');
$email=$_SESSION['email'];
$to = $_POST ['touser'];
$toemail = $_POST['touseremail'];
$from = $_SESSION['name'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$time = time();
if ($to == 'Level 4'){
$usersquery = "SELECT email FROM users WHERE account = 'Level4'";
$getusers = $conn -> query($usersquery);
while ($row = $getusers->fetch_assoc()){
foreach ($row as $value){
$query ="INSERT INTO messages (to_user, to_email, subject, message, from_user, from_email, daterecord) VALUES ('" . $to . "', '" . $value . "', '" . mysqli_real_escape_string($conn, $subject) . "', '" . mysqli_real_escape_string($conn, $message) . "', '$from', '$email', '$time')";
$send = $conn -> query($query);
}
}
}
这很好用,但问题是当我打开发件箱时,会显示每条单独的消息 - 当一大群人收到消息时,这会堵塞发件箱并且非常烦人!发件箱的代码是:
$emailquery = "SELECT * FROM messages WHERE from_email = '$email' AND sent_deleted = 'no' ORDER BY daterecord DESC";
$sentemails = $conn->query($emailquery);
$emailcount = $sentemails ->num_rows;
if ($emailcount == 0){
echo '<div>No messages sent</div>';
}
else{
?>
<table class="udtable">
<tr>
<th class="reqhead">To</th>
<th class="reqhead">Subject</th>
<th class="reqhead"></th>
</tr>
<?
$i=1;
while ($sent = $sentemails->fetch_assoc()){
if ($i%2 != 0){
$rowclass = 'reqodd';
}
else {
$rowclass = 'reqeven';
}
echo ' <tr class = "' . $rowclass . '">
<td class="reqfrom">' . $sent['to_user'] . '</td>
<td class="reqsubj">' . $sent['subject'] . '</td>
<td class="req"><a id="link' . $sent['id'] . '" href="#" class="sentopen">Open</a></td>
<td class="reqmessage"><pre class=sentboxmessage>' . $sent['message'] . '</pre></td>
<td class="reqid">' . $sent['id'] . '</td>
</tr>';
$i++;
}
?>
</table>
<?
}
?>
发件箱如下所示:
我想将所有这些消息合并到一行中。
有任何想法吗?
谢谢!