akmoney Posted August 26, 2018 Share Posted August 26, 2018 (edited) I need you to help me take a look at this PHP code. It's a broadcast code. I use it to add a feature to send bulk messages emails on the database. One issue I had was that when emails are sent all the resipent show. Which is wrong. <?php include_once "../core/kernel.php"; include_once '../view/head.php'; use Taxcoin\Notification\Notification; use Taxcoin\User; use Taxcoin\wallet; $user = @new User(); $user->moderateUser(); $wallet = @new wallet($user->userId); $transaction_home = new Taxcoin\Transactions(); $transaction_home->user_id = $user->userId; $action = @$_GET['action']; $uid = @$_GET['uid']; $setup = new \Taxcoin\Setup(); ?> <body class="w3-light-grey"> <?php include_once '../view/admin-side-bar.php'; ?> <div class="w3-row-padding"> <div class="w3-col m6 w3-section"> <div class="w3-white w3-round"> <div class="w3-padding w3-container"> Pending Cash Inflow </div> <div class="w3-xlarge w3-teal w3-padding w3-padding-24"> <?=number_format($transaction_home->total_pending_blocks)?> TXC </div> </div> </div> <div class="w3-col m6 w3-section"> <div class="w3-white w3-round"> <div class="w3-padding w3-container"> Active Cash InFlow </div> <div class="w3-xlarge w3-teal w3-padding w3-padding-24"> <?=number_format($transaction_home->total_active_blocks)?> TXC </div> </div> </div> </div> <div class="w3-container w3-row"> <div class="w3-white w3-col s6"> <div class="w3-container w3-responsive " style="float: none;"> <h3>Send Broadcast Message</h3> <?php if ($_POST){ try{ $notify = new Notification(); $notify->recipient = $user->mail_list; $notify->sender["name"] = "Blockfreelancer.com"; $notify->sender["email"] = "support@xxxx.com"; $notify->title = $_POST['title']; $notify->body = "<html><body> <div style='background: #156abf; color: white; padding-top: 10px; padding-bottom: 10px; text-align: center;'><h1>Newsletter</h1></div><div style='padding: 15px;background: #156abf;'><div style='background: white;padding: 10px;'><p>".$_POST['content']."</p> <br> Warm regards <br> Team <br> <br> Facebook: <a href='https://www.facebook.com//'>Join us on Facebook</a> <br> Telegram: <a href='https://t.me/joinchat/'>Join us on Telegram</a><br><br></div><div style='padding: 20px; text-align: center;'><b>© 2018 - xxx.com</b></div> </div></body></html> "; if($notify->mail()){ echo "<div class='w3-padding w3-panel w3-blue'>Mail successfully sent to all users.</div>"; }else{ echo "<div class='w3-padding w3-panel w3-red'>Unable to send mail</div>"; } }catch (Exception $e){ echo "<div class='w3-padding w3-panel w3-red'>{$e->getMessage()}</div>"; } } ?> <form method="post" action="#"> <p> <label>Title</label> <input type="text" name="title" class="w3-input w3-round w3-border" required/> </p> <p><label>Letter Content</label> <textarea type="text" name="content" class="w3-input w3-round w3-border" rows="4" required></textarea> </p> <p> <input type="submit" value="Send Message" class="w3-btn w3-xlarge blue-bg w3-round"> </p> </form> </div> </div> </div> </body> <script type="text/javascript"> $(document).ready(function() { $('#example').DataTable(); } ); </script> </html> Edited August 26, 2018 by Barand Code tags added Quote Link to comment Share on other sites More sharing options...
requinix Posted August 26, 2018 Share Posted August 26, 2018 Well, the recipient would be $user->mail_list, which by the sounds of it is either an array of recipient addresses or one address corresponding to a mailing list. Which is it? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 26, 2018 Share Posted August 26, 2018 Did you write this code? If you did, have you considered the use of a BCC instead of the standard "TO" for your address list? Seems ridiculously simple to make this change so I am surprised that you need our help. Am I missing something? And - it's "recipient". Quote Link to comment Share on other sites More sharing options...
akmoney Posted August 26, 2018 Author Share Posted August 26, 2018 Not my coding sir. That's why I need your help. Thanks for the quick response. Kindly assist in formatting it. Warm Regards Quote Link to comment Share on other sites More sharing options...
akmoney Posted August 26, 2018 Author Share Posted August 26, 2018 5 hours ago, requinix said: Well, the recipient would be $user->mail_list, which by the sounds of it is either an array of recipient addresses or one address corresponding to a mailing list. Which is it? Resipent addresess Quote Link to comment Share on other sites More sharing options...
requinix Posted August 26, 2018 Share Posted August 26, 2018 Then either a) Have it send an email to each address instead of to all the addresses, or b) Use BCC like ginerjm said How you do that depends on whatever that Notification class is. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 26, 2018 Share Posted August 26, 2018 So - you have some 3rd party code and you either can't or won't figure out how to modify it and you want us to do it? Examine the code where it places the actual addresses into the email build process. That's how we would do it in the same situation. And - we can't do it from here. Have fun! PPS - It's "recipient". At least you can change your spelling I assume? Quote Link to comment Share on other sites More sharing options...
akmoney Posted August 26, 2018 Author Share Posted August 26, 2018 Here is what the notification class looks like. <?php /** * Created by PhpStorm. * User: HP * Date: 7/9/2017 * Time: 3:50 PM */ namespace Taxcoin\Notification { class Notification { public $recipient; public $body; public $title; public $sender = array(); function mail($html = true)//whether to use HTML email or not { $headers = ""; $headers .= "From: {$this->sender['name']} <{$this->sender['email']}>" . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= 'X-Mailer: PHP/' . phpversion(); if(!@mail($this->recipient, $this->title, $this->body, $headers)){ throw new \Exception("Unable to send email",1); } return true; } function SMS() { } } } Thanks for your quick response Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 26, 2018 Share Posted August 26, 2018 Ok - If you look at this code and READ THE MANUAL ON the Mail Function: $headers = ""; $headers .= "From: {$this->sender['name']} <{$this->sender['email']}>" . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= 'X-Mailer: PHP/' . phpversion(); if(!@mail($this->recipient, $this->title, $this->body, $headers)){ throw new \Exception("Unable to send email",1); You can learn how to 1 - NOT use the @ symbol 2 - How to specify BCC's in your headers 3 - use a dummy address or perhaps a specific address of your own to use as the To address 4 - to solve your problem. Have at it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.