searls03 Posted November 15, 2011 Share Posted November 15, 2011 Ok I have a code for email here: <?php if($_POST['submit']){ $to = "$member[email]"; // Change this to your site admin email $from = "announcements@troop78.infiniteserve.com"; $subject = "You have a new message waiting on your dashboard!"; //Begin HTML Email Message where you need to change the activation URL inside $message = 'Hello, You have a new message awaiting on your dashboard. Please login with your userid to see more. Thank you.'; // end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; $to = "$to"; // Finally send the activation email to the member mail($to, $subject, $message, $headers); // Then print a message to the browser for the joiner } ?> then I have a list of recipients for messages. This code will select who will post a message on the user's dashboard. the ultimate goal is that an email will be sent out to whoever is selected too......so that they know there is a message. here is the code.....I don't know if it is written properly: <?php $select = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($select)) { echo '<input type="checkbox" name="user[]" value="'.$member[name].'"><input type="hidden" name="email[]" value="'.$member[email].'">'.$member[name].'<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/251159-send-email-to-array/ Share on other sites More sharing options...
SchweppesAle Posted November 15, 2011 Share Posted November 15, 2011 Something like this? if(isset($_REQUEST['task'])) { case 'email_recipients': $result = email_recipients($_REQUEST['member_emails']); //add error checking print '<h3>Emails sent out successfully</h3>'; break; } function email_recipients($email_array) { if(is_array($email_array)) { $headers = //blah; $subject = blah; $from = blah; foreach($email_array as $recip_email) { mail($recip_email, etc); } } } print ' <form action = "" method = "post" >'; $res = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($res)) { print '<input type = "checkbox" name = "member_emails[]" value = "'.$member['email'].'" /> '.$member['email'].' <br/>'; } print ' <input type = "hidden" name = "task" value = "email_recipients" /> <input type = "submit" value = "submit" /> </form>'; Quote Link to comment https://forums.phpfreaks.com/topic/251159-send-email-to-array/#findComment-1288244 Share on other sites More sharing options...
Zane Posted November 15, 2011 Share Posted November 15, 2011 You'd be better off using BCC headers if you're going to do a mass email. Calling the mail() function X amount of times will just make your script X times slower. BCC stands for Blind Carbon Copy if you didn't already know. if you want the other users to see all the subscribers then just use CC so for instance, with your code foreach($email_array as $recip_email) { $headers .= "\r\nBCC:" . $recip_email . "\r\n"; } Then just put the headers variable in your ONE mail function. Quote Link to comment https://forums.phpfreaks.com/topic/251159-send-email-to-array/#findComment-1288247 Share on other sites More sharing options...
searls03 Posted November 15, 2011 Author Share Posted November 15, 2011 I get an error saying unexpected t_CASE on line 59...... <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="/login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } ?> <?php if ($_POST[user]){ foreach ($_POST[user] as $key => $value){ // [..] code that adds the message to the database $content = $_POST['content']; $from = $_POST['from']; $subject = $_POST['title']; $query ="insert into messages(title, content, recipient, from1) VALUES ('$subject', '$content', '$value','$from')"; mysql_query($query) or die('Error, query failed'); } } ?> <?php if(isset($_REQUEST['task'])) { case 'email_recipients': $result = email_recipients($_REQUEST['member_emails']); //add error checking print '<h3>Emails sent out successfully</h3>'; break; } function email_recipients($email_array) { if(is_array($email_array)) { $headers = //blah; $subject = blah; $from = blah; foreach($email_array as $recip_email) { mail($recip_email, etc); } } } print ' <form action = "" method = "post" >'; $res = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($res)) { print '<input type = "checkbox" name = "member_emails[]" value = "'.$member['email'].'" /> '.$member['email'].' <br/>'; } print ' <input type = "hidden" name = "task" value = "email_recipients" /> <input type = "submit" value = "submit" /> </form>'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template2.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <style type="text/css"> body { background-image: url(button/boyscout1.png); background-repeat: no-repeat; position: relative; } #menu { position:relative; left:160px; top:0px; width:931px; height:59px; z-index:19; } #menu #MenuBar1 li a { color: #000; border-top-style: outset; border-right-style: outset; border-bottom-style: outset; border-left-style: outset; width: 100px; } #status { position:relative; left:16px; top:180px; width:124px; height:44px; z-index:14; } </style> <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } </script> <!-- InstanceBeginEditable name="head" --> <style type="text/css"> #editregion { position:absolute; left:-8px; top:272px; width:1293px; height:51px; z-index:1; clear: none; float: none; } body { background-image: url(file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/button/boyscout1.png); background-repeat: no-repeat; position: relative; } #menu { position:relative; left:160px; top:0px; width:931px; height:59px; z-index:19; } #menu #MenuBar1 li a { color: #000; border-top-style: outset; border-right-style: outset; border-bottom-style: outset; border-left-style: outset; width: 100px; } #status { position:relative; left:16px; top:180px; width:124px; height:44px; z-index:14; } </style> <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <script src="Scripts/tiny_mce/tiny_mce.js" type="text/javascript"></script> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } </script> <style type="text/css"> body { background-image: url(button/boyscout1.png); } </style> <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #logout { position:relative; left:0px; top:0pxpx; width:134px; height:38px; z-index:20; font-weight: bold; font-size: 24px; } #logout a { color: #000; } #status { text-align: center; } #logout1 { position:absolute; left:1071px; top:191px; width:224px; height:61px; z-index:2; } #menu2 { position:absolute; left:-1px; top:172px; width:497px; height:92px; z-index:20; } #footer { position:fixed; left:-10px; top:0px2 width:1290px; height:63px; z-index:200; color: #000; background-color: #000; right: 0px; bottom: 0px; } </style> <script type="text/xml"> <!-- <oa:widgets> <oa:widget wid="2204022" binding="#postContent" /> </oa:widgets> --> </script> <!-- InstanceEndEditable --> <!-- InstanceParam name="id" type="text" value="apDiv6" --> <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #logout { position:relative; left:0px; top:0pxpx; width:134px; height:38px; z-index:20; font-weight: bold; font-size: 24px; } #logout a { color: #000; } #status { text-align: center; } #logout1 { position:absolute; left:1071px; top:191px; width:224px; height:61px; z-index:2; } #menu2 { position:absolute; left:-1px; top:172px; width:497px; height:92px; z-index:20; } * { padding: 0; } html, body { height: 100%; } .wrapper { min-height: 100%; height: auto !important; height: 100%; padding: 0 auto -4em; } .footer, .push { height: 4em; clear: both; } </style> </head> <body> <div id="menu2"><div id="menu"> <ul id="MenuBar1" class="MenuBarHorizontal"> <li><a href="myprofile.php">My Profile</a> </li> <li><a href="register.php">Register</a></li> <li><a href="dashboard.php">Dashboard</a> </li> <li><a href="news.php">News</a></li> <?php if ($accounttype == "Admin") { ?> <li><a href="membermanager.php">Scout Manager</a></li> <li><a href="eventmanager.php">Event Manager</a></li> <li><a href="newsmanager.php">News Manager</a></li> </ul><?php } ?><?php if ($accounttype == "Scout Master") { ?> <li><a href="membermanager.php">Scout Manager</a></li> <li><a href="eventmanager.php">Event Manager</a></li> <li><a href="newsmanager.php">News Manager</a></li> </ul><?php } ?> </div></div> <div id="logout1"><div id="logout"><a href="logout.php">Logout</a></div></div> <div id="status"><?php echo "$accounttype"; ?> <br /><?php echo "$name"; ?> <p> </p> </div><br /><br /><br /><br /><br /><br /><br /><br /><br /> <br /> <br /> <!-- InstanceBeginEditable name="EditRegion3" --> <form id="form1" name="form1" method="post" action="newmess.php"> <center> <table width="323" border="0" cellspacing="2" cellpadding="2"> <tr> <th width="58" scope="col">Subject: <label for="subject"></label></th> <td width="245" scope="col"><input type="text" name="title" id="subject" /></td> </tr> <tr> <th> </th> <td> </td> </tr> <tr> <th> Recipient(s):<br /></th> <td><?php $select = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($select)) { echo '<input type="checkbox" name="user[]" value="'.$member[name].'"><input type="hidden" name="email[]" value="'.$member[email].'">'.$member[name].'<br>'; } ?></td> </tr> <tr> <td><label for="content2">Content:</label></td> <td><script type="text/javascript"> // BeginOAWidget_Instance_2204022: #postContent tinyMCE.init({ // General options mode : "exact", elements : "postContent", theme : "advanced", skin : "default", plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave", // Theme options theme_advanced_buttons1 : "save,newdocument,print,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect,", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,|,image,media,|,forecolor,backcolor,|,insertdate,inserttime,", theme_advanced_buttons3 : "hr,cite,abbr,acronym,del,ins,sub,sup,visualchars,nonbreaking,charmap,emotions,ltr,rtl,|,code,preview,fullscreen,help,cleanup,removeformat,|,styleprops,attribs,", theme_advanced_buttons4 : "tablecontrols,visualaid,|,insertlayer,moveforward,movebackward,absolute,visualaid,|,template,pagebreak,restoredraft,", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, // Example content CSS (should be your site CSS) content_css : "/css/editor_styles.css", // Drop lists for link/image/media/template dialogs, You shouldn't need to touch this template_external_list_url : "/lists/template_list.js", external_link_list_url : "/lists/link_list.js", external_image_list_url : "/lists/image_list.js", media_external_list_url : "/lists/media_list.js", // Style formats: You must add here all the inline styles and css classes exposed to the end user in the styles menus style_formats : [ {title : 'Bold text', inline : 'b'}, {title : 'Red text', inline : 'span', styles : {color : '#ff0000'}}, {title : 'Red header', block : 'h1', styles : {color : '#ff0000'}}, {title : 'Example 1', inline : 'span', classes : 'example1'}, {title : 'Example 2', inline : 'span', classes : 'example2'}, {title : 'Table styles'}, {title : 'Table row 1', selector : 'tr', classes : 'tablerow1'} ] }); // EndOAWidget_Instance_2204022 </script> <!-- Textarea gets replaced with TinyMCE, remember HTML in a textarea should be encoded --> <textarea id="postContent" name="content" rows="15" style="width:80%"></textarea></td> </tr> <tr> <td><input type="hidden" name="from" id="from" value='<?php echo $name; ?>' /></td> <td><input type="submit" name="submit" id="submit" value="Post" /></td> </tr> </table></center> <p> </p> <p> </p> <p> </p> <p> </p> </form> <!-- InstanceEndEditable --> <div class="push"></div></div> <div class="footer"><?php if($accounttype == "Admin"){include_once "footer-ad.php";}else if($accounttype == "Scout Master"){ include_once "footer-ad.php";} else if($accounttype == "Scout") { include_once "footer-sc.php"; } ?> </div> <script type="text/javascript"> var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"}); </script> </body> <!-- InstanceEnd --></html> is this the way I would set the code up? Quote Link to comment https://forums.phpfreaks.com/topic/251159-send-email-to-array/#findComment-1288465 Share on other sites More sharing options...
searls03 Posted November 15, 2011 Author Share Posted November 15, 2011 and how would I replace the form I have set up for name select to work with the one you guys gave me? Quote Link to comment https://forums.phpfreaks.com/topic/251159-send-email-to-array/#findComment-1288469 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.