SEVIZ Posted April 16, 2009 Share Posted April 16, 2009 Ok here is what I have and what I need to do. I have a simple form that works fine. Here is the code: <?php if ($_POST["email"]<>'') { $ToEmail = '5555555555@messaging.sprintpcs.com'; $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = nl2br($_POST["message"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); ?> <font color="red"><b>Your Text has been sent. The message sent was:</b></font><br /><br /> <font face="tahoma" size="4"><?php echo $_POST["message"]; ?></font> <br /><br /> - <b><a href="text.php">GO BACK</a></b> <?php } else { ?> <!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"> <head> <meta content="en-us" http-equiv="Content-Language" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Text Tool</title> <style type="text/css"> .style1 { text-align: center; } </style> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) // if too long...trim it! field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter else countfield.value = maxlimit - field.value.length; } // End --> </script> </head> <body> <form action="text.php" method="post"> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td valign="top"> Send To:<br /> <select name="recip"> HERE IS WHERE THE OPTIONS WOULD BE DEPENDING ON HOW I NEED TO GET THEM HERE. Either hard coded or by query </select> </td> </tr> <tr> <td>Message:<br /><textarea name=message wrap=physical onKeyDown="textCounter(this.form.message,this.form.remLen,143);" onKeyUp="textCounter(this.form.message,this.form.remLen,143);" cols="20" rows="6" id="comment" maxlength="143"></textarea><br /><input readonly type=text name=remLen size=3 maxlength=3 value="143" /> characters left </td> </tr> <tr> <td> <input name="email" type="hidden" id="email" size="20" value="r@site.com"></td> </tr> <tr> <td valign="top"><font color="red" size="2"><b>Do not hit enter for a new line. This will give you less characters to use due to the text limits.</b></font><br /><input type="submit" name="Submit" value="Send"></td> </tr> </table> </form> </body> </html> <?php }; ?> What it does is emails the message to a cell phone number @messaging.sprintpcs.com. (You can see the mail to address at the very top). This all works great and is good to go. I need to have the drop down at the top pull a query depending on the choice and get the phone numbers to email to. Example: You choose All Sups from the dropdown. On send it queries the database and search's table "sprint" for "sup" in the "dept" row. Once it finds the sups it then outputs the phone number from row "num" to the top of the form under $ToEmail. So if I searched for all SUPS it would email about 9 people. Anyone with the label "sup" in the dept row. Any help is appreciated guys. Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/ Share on other sites More sharing options...
SEVIZ Posted April 16, 2009 Author Share Posted April 16, 2009 I don't know if this should be in mysql section. If so, mods please move it. I just couldn't decide where it made more sense. Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/#findComment-811922 Share on other sites More sharing options...
SEVIZ Posted April 17, 2009 Author Share Posted April 17, 2009 Let me know if I did not explain it right. Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/#findComment-812014 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 $toEmail gets changed based to the $_POST['email'], where email is defined as: <select name="email" ... <option... </select> Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/#findComment-812048 Share on other sites More sharing options...
SEVIZ Posted April 17, 2009 Author Share Posted April 17, 2009 Thanks for the reply! That does a bit of what I need. But now how do I query for the select items? ie. How do I make the value of a select option be pulled from the database? Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/#findComment-812739 Share on other sites More sharing options...
keeB Posted April 17, 2009 Share Posted April 17, 2009 $q = "select * from table_where_emails_are_stored..."; $ret = mysql_query($q); print '<select name="email">'; while ($row = mysql_fetch_assoc($ret)) { $email_addr = $row['email']; print "<option value=\"$email_addr\">$email_addr</option>"; } or something Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/#findComment-812750 Share on other sites More sharing options...
SEVIZ Posted April 18, 2009 Author Share Posted April 18, 2009 This works for query to email. Thank you! Now I can do a new thread for my next issue. Quote Link to comment https://forums.phpfreaks.com/topic/154412-solved-do-a-query-from-a-drop-down-to-email/#findComment-812871 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.