Hamish Posted May 29, 2007 Share Posted May 29, 2007 Hi All, This is my second attempt at using a MySQL generated query to populate a dropdown box to send email. The query populates the dropdown box “ok”, allowing the desired email address to be selected. The problem seems to be in using this email address as the input. How do I get the selected email to then become an input? Any ideas much appreciated. Hamish <?php //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$PLemailAddress; $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>php email</title> </head> <body> <form name="frmsendmail" method="post" action="" onSubmit="return ValidationForm()"> <table width="100%" border="0"> <tr> <td><div align="right">To</div></td> <td><select name="PLemailAddress"> <option>Please select a email from the list</option> <?php 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></td> </tr> <tr> <td width="34%"><div align="right">From</div></td> <td width="66%"><input name="txtEmailfrm2" type="text" id="txtEmailfrm2" /></td> </tr> <tr> <td><div align="right">Subject</div></td> <td><input type="txtSub2" name="textfield" /></td> </tr> <tr> <td><div align="right">Message</div></td> <td><textarea name="txtMsg" cols="50" rows="6"></textarea></td> </tr> <tr> <td><div align="right"></div></td> <td><input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/ Share on other sites More sharing options...
taith Posted May 29, 2007 Share Posted May 29, 2007 $query=mysql_query("SELECT `PLemailAddress` FROM `P_Leader`") or die(mysql_error()); while($row=mysql_fetch_assoc($query)){ echo "<option>".$row['PLemailAddress']."</option>"; } Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-263854 Share on other sites More sharing options...
Hamish Posted May 29, 2007 Author Share Posted May 29, 2007 Hi taith, Thanks for the modified query which I have changed and tried, however when submitted the script does not get either success or failure from warnings nor is the email delivered. Regards Hamish Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-263859 Share on other sites More sharing options...
taith Posted May 29, 2007 Share Posted May 29, 2007 ok... but is the field filling in? does the dropdown have value? Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-263864 Share on other sites More sharing options...
Hamish Posted May 29, 2007 Author Share Posted May 29, 2007 Hi taith, The dropdown populates with the result of the query in the form of an email address, ie fredblogs@pipex.net. You can select the an email address and it holds in the text box, allowing "from", "subject" and "message" to be filled in. Pressing submit gives the impression that the email has be forwarded and the form fields clear, no error message but the email does not arrive. I have tested the script without the dropdown and the emails arrive, the problem seems to be in getting from the dropdown to "input" Regards Hamish Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-264098 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 You are assuming register_globals is turned on, very bad and very insecure. <?php //Check whether the submission is made if(isset($_POST['Submit'])){ // no hid I do not know where you got that from. //Declarate the necessary variables $mail_to=$_POST['PLemailAddress']; $mail_from=$_POST['txtEmailfrm2']; $mail_sub=$_POST['txtSub2']; $mail_mesg=$_POST['txtMsg']; That works with or without register_globals being on/off and you should generally use those anyways for security purposes. $query=mysql_query("SELECT `PLemailAddress` FROM `P_Leader`") or die(mysql_error()); while($row=mysql_fetch_assoc($query)){ echo "<option>".$row['PLemailAddress']."</option>"; } That is invalid code, the code you were using above should work just fine. If you want to try taith's code you need it to look like this instead <?php $query=mysql_query("SELECT `PLemailAddress` FROM `P_Leader`") or die(mysql_error()); while($row=mysql_fetch_assoc($query)){ echo "<option value=" . $row['PLemailAddress'] . ">".$row['PLemailAddress']."</option>"; } The value part must be assigned. Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-264106 Share on other sites More sharing options...
Hamish Posted May 29, 2007 Author Share Posted May 29, 2007 Hi frost110, Are you saying that my original code should work as is. Hamish. Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-264112 Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 Exactly what I am saying, with the exception of the $_POST portion I posted above. Quote Link to comment https://forums.phpfreaks.com/topic/53387-solved-using-a-dynamic-dropdown-as-input/#findComment-264182 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.