Ninjakreborn Posted April 24, 2006 Share Posted April 24, 2006 I need help I can't do this, I have fought with this for days and days. I studied all the basics of php so I know pretty much the basics, 3 weeks so far, and I know quite a bit, ubt I am trying to put all that I know together and get to where after I create a advanced xhtml form, I need to be able to run it to an external php file, and gather the information and send it to myself in an email. and validate it using php and javascript. I worked on this technique for a long time, I decided to validate client side in order to catch some, and have the also validate server side for those people that have javascript turned off. THis is something I read on a few sites as a recommendation, so far I have gotten php to send an email, then I finally get the information and tried to send it, but when it did all the information came back in the email as blank, I did a few modifications use an if mail statement to tell me if it sent, I sent 2 or 3 and the email never even came in, can someone please help me sort through all of this, I have to master this before I can move onto the more advanced thigns. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/ Share on other sites More sharing options...
AndyB Posted April 24, 2006 Share Posted April 24, 2006 Post your code. We can't fix what we can't see, and guessing is pointless. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30312 Share on other sites More sharing options...
PWD Posted April 24, 2006 Share Posted April 24, 2006 Do you have some code we can look at? Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30313 Share on other sites More sharing options...
Ninjakreborn Posted April 24, 2006 Author Share Posted April 24, 2006 I can't figure this out, I am just trying to get the basics of sending hte information in an email, much less validation, here for instance is my form that I created to test this out on.[code]<form action="formprocessor.php" method="post" name="testform" id="testform"><br />First Name:<input name="firstname" type="text" maxlength="20" /><br />Last Name:<input name="lastname" type="text" maxlength="20" /><br />Age:<input name="age" type="text" maxlength="3" /><br />Your Favorite Video Game Genre:<br />Shooting:<input name="favvids" type="radio" />Rpg:<input name="favvids" type="radio" />Strategy:<input name="favvids" type="radio" />Roleplaying:<input name="favvids" type="radio" />Simulation:<input name="favvids" type="radio" /><br />How do you like spending your time the most.<select name="spendingtime"><option>Sleeping</option><option>Relaxing</option><option>Socializing</option><option>Other</option></select><br />Check All that Apply:<br />I am well respected:<input name="iam" type="checkbox" /><br />I am well renowned:<input name="iam" type="checkbox" /><br />I am very short:<input name="iam" type="checkbox" /><br />I don't like confrontation<input name="iam" type="checkbox" /><br />I dislike people talking to me:<input name="iam" type="checkbox" /><br /><input name="submit" type="submit" value="submit me" /></form>[/code]Ok Now I tried multiple methods to get this to work right, maybe all the methods aren't good, or this isn't how it should be done or what, but none of them are workign right, much less me getting into client side and server side validation.ok here was the first thing I tried.[code]<?php$recipient = $_POST['businessman332211@hotmail.com'];$subject = $_POST['This is from my site']; mail($firstname, $lastname, $age, $favvids, $spendingtime, $iam);?>[/code]I then recieved the following error message[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mail() expects at most 5 parameters, 6 given in /home/freelan4/public_html/formprocessor.php on line 11[/quote]ok so then I changed it to do the following, that doesn't even go to show I have no idea why it told me the mail command can only send 5 things, beats me.[code]<?php$recipient = $_POST['businessman332211@hotmail.com'];$subject = $_POST['This is from my site']; mail($firstname, $lastname, $age, $favvids, $spendingtime);?>[/code]ok that took me ahwile to get down, what happened with that is it sent, and just to be safe, I put in the following php if statement to make sure it sent.[code] if (mail($firstname, $lastname, $age, $favvids, $spendingtime)) {print "This email was sent correctly";} else {print "this email did not send correctly"}[/code]after that I sent it three or 4 times to see if it worked and each time it seemed to come up successful. Now I sit down a long time later and find out that it did not come to my email address. Awhile back I tried something else, but I don't remember what, oh I was just trying to send a basic email, and it sent, but everytime it did(this was without the form by the way just trying to send an email that was it.), and it sent, but I had a major problem and every time it came into my junk mail only.now I am trying to figure out, I want to be able to create any form, get it processed and sent in the email, that is what I am trying to master, along with validating it with javascript properly, and validating it with php also in the external file, but I am running into this major roadblock, I know there are hundreds of ways to do everything in php, but I can't seem to get down even one. Any advice would help. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30327 Share on other sites More sharing options...
KrisNz Posted April 25, 2006 Share Posted April 25, 2006 For starters, your form has some issues, your checkboxes dont have any values, when you use checkboxes to allow for multiple values you have to name them as an array like so[code]I am well respected:<input name="iam[]" value="respected" type="checkbox" /><br />I am well renowned:<input name="iam[]" value="renowned" type="checkbox" /><br />I am very short:<input name="iam[]" value="short" type="checkbox" /><br />etc etc...[/code]Secondly, [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$recipient = $_POST['businessman332211@hotmail.com'];$subject = $_POST['This is from my site'];[/quote]you set these variables incorrectly, they aren't posted from a form, just set them yourself. Your code says "set the recipient variable to the value contained in the $_POST array at the index of 'businessman332211@hotmail.com' . [code]$recipient = 'businessman332211@hotmail.com';[/code]have you looked at the method signature for php's mail function? Or for that matter the help page for php's mail function? You cant just pass it some random variables and expect it to send an email. In your code you dont seem to be passing in an email address, a subject, a message, any extra headers or any extra parameters.Perhaps you should take a few steps back, you're obviously very keen to learn but might be getting a bit ahead of yourself? Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30350 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 don't I have to pass something to say who to email it to, for instance when I create a form, I am not going to have a field there that says my email address. So how would I set up to be able to email it to me, without having it as a variable in the form. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30368 Share on other sites More sharing options...
AndyB Posted April 25, 2006 Share Posted April 25, 2006 You have misunderstood how the mail() function works.You can send as many form variables as you want BUT they all have to be part of the message (email body) not as 'parameters' to the mail function.There are plenty of posts here about the mail() function and the required syntax. A simple tutorial like the one at [a href=\"http://www.apptools.com/phptools/forms/\" target=\"_blank\"]http://www.apptools.com/phptools/forms/[/a] would be well worth reading. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30374 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 i will look at that thanks. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30528 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 ok I worked on this along time today< I redid the form completely> but when I added the brackets under the checks it gave me an error someone said to do that into an array, that was confusing so Iput the [] at the end of the choice, but when it tried to process for the form, it just gave me an error and said it could not process the characters []. So I did some tweaking, ran into some errors, fixed some errors in my code. When I got the code right I came up with teh following error. first of all my new form.[code]<form name="testform" action="formprocessor.php" action="post">First Name:<input name="firstname" type="text" maxlength="20" /><br />Last Name:<input name="lastname" type="text" maxlength="20" /><br />Age:<input name="age" type="text" maxlength="3" /><br />How you located this Website:<br /><select name="location"><option>Search Engine</option><option>Browsing other</option><option>freelance businessman</option><option>You don't want to specify</option></select><br />Pick one of the following:<br />Video Games:<input name="favorites" type="radio" value="video games" checked="check"/><br />Tv:<input name="favorites" type="radio" value="tv" /><br />Nothing:<input name="favorites" type="radio" value="nothing" /><br />Please check all that apply:<br />I am comfortable with my surroundings:<input name="choices" type="checkbox" value="comfortable" /><br />I am angered by my surroundings:<input name="choices" type="checkbox" value="angered" /><br />I am bothered by my surroundings:<input name="choices" type="checkbox" value="bothered" /><br />I am worthless when people are around:<input name="choices" type="checkbox" value="worthless" /><br />I am unserious when people are around:<input name="choices" type="checkbox" value="unserious" /><br />Please choose a proper username:<input name="username" type="text" maxlength="30" /><br />Please verify your username:<input name="verifyusername" type="text" maxlength="30" /><br />Please add in your password:<input name="password" type="password" maxlength="25" /><br />Please verify your password:<input name="verifypassword" type="password" maxlength="25" /><br /><input name="submit" type="submit" value="submit" /><input name="reset" type="reset" value="reset" />Thank you for taking the time to fill out this form, if everything works correctly you will recieve a confirmation stating that it was completed successfully.</form>[/code]Then here is the php code on the correct page.[code]<?php$recipient = "businessman332211@hotmail.com";$header = "This is from freelance businessman";mail($recipient, $header, $firstname, $lastname, $age, $location, $favorites, $choices, $username, $verifyusername, $password, $verifypassword);if(mail($recipient, $header, $firstname, $lastname, $age, $location, $favorites, $choices, $username, $verifyusername, $password, $verifypassword)){print "The email was sent successfully";} else {print "the email was not sent correctly";}?>[/code]I am now getting the same error I was getting yesterday, I was fiddling around trying to figure out how [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mail() expects at most 5 parameters, 12 given in /home/freelan4/public_html/formprocessor.php on line 12Warning: mail() expects at most 5 parameters, 12 given in /home/freelan4/public_html/formprocessor.php on line 13the email was not sent correctly [/quote]again there is a lot I want to do before I move onto other things, I want to be able to create any form and process it properly with little to no hasstle. After that I was going to start tackling php validating. and then javascript validating, because I am trying to string everything together so I can master this entire aspect of php programming, I need form advanced down so when I move onto more advanced programming I won't have as hard of a time understanding. Anyadvice on the problems I encountered at this stage would be nice, and someone mentioned passing your checkboxes off as an array, I know what arrays are, but don't understand what setting these up as an array is going to help, I also don't fully understand HOW to pass them off as an array, what would the purpose of this be.I just fixed it nevermind, let me see if I run into any more problems, but I got theemail to send, I misread something someone on here told me but the person when I reread it I reunderstood everything.ok it sent, I need to work on a few things here. First of all how do I pass the variables of checked boxes into an array, I see what he meant now, because when I tried to send it, it sent, but allchecks didn't come up, it only picked up one of them.Also I noticed a lot of people when they are trying to send it they put$get then wahteveror $post then whateverwhat's the point of this, I got it to send the other day, do I need to do anything with the $get, $post on the processing page, why didn't I have to to get it to send. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30557 Share on other sites More sharing options...
zq29 Posted April 25, 2006 Share Posted April 25, 2006 You [i]really[/i] need to slow down and actually [i]read[/i] peoples advice on here. You are still using the mail function incorrectly, heres an example of how it is used:[code]<?php$message = "This is the body of the Email";mail("businessman332211@hotmail.com","The Subject", $message);?>[/code] The above code will send an email to businessman332211@hotmail.com with the subject "The Subject", and the email will just contain "This is the body of the Email".[b]EDIT: Turns out you got this bit working - Ignore the above then...[/b]Form checkboxes require the name set as an array so that the user can select more than one checkbox, all of the checked boxes are put in the array, heres an example of using check boxes and displaying which ones were checked:[code]<?phpif(isset($_POST['submit'])) { echo "You selected the following colours:<br/>"; foreach($_POST['colours'] as $c) { echo $c."<br/>"; }}?><h1>Select some colours</h1><form name="colour_select" action="" method="post"> <input type="checkbox" name="colours[]" value="Red"/> Red<br/> <input type="checkbox" name="colours[]" value="Green"/> Green<br/> <input type="checkbox" name="colours[]" value="Blue"/> Blue<br/> <input type="submit" name="submit" value="Go!"/></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30566 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 I noticed that at the last minute, I put down this at the last minute when I realized I had read it incorrectly.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]ok it sent, I need to work on a few things here. First of all how do I pass the variables of checked boxes into an array, I see what he meant now, because when I tried to send it, it sent, but allchecks didn't come up, it only picked up one of them.Also I noticed a lot of people when they are trying to send it they put$get then wahteveror $post then whateverwhat's the point of this, I got it to send the other day, do I need to do anything with the $get, $post on the processing page, why didn't I have to to get it to send[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30569 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 I still don't understand, how do I draw that information in the select boxes into an array, and set it up to where it can be sent in an email like I did earlier. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30579 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 ok I played around with it some and ran into a few problems. When I pass it into an array, how to pass it into an array, and get it to send me all the checked items through the email.I saw a lot of people getting the information variables using stuff like[code]_GET['something'];or_POST['something'];[/code]I am asking these questions because Ididn't find the answers anywhere else. I looked around understood what I could and came here. THe last thing I am trying to figure out, is what is the point of keeping the _GET _post in there, nad what is the difference. Should I always use get, or always use post, or mix them based on the reason if so what reasons. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30595 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 ok I tried the following form again[code]<form name="testform" action="formprocessor.php" action="get">First Name:<input name="firstname" type="text" maxlength="20" /><br />Last Name:<input name="lastname" type="text" maxlength="20" /><br />Age:<input name="age" type="text" maxlength="3" /><br />How you located this Website:<br /><select name="location"><option>Search Engine</option><option>Browsing other</option><option>freelance businessman</option><option>You don't want to specify</option></select><br />Pick one of the following:<br />Video Games:<input name="favorites" type="radio" value="video games" checked="check"/><br />Tv:<input name="favorites" type="radio" value="tv" /><br />Nothing:<input name="favorites" type="radio" value="nothing" /><br />Please check all that apply:<br />I am comfortable with my surroundings:<input name="choices[]" type="checkbox" value="comfortable" /><br />I am angered by my surroundings:<input name="choices[]" type="checkbox" value="angered" /><br />I am bothered by my surroundings:<input name="choices[]" type="checkbox" value="bothered" /><br />I am worthless when people are around:<input name="choices[]" type="checkbox" value="worthless" /><br />I am unserious when people are around:<input name="choices[]" type="checkbox" value="unserious" /><br />Please choose a proper username:<input name="username" type="text" maxlength="30" /><br />Please verify your username:<input name="verifyusername" type="text" maxlength="30" /><br />Please add in your password:<input name="password" type="password" maxlength="25" /><br />Please verify your password:<input name="verifypassword" type="password" maxlength="25" /><br /><input name="submit" type="submit" value="submit" /><input name="reset" type="reset" value="reset" />Thank you for taking the time to fill out this form, if everything works correctly you will recieve a confirmation stating that it was completed successfully.</form>[/code]I had the drop down menu and radio buttons, they were sending the correct on that was chosen, then I noticed it was only the checkboxes, so I tried an array like this.[code]<?php$choices = array($choices=>$comfortable, $choices=>$angered, $choices=>$bothered, $choices=>$worthless, $choices=>$unserious);$to = "businessman332211@hotmail.com";$subject = "freelance businessman!";$body = "First Name:$firstnameLast Name:$lastnameAge: $ageLocation: $locationFavorites: $favoritesChoices: $choicesUsername: $usernameVerify Username: $verifyusernamePassword: $passwordVerify Password: $verifypassword";if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); }?>[/code]and like this[code]<?php$choices = array($comfortable, $angered, $bothered, $worthless, $unserious);$to = "businessman332211@hotmail.com";$subject = "freelance businessman!";$body = "First Name:$firstnameLast Name:$lastnameAge: $ageLocation: $locationFavorites: $favoritesChoices: $choicesUsername: $usernameVerify Username: $verifyusernamePassword: $passwordVerify Password: $verifypassword";if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); }?>[/code]Neither of them worked. Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30606 Share on other sites More sharing options...
Ninjakreborn Posted April 25, 2006 Author Share Posted April 25, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/8315-help/#findComment-30625 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.