abdulkareem Posted September 28, 2010 Share Posted September 28, 2010 Hi, am having abit of a problem.Can anyone help me in programming my form to send it's details to an email address.The form should be able to detect unfilled fields,unselected items all in all the form should work as a effectively according to how i designed it The email sending processing should be handled by a separate file known as process.php below is the HTML coding... <form name="myform" action="process.php" method="POST"> Name: <input type="text" name="Name" /><br /> Email: <input type="text" name="Email" /><br /> Select something from the list: <select name="Seasons"> <option value="Spring" selected="selected">Spring</option> <option value="Summer">Summer</option> <option value="Autumn">Autumn</option> <option value="Winter">Winter</option> </select><br /><br /> Choose one: <input type="radio" name="Country" value="USA" /> USA <input type="radio" name="Country" value="Canada" /> Canada <input type="radio" name="Country" value="Other" /> Other <br /> Choose the colors: <input type="checkbox" name="Colors[]" value="green" checked="checked" /> Green <input type="checkbox" name="Colors[]" value="yellow" /> Yellow <input type="checkbox" name="Colors[]" value="red" /> Red <input type="checkbox" name="Colors[]" value="gray" /> Gray <br /><br /> Comments:<br /> <textarea name="Comments" rows="10" cols="60">Enter your comments here</textarea><br /> <input type="submit" /> </form> Quote Link to comment Share on other sites More sharing options...
Rifts Posted September 28, 2010 Share Posted September 28, 2010 what is the problem? does the email not send or what? also post the process.php file if you want help Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 28, 2010 Share Posted September 28, 2010 Apart from the form missing some rudimentary things from it, might I suggest a tutorial as a pointer for you: mail() tutorial from there it shouldn't take long to do a semi decent email form handler; just be aware that you will need some form of data sanitising as user generated input should NEVER be trusted, simple commands could wreak havoc on your hard work. Oh, BTW; your form is missing this from it: <input type="submit" name="submit" value="submit"/> other than that, all ok, though css can help with other things such as removing the row's/col's attributes from the textarea.. Rw Quote Link to comment Share on other sites More sharing options...
abdulkareem Posted September 28, 2010 Author Share Posted September 28, 2010 at "rwwd" thanks for the correction <input type="submit" name="submit" value="submit"/> the process.php file looks like this... <?php //Check whether the form has been submitted if (array_key_exists('check_submit', $_POST)) { //Converts the new line characters (\n) in the text area into HTML line breaks (the <br /> tag) $_POST['Comments'] = nl2br($_POST['Comments']); //Check whether a $_GET['Languages'] is set if ( isset($_POST['Colors']) ) { $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array into a single string } //Let's now print out the received values in the browser echo "Your name: {$_POST['Name']}<br />"; echo "Your password: {$_POST['Password']}<br />"; echo "Your favourite season: {$_POST['Seasons']}<br /><br />"; echo "Your comments:<br />{$_POST['Comments']}<br /><br />"; echo "You are from: {$_POST['Country']}<br />"; echo "Colors you chose: {$_POST['Colors']}<br />"; } else { echo "You can't see this page without submitting the form."; } ?> what i would like is the form to send the details to an email address. Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 28, 2010 Share Posted September 28, 2010 <?php //Check whether the form has been submitted if (array_key_exists('submit', $_POST)) {//the submit button was named submit, unless you changed it? //Converts the new line characters (\n) in the text area into HTML line breaks (the <br /> tag) $_POST['Comments'] = nl2br($_POST['Comments']); //Check whether a $_GET['Languages'] is set<-Your not checking a $_GET if ( isset($_POST['Colors']) ) { //your just putting all the Array values into one key here, so still an array really... $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array into a single string } //So your echoing the details being submitted, fine... //Let's now print out the received values in the browser echo "Your name: {$_POST['Name']}<br />"; echo "Your password: {$_POST['Password']}<br />"; echo "Your favourite season: {$_POST['Seasons']}<br /><br />"; echo "Your comments:<br />{$_POST['Comments']}<br /><br />"; echo "You are from: {$_POST['Country']}<br />"; echo "Colors you chose: {$_POST['Colors']}<br />"; //pop the mail function here, set the headers and send mail(to, subject, message, headers); } else { //have the error handler here so that you keep traffic, and nothing is more annoying than a static //error message really? header("location: REDIRECT BACK TO FORM HERE"); exit; //kill the script here so that nothing else can be invoked by php... always handy } ?> Just a few pointers really. Rw Quote Link to comment Share on other sites More sharing options...
abdulkareem Posted September 29, 2010 Author Share Posted September 29, 2010 THE HTML FORM; form.html <form name="myform" action="process.php" method="POST"> <input type="hidden" name="check_submit" value="1" /> Name: <input type="text" name="Name" /><br /> From: <input type="text" name="from" /><br /> Select something from the list: <select name="Seasons"> <option value="Spring" selected="selected">Spring</option> <option value="Summer">Summer</option> <option value="Autumn">Autumn</option> <option value="Winter">Winter</option> </select><br /><br /> Choose one: <input type="radio" name="Country" value="USA" /> USA <input type="radio" name="Country" value="Canada" /> Canada <input type="radio" name="Country" value="Other" /> Other <br /> Choose the colors: <input type="checkbox" name="Colors[]" value="green" checked="checked" /> Green <input type="checkbox" name="Colors[]" value="yellow" /> Yellow <input type="checkbox" name="Colors[]" value="red" /> Red <input type="checkbox" name="Colors[]" value="gray" /> Gray <br /><br /> Comments:<br /> <textarea name="Comments" rows="10" cols="60">Enter your comments here</textarea><br /> <input type="submit" name="submit" value="submit"/> </form> process.php <?php //Check whether the form has been submitted if (array_key_exists('submit', $_POST)) {//the submit button was named submit, unless you changed it? //Converts the new line characters (\n) in the text area into HTML line breaks (the <br /> tag) $_POST['Comments'] = nl2br($_POST['Comments']); //Check whether a $_GET['Languages'] is set<-Your not checking a $_GET if ( isset($_POST['Colors']) ) { //your just putting all the Array values into one key here, so still an array really... $_POST['Colors'] = implode(', ', $_POST['Colors']); //Converts an array into a single string } //So your echoing the details being submitted, fine... //Let's now print out the received values in the browser echo "Your name: {$_POST['Name']}<br />"; echo "from: {$_POST['from']}<br />"; echo "Your favourite season: {$_POST['Seasons']}<br /><br />"; echo "Your comments:<br />{$_POST['Comments']}<br /><br />"; echo "You are from: {$_POST['Country']}<br />"; echo "Colors you chose: {$_POST['Colors']}<br />"; //pop the mail function here, set the headers and send mail("info@youremail.com", 'online form',$comments,"from: $from"); } else { //have the error handler here so that you keep traffic, and nothing is more annoying than a static //error message really? header("location: form.html"); exit; //kill the script here so that nothing else can be invoked by php... always handy } ?> well, i uploaded the form to a server. the sending process works well but the big problem is that it doesnt pick the details from the from. an empty email is sent to the recipient mail. could anyone program the form according to his/her knowledge so that it picks the form details? Quote Link to comment Share on other sites More sharing options...
abdulkareem Posted September 29, 2010 Author Share Posted September 29, 2010 well, i uploaded the form to a server. the sending process works well but the big problem is that it doesnt pick the details from the from. an empty email is sent to the recipient mail. could anyone program the form according to his/her knowledge so that it picks the form details? 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.