kenwvs Posted October 7, 2006 Share Posted October 7, 2006 I have a form that gets completed and then I want to email the results of the form to different people. The person completing the form will choose who they want to send the results to. I have a dropdown box, where the list of names used is obtained from the database.Is there a way, that when a person hilites multiple names that the email can be sent to these people.Here is what I have for the dropdown box.[CODE]<div> <center><B>Send this form to:</B><BR> <select name='tech' multiple> <?php $result = mysql_query("SELECT * FROM employees") or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<option>$row[name]</option>"; }[/CODE]Once you have selected who the email goes to, and completed the form, I want to create a query that will send the email to these people when you press the submit button for the rest of the form. The data is being saved in a database, but I don't have it set up to save the names of the people receiving an email (although I could if necessary.)Thanks for any help as this has me totally stumped.Ken Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 7, 2006 Share Posted October 7, 2006 The name of the select needs to be an array ... fully explained with example code at http://onlinetools.org/tricks/using_multiple_select.php Quote Link to comment Share on other sites More sharing options...
kenwvs Posted October 7, 2006 Author Share Posted October 7, 2006 If I use an array and do this, I will end up with something like this..........[code]<div> <center><B>Send this form to:</B><BR> <select name='emailname[]' multiple="multiple"> <?php $result = mysql_query("SELECT * FROM employees") or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<option>$row[name]</option>"; }$emailname=$_POST['emailname']; if ($emailname){ foreach ($emailname as $ename); } ?></select></center>[/code]Would I then be able to do something like this to get the email addresses into the TO field of the email script:SELECT email from employees where $ename=name;email is the column name in the DB table and name is the column title where the name is found.Thanks,Ken Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 i dont get it do you mean this select the members emails withn a pualldown list then be able to use the email of the user?example[code]<div> <center><B>Send this form to:</B><BR> <select name='emailname[]' multiple="multiple"> <?php $result = mysql_query("SELECT email FROM employees") or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<option>$row[email]</option>"; }?></select></center>[/code]might be wrong here only guessing. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted October 7, 2006 Author Share Posted October 7, 2006 The dropdown box has a list of names (not email addresses) that it has gotten from the employee table of the database. Once you select which names you want to send an email to, I need to get the email addresses from the employee table, to actually send the email. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 so dont you just say$row['name']=$row['email'];then the email code[code]<div> <center><B>Send this form to:</B><BR> <select name='emailname[]' multiple="multiple"> <?php $result = mysql_query("SELECT * FROM employees") or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo "<option>$row[name]</option>"; $row['name']=$row['email'];} ?></select></center>[/code] Quote Link to comment Share on other sites More sharing options...
kenwvs Posted October 7, 2006 Author Share Posted October 7, 2006 I will try that. I have no idea how to do this, as I am new at all of this. I have never used the mail function, and this is the first DB project I have ever worked on. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 i thort that you select the users name then you do another selct email from users were username is ='$name'then the email code sure of it. Quote Link to comment Share on other sites More sharing options...
kenwvs Posted October 7, 2006 Author Share Posted October 7, 2006 I am sorry, but I am not following what you have just said.Ken Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 some think like this i am sure that when you select a name you then convert the name intot the users email address then send the email via the user name as it is there email address.example only[code]<div><center><B>Send this form to:</B><BR><select name='emailname[]' multiple="multiple"><?php$result = mysql_query("SELECT * FROM employees") or die(mysql_error());while ($row = mysql_fetch_assoc($result)) {echo "<option>$row[name]</option>"; }foreach ($emailname as $ename); $ename=$row['email'];</select></center>$to = $ename;$subject = 'the subject';$message = 'hello';$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();mail($to, $subject, $message, $headers);?>[/code] Quote Link to comment Share on other sites More sharing options...
kenwvs Posted October 7, 2006 Author Share Posted October 7, 2006 Ok, I see what you are saying. Thanks a bunch for the help. It is starting to make sense now. I appreciate your help.Ken Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 this should defently work[code]<div><center><B>Send this form to:</B><BR><select name='emailname[]' multiple="multiple"><?php$result = mysql_query("SELECT * FROM employees") or die(mysql_error());while ($row = mysql_fetch_assoc($result)) {echo "<option>$row[name]</option>"; }foreach($emailname as $ename); $result2 = mysql_query("SELECT email FROM employees where ename='$ename'") or die(mysql_error());while ($a = mysql_fetch_assoc($result2)) {$email=$a['email'];</select></center>$to = $email;$subject = 'the subject';$message = 'hello';$headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();mail($to, $subject, $message, $headers);}?>[/code] Quote Link to comment Share on other sites More sharing options...
kenwvs Posted October 8, 2006 Author Share Posted October 8, 2006 I have tried using the last script supplied, but for some reason it isn't sending an email. I have also added the line [code=php:0]echo 'Email has been sent to'.$_POST[$ename];[/code] to see what it shows and it prints out the Email has been sent to, but there is no names in there.Am I missing a step as far as setting the email address of something for it to use it? I am not really sure what I would need to change to make this actually send the email. the rest of the form is being saved to the Db, so it is making a connection and not generating any errors.Any ideas or suggestions would be appreciated. Would I need to save the names to a db table before it could send the email?Thanks,Ken 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.