Hamish Posted May 23, 2007 Share Posted May 23, 2007 Hi All, This is my first attempt at using a dropdown box to submit data. I am trying to use a dropdown box to pass an email address to an email form and then send to the recipient. So far I have: This returns the email addresses to a dropdown box . <body> <select name="txtEmailto2"> <option>Please select a email from the list</option> <? include ("opendbincludeA.php"); $query ="SELECT P_Leader.PLemailAddress FROM P_Leader"; $query = mysql_query($query); $query_row=mysql_num_rows($query); while ($row=mysql_fetch_array($query)) { echo "<option>".$row['PLemailAddress']."</option>"; } ?> </select> </form> </body> The following is a simple email form, which sends an email to the recipient typed in text box. I have tried to use the dropdown box code above to replace the typed input text box without success. I can find no example as to what the syntax should for using the "option". I am hoping someone with more experience with dropdown boxes / php will be able to help. Regards Hamish <?php //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$txtEmailto2; $mail_from=$txtEmailfrm2; $mail_sub=$txtSub2; $mail_mesg=$txtMsg; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2")) echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } ?> <!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 http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> <title>Untitled Document</title> </head> <body> <form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()"> <table width="100%" border="0"> <tr> <td width="33%" align="right" class="text">To : <td width="67%"><input name="txtEmailto2" type="text" class="input" id="txtEmailto22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">From : <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">Subject : <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">Message: <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea> </tr> <tr> <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true"> <td><input name="Submit" type="submit" class="input" value="Send" /> <input name="Submit2" type="reset" class="input" value="Reset" /> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/ Share on other sites More sharing options...
Daniel0 Posted May 23, 2007 Share Posted May 23, 2007 You need a value attribute in the <option> tag. Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259647 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks DanielO for the very quick response I'm sorry I don't understand I'm very new to php. Could you show me an example? Hamish Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259648 Share on other sites More sharing options...
dweir Posted May 23, 2007 Share Posted May 23, 2007 For your pull down option: <select> <option value="name">Option</select> </select> "name" value attribute should match what you are using in your table. Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259749 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks dweir for that, I have tried what you suggested but must not have it right, the dynamic list is displaying outside the box as a list of email addresses, and as such can't be selected. <?php //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$txtEmailto2; $mail_from=$txtEmailfrm2; $mail_sub=$txtSub2; $mail_mesg=$txtMsg; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2")) echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } ?> <!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 http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> <title>Untitled Document</title> </head> <body> <form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()"> <table width="100%" border="0"> <tr> <td width="33%" align="right" class="text">To : <td width="67%"><select><option value="txtEmailto2"> <option>Please select a email from the list</option></select> <? include ("opendbincludeA.php"); $query ="SELECT P_Leader.PLemailAddress FROM P_Leader"; $query = mysql_query($query); $query_row=mysql_num_rows($query); while ($row=mysql_fetch_array($query)) { echo "<option>".$row['PLemailAddress']."</option>"; } ?> </select> </tr> <tr> <td align="right" class="text">From : <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">Subject : <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">Message: <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea> </tr> <tr> <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true"> <td><input name="Submit" type="submit" class="input" value="Send" /> <input name="Submit2" type="reset" class="input" value="Reset" /> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259802 Share on other sites More sharing options...
demon_athens Posted May 23, 2007 Share Posted May 23, 2007 As others said you need to have a value. while ($row=mysql_fetch_array($query)) { echo "<option>".$row['PLemailAddress']."</option>"; } There is no value here. You must have something like this while ($row=mysql_fetch_array($query)) { echo "<option value=".$row['PLemailAddress'].">".$row['PLemailAddress']."</option>"; } Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259809 Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 also... you closed your select tags in there... Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259811 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 I am sorry if I appear stupid and I am just finding my way round php. I have added the option value as suggested, <form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()"> <table width="100%" border="0"> <tr> <td width="33%" align="right" class="text">To : <td width="67%"><select><option value="txtEmailto2"> <option>Please select a email from the list</option></select> <? include ("opendbincludeA.php"); $query ="SELECT P_Leader.PLemailAddress FROM P_Leader"; $query = mysql_query($query); $query_row=mysql_num_rows($query); while ($row=mysql_fetch_array($query)) { echo "<option value=".$row['PLemailAddress'].">".$row['PLemailAddress']."</option>"; } ?> </select> </tr> <tr> <td align="right" class="text">From : <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">Subject : <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100"> </tr> <tr> <td align="right" class="text">Message: <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea> </tr> <tr> <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true"> <td><input name="Submit" type="submit" class="input" value="Send" /> <input name="Submit2" type="reset" class="input" value="Reset" /> </tr> </table> </form> but the returned query is still diplaying outside the dropdown box. Hamish Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259833 Share on other sites More sharing options...
demon_athens Posted May 23, 2007 Share Posted May 23, 2007 the </select> must be after the loop, thats why. remove the </select> from line 6, you're closing it too soon! Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259837 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks sorted that bit, Now populating the dropdown and am able to select an address. The email appears to be sending but does not arrive at the destination. Hamish Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259849 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 Help ! There must be a simple answer to this but I can't see it Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259924 Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 well as far as your code goes... where do these get set? $mail_to=$txtEmailto2; $mail_from=$txtEmailfrm2; $mail_sub=$txtSub2; $mail_mesg=$txtMsg; ? Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259930 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 I thought they were set in the "form table". I copied that bit of code from elsewhere and as I said before that section works on its own. Hamish Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259944 Share on other sites More sharing options...
Wildhalf Posted May 23, 2007 Share Posted May 23, 2007 Here is a mailing script i use the whole time that always works.... $firstname = 'persons name'; $email = 'persons email'; // Let's mail the User! $subject = " Enter Subject Here "; $message = " Enter Subject Here "; $femail = "From: $firstname<$email>"; $remail = "Reply-To: $firstname<$email>"; $headers = $femail . "\r\n" . $remail . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail('Your email Goes Here', $subject, $message, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259946 Share on other sites More sharing options...
taith Posted May 23, 2007 Share Posted May 23, 2007 them should be $_POST variables... Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259947 Share on other sites More sharing options...
Hamish Posted May 23, 2007 Author Share Posted May 23, 2007 This bit of code works fine <?php //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$txtEmailto2; $mail_from=$txtEmailfrm2; $mail_sub=$txtSub2; $mail_mesg=$txtMsg; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from Reply-to:$txtEmailfrm2")) echo "<span class='textred'>E-mail has been sent successfully from $mail_sub to $mail_to</span>"; else echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } ?> <!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 http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> <title>Untitled Document</title> </head> <body> <p> </p> <form action="" method="post" name="frmsendmail" id="frmsendmail" onsubmit="return ValidationForm()"> <table width="100%" border="0"> <tr> <td width="33%" align="right" class="text">To : </td> <td width="67%"><input name="txtEmailto2" type="text" class="input" id="txtEmailto22" size="30" maxlength="100" /> </td> </tr> <tr> <td align="right" class="text">From : </td> <td><input name="txtEmailfrm2" type="text" class="input" id="txtEmailfrm22" size="30" maxlength="100" /> </td> </tr> <tr> <td align="right" class="text">Subject : </td> <td><input name="txtSub2" type="text" class="input" id="txtSub22" size="30" maxlength="100" /> </td> </tr> <tr> <td align="right" class="text">Message: </td> <td><textarea name="txtMsg" cols="50" rows="10" class="input" id="textarea"></textarea> </td> </tr> <tr> <td align="right"><input name="hidSubmit" type="hidden" id="hidSubmit" value="true" /> </td> <td><input name="Submit" type="submit" class="input" value="Send" /> <input name="Submit2" type="reset" class="input" value="Reset" /> </td> </tr> </table> </form> <p> </p> </body> </html> What I have been trying to do is replace the "txtEmailto2" ie the recipient with a drop down box populated by a query . The query code also works fine and populates the dropdownbox <form> <select name="txtEmailto2"> <option>Please select a email from the list</option> <? include ("opendbincludeA.php"); $query ="SELECT P_Leader.PLemailAddress FROM P_Leader"; $query = mysql_query($query); $query_row=mysql_num_rows($query); while ($row=mysql_fetch_array($query)) { echo "<option>".$row['PLemailAddress']."</option>"; } ?> </select> </form> When I try and join them together it doesn't work. Hamish Quote Link to comment https://forums.phpfreaks.com/topic/52623-using-dropdown-box-to-submit-data/#findComment-259955 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.