sunny- Posted December 31, 2012 Share Posted December 31, 2012 Greetings everyone, I am a really new php coder and I got stuck in a problem while writting a practice code. This is about a Feedback page that sends an email after getting the Feedback. The error Recieved basically states that the variables are undefined. so That means there is some problem while passing the values of the variables. I really cannot Figure it out. Please help me. The Feedback Form Page is--- <HTML> <HEAD> <TITLE>The Feedback Form</TITLE> </HEAD> <BODY> <FORM method="POST" action="sf.php"> <p>Your Name: <INPUT type="text" name="sender_name" size=20 maxlength=50> </p> <p>Your Email: <INPUT type="text" name="sender_email" size=20 maxlength=50> </p> <p>Message: <textarea name="message" cols=30 rows=5></textarea></p> <p>Do you like this Website: <INPUT type="radio" name="like_site" value="Yes" checked> yes <INPUT type="radio" name="like_site" value="No"> no </p> <INPUT type="submit" value="SUBMIT"> </FORM> </BODY> </HTML> The Page which is responsible for sending the email is <HTML> <HEAD> <TITLE>The Send Feedback</TITLE> </HEAD> <BODY> <?php_track_vars?> <?php $msg="Sender's Full Name:\t $sender_name \n"; $msg.="Sender's Email:\\t$sender_email\n"; $msg.="Did you like the Website?\t$like_site\n"; $msg.="Additional Message:\t$message\n\n"; $mailheaders="From: Lord Sunny's Website"; $mailheaders.="Reply-To: $sender_email\n\n"; mail("sunnymay1993@hotmail.com", "Feedback Form From--$sender_name",$msg,$mailheaders); echo"<H1 align=centre> Thank you, $sender_name"; if($sender_name=='yes') echo"<P align=centre> Thank you for Liking our Website.</p>"; else echo"<P align=centre> We will try to improve our website as per your feedback.</p>"; ?> </BODY> </HTML> Sorry if I am posting this in an inappropiate forum. Quote Link to comment Share on other sites More sharing options...
Silvar Posted December 31, 2012 Share Posted December 31, 2012 (edited) Try this: <?php $message = $_POST["message"]; $sender_name = $_POST["sender_name"]; $sender_email = $_POST["sender_email"]; $like_site = $_POST["like_site"]; $msg="Sender's Full Name:\t $sender_name \n"; $msg.="Sender's Email:\\t$sender_email\n"; $msg.="Did you like the Website?\t$like_site\n"; $msg.="Additional Message:\t$message\n\n"; $mailheaders="From: Lord Sunny's Website"; $mailheaders.="Reply-To: $sender_email\n\n"; mail("sunnymay1993@hotmail.com", "Feedback Form From--$sender_name",$msg,$mailheaders); echo"<H1 align=centre> Thank you, $sender_name"; if($like_site == 'Yes') { echo "<p align='centre'> Thank you for Liking our Website.</p>"; } else { echo "<p align='centre'> We will try to improve our website as per your feedback.</p>"; } ?> Corrected this: - I've defined the values of the form with $_POST[]; - The "if($like_site == 'Yes')" was set to "if($sender_name == 'Yes')" Edited December 31, 2012 by Silvar Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 31, 2012 Share Posted December 31, 2012 You need to check if the $_POST array key isset before trying to use it, and check overall if the form was even submitted. Quote Link to comment Share on other sites More sharing options...
sunny- Posted January 1, 2013 Author Share Posted January 1, 2013 (edited) Silvar's Solution Seems to be working.Thank you very much. But why do I have to use another set of varibales just to hold whatever I actaully passed? Isent that a bit of waste of Space? because I am storing the same thing which I already have direct access to. Or is this the way it is done in php? As for the isset() function. I tired it and it seems like the $_POST is actaully set. The new sf.php with the isset() ==== <HTML> <HEAD> <TITLE>The Send Feedback</TITLE> </HEAD> <BODY> <?php_track_vars?> <?php if(isset($_POST)) echo "IT is set."; $msg="Sender's Full Name:\t $sender_name \n"; $msg.="Sender's Email:\\t$sender_email\n"; $msg.="Did you like the Website?\t$like_site\n"; $msg.="Additional Message:\t$message\n\n"; $mailheaders="From: Lord Sunny's Website"; $mailheaders.="Reply-To: $sender_email\n\n"; mail("sunnymay1993@hotmail.com", "Feedback Form From--$sender_name",$msg,$mailheaders); echo"<H1 align=centre> Thank you, $sender_name"; if($sender_name=='yes') echo"<P align=centre> Thank you for Liking our Website.</p>"; else echo"<P align=centre> We will try to improve our website as per your feedback.</p>"; ?> </BODY> </HTML> So it is suppose to print "IT is Set" if isset($_POST) returns a 1; So It is printing, so that means that the variables are passed properly? If so then why does it still say that the Variable is undefined. Edited January 1, 2013 by sunny- Quote Link to comment Share on other sites More sharing options...
trq Posted January 1, 2013 Share Posted January 1, 2013 Because they are not defined. The data your after is in the $_POST array. See reply #2. Quote Link to comment Share on other sites More sharing options...
Silvar Posted January 1, 2013 Share Posted January 1, 2013 See my reply. As Silvar's Solution Seems to be working.Thank you very much. But why do I have to use another set of varibales just to hold whatever I actaully passed? Isent that a bit of waste of Space? because I am storing the same thing which I already have direct access to. Or is this the way it is done in php? As for the isset() function. I tired it and it seems like the $_POST is actaully set. The new sf.php with the isset() ==== <HTML> <HEAD> <TITLE>The Send Feedback</TITLE> </HEAD> <BODY> <?php_track_vars?> <?php if(isset($_POST)) echo "IT is set."; $msg="Sender's Full Name:\t $sender_name \n"; $msg.="Sender's Email:\\t$sender_email\n"; $msg.="Did you like the Website?\t$like_site\n"; $msg.="Additional Message:\t$message\n\n"; $mailheaders="From: Lord Sunny's Website"; $mailheaders.="Reply-To: $sender_email\n\n"; mail("sunnymay1993@hotmail.com", "Feedback Form From--$sender_name",$msg,$mailheaders); echo"<H1 align=centre> Thank you, $sender_name"; if($sender_name=='yes') echo"<P align=centre> Thank you for Liking our Website.</p>"; else echo"<P align=centre> We will try to improve our website as per your feedback.</p>"; ?> </BODY> </HTML> So it is suppose to print "IT is Set" if isset($_POST) returns a 1; So It is printing, so that means that the variables are passed properly? If so then why does it still say that the Variable is undefined. See my first reply. As en example $sender_name doesn't give you the output of the form, $_POST['sender_name']; does, so you need to define it. Quote Link to comment Share on other sites More sharing options...
trq Posted January 1, 2013 Share Posted January 1, 2013 Whatever resource your learning php from is severely outdated. The functionality you are expecting has been disabled for like 10 years. The functionality would magically register globals into local scope. You now have to get the data you are looking for from the $_POST array. 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.