arbitter Posted February 22, 2010 Share Posted February 22, 2010 I want this simple php form which allows me to send mails to all of my contacts or all of my selected contacts. This is what I have: <html> <?php if(isset($_POST['actie'])) {echo 'actie'; $persoon = $_POST['persoon']; echo $persoon; exit(); } ?> <form method="post" action="mail.php"> <b>Recipients:</b><br> <input type="checkbox" name="person" value="Everybody">Everybody<br> <?php require_once('mysql_connect.inc.php'); mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die("Verbinding mislukt: " . mysql_error()); mysql_select_db("users") or die("Couldnt open: " . mysql_error()); $query = "SELECT name, email FROM users"; $result = mysql_query($query)or die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<input type='checkbox' name='persoon' value='" . $row['email'] . "'>" . $row['name'] . "<br>"; } ?> <b>Message:</b><br> <textarea rows="5" cols="20" name="message"> </textarea><br> <input type="submit" value="Email Myself" name='actie'> </form> </html> Now, part of this is already working; I want to get a list of all my contacts, and I do indeed get a list of all my contacts With the php part where I connect with my database. The problem is, that I need to get all the data of the 'person' part in the form. I need all of the emails (that I selected), because I need to send my mail to all of them. Anyone a little help? Quote Link to comment Share on other sites More sharing options...
manohoo Posted February 22, 2010 Share Posted February 22, 2010 Your query is only retrieving NAME and EMAIL, so that's the only data that you can display in your form. Right now you only display NAME. If you want to display NAME and EMAIL do this: echo "<input type='checkbox' name='persoon' value='" . $row['email'] . "'>" . $row['name'] .' '.$row['email'] "<br>"; Quote Link to comment Share on other sites More sharing options...
arbitter Posted February 22, 2010 Author Share Posted February 22, 2010 Yes, I am aware of that. But I don't need to display the email. I have the checkboxes, with a value of an email. Next to the checkbox it gives the name of the person who's email it is, so I can see whom I'd like to send it to. Now, when I click the submit button, the message should be sent to all selected recepients, or if I click everybody, to everybody. How do I do that? For the textarea; <?php $message = $_POST['message']; $message = strip_tags($message); $message = trim($message);?> But for the checkboxes, $_POST['person'] ,can only give one result? Or how does this work? Quote Link to comment Share on other sites More sharing options...
arbitter Posted February 22, 2010 Author Share Posted February 22, 2010 Okay, I've found it. if(isset($_POST['action'])) { $person = $_POST['person']; foreach($person as $mail){echo $mail;} exit(); } 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.