خرید بک لینک
I'm trying to figure a way to allow members of a website to send email messages via the system without allowing the member to see the email addresses. They should be able to select either just one user, or a number of them, or all of them if they want.

I've got as far as successfully outputting the member data from the mySQL database but can't figure how to get the checkbox values (i.e email addresses, comma separated) into the message.

I've made the recipient a no-reply address and the list of email addresses a BCC, to stop recipients harvesting the addresses.

I just need to know how I can input the checkbox values in, however many the member selects. I found some solutions but none were quite what I was looking for or they just didn't work for whatever reason. Any ideas? Thanks!

Code:

<?php
$mysqli = new mysqli("coection details...");

if($mysqli->coect_errno > 0){
    die('Unable to coect to database [' . $mysqli->coect_error . ']');
}

$username = $user->get('username'); //this just grabs the username for the logged-in member

$getuseremail = $mysqli->query("SELECT * from members WHERE Username LIKE '$username'"); //get the member's email address, so the message will appear to come from that email address
        while ($row = $getuseremail->fetch_assoc()) {
                $useremail = $row["Email"];
                $count++;
        }

$getmembers = $mysqli->query("SELECT * FROM members WHERE IsArchived NOT LIKE 'Y' ORDER BY MemberID DESC");
               
                if ($getmembers->num_rows == 0) {
                                echo '<p>There are no members on the system at the moment.</p>';
                        }
?>
<h1>Send a message to other Members</h1>
<p>Using your email: <?php echo $useremail; ?></p>
<form name="sendmessage" action="send-message-to-members.html" method="post">
<?php
if( isset($_POST['checkbox']) && !empty($_POST['checkbox']) )
  {
 $list = $_POST['checkbox'];
 $to = $list;
 $subject = "Message from Member";
 $body = "$_POST['messagetext'];";
 $headers = "From: " .$useremail;
 "X-Mailer: php";

 $to =  "[email protected]";
 $headerFields = array('BCC: '.$list.', "From: ".$useremail."X-Mailer:    php"');
 if (mail($to, $subject, $body, implode("rn", $headerFields))) {
 //if (mail($to, $subject, $body, $headers)) {
  echo("<p>Message sent successfully</p>");
  } else {
  echo("<p>Message delivery failed...</p>");
  }
  exit();
  }

// display the results returned
while ($row = $getmembers->fetch_assoc()) { 
  $memberid = $row["MemberID"];
  $firstname = $row["FirstName"];
  $surname = $row["Surname"];
  $email = $row["Email"];
?>
        <input type="checkbox" name="checkbox[]" id="email1" value=<?php echo $email;?> /><a href="" onclick=""><?php echo $firstname.' '.$surname;?></a><br>
<?php
        $count++ ;
}
<textarea name="messagetext" rows="10" cols="40"></textarea>
<input name="sendmessage" type="submit">
</form>

برچسب: نویسنده: آیلین رضوانی تاريخ: سه شنبه 14 شهريور 1396 ساعت: 18:46

صفحه بندی