[dx] Posted March 22, 2010 Share Posted March 22, 2010 Hi,What I'm trying to make is small while loop which lists emails and when you check some of them, and then press SEND button, script must check which of them are checked and send email on that address.What I have is <form> tag, and while loop in it which reads from db, and users <input> for checkbox. Selecting from db works fine, but now, main problem is to make script which sends/checks checked addresses and proceed with command.Now what I'm asking you is to suggest me the best way for making this.Regards. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2010 Share Posted March 22, 2010 Use print_r to print out $_POST to see what gets submitted to the form. It sort of depends how you set up the form for how you're going to process it. You may have the checkboxes in an array, where you loop through the array and check the value of each one that was submitted, or you may get the list again from the database and loop through that to check if each one was selected.Why is this in Javascript, by the way? Are you trying to use Javascript to send email? Link to comment Share on other sites More sharing options...
[dx] Posted March 22, 2010 Author Share Posted March 22, 2010 Well no, I'm really not sure which lang is best to use for checking. But I know for PHP's mail function. This is what I've done: <?php$host = "localhost";$user = "user";$db = "database";$pass = "pass";$table = "users";$try = mysql_connect($host, $user, $pass) or die(mysql_error());mysql_select_db($db, $try) or die(mysql_error());$q = mysql_query("SELECT name, email FROM $table") or die(mysql_error());$v = 1;echo '<form name="email-list" method="post" action="#">';while ($r = mysql_fetch_array($q)) { echo '<input type="checkbox" name="' . $v . '" value="' . $r['email'] . '"> ' . $r['email'] . '</input> - Name: ' . $r['name'] . '<br />'; $v++;}echo '<input type="submit" value="SEND" /> </form>';?> Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2010 Share Posted March 22, 2010 Right, so check a few boxes and then use print_r to print $_POST, which will let you see the submitted data. Find out if the data in $_POST is what you need in order to send the emails. Input tags don't have closing tags though, an input tag is supposed to be self-closing.You may also want to store the checkboxes in an array instead, which would give you an array in PHP of the values which were selected. If you want to do that, give your checkboxes the same name followed by [], like "emails[]", and then $_POST['emails'] in PHP will be the submitted array. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.