Gier NL Posted December 3, 2008 Share Posted December 3, 2008 Hey guys! I've got a simple web form for sending e-mail. The form contains a name, email, subject and body textfield and a submit button: Userinfo.html: <form action="sendmail.php" method="post"> <input type="text" name="name" size="30"> <input type="text" name="replyemail" size="30"> <input type="text" name="subject" size="30"> <textarea rows="6" cols="54" name="body"></textarea> <input type="submit" name="submit" value="send"> sendmail.php: <?PHP $to = "my@email.com"; $from_header = "From: $replyemail"; if($body!= "") { //send mail - $subject & $body come from surfer input mail($to, $subject, $body, $from_header); } else { print("<HTML><BODY>Error, no comments were submitted!"); print("</BODY></HTML>"); } ?> I'm getting the following error: Notice: Undefined variable: subject in C:\Inetpub\wwwroot\cms\Download\Sendmail.php on line 3 Notice: Undefined variable: to in C:\Inetpub\wwwroot\cms\Download\Sendmail.php on line 4 Notice: Undefined variable: replyemail in C:\Inetpub\wwwroot\cms\Download\Sendmail.php on line 6 Notice: Undefined variable: body in C:\Inetpub\...\Sendmail.php on line 7 Error, no comments were submitted!PHP Notice: Undefined variable: subject in C:\Inetpub...\Sendmail.php on line 3 PHP Notice: Undefined variable: to in C:\Inetpub\...\Sendmail.php on line 4 PHP Notice: Undefined variable: replyemail in C:\Inetpub\...\Sendmail.php on line 6 PHP Notice: Undefined variable: bericht in C:\Inetpub\...\Sendmail.php on line 7 Does anyone have an idea what could be wrong? Quote Link to comment https://forums.phpfreaks.com/topic/135307-form-data-doesnt-transfer-to-my-php-script/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 3, 2008 Share Posted December 3, 2008 You need to use $_POST variables - http://us.php.net/manual/en/language.variables.external.php The code you have now would have only worked when register_globals are on and they were turned off six years ago because they created a security hole. Wherever you got or learned that code is way out of date. Quote Link to comment https://forums.phpfreaks.com/topic/135307-form-data-doesnt-transfer-to-my-php-script/#findComment-704962 Share on other sites More sharing options...
shutat Posted December 4, 2008 Share Posted December 4, 2008 If you want, you can use php to serve the form as well as process it. You should always check your variables before using them; empty is just a simple check to see whether or not a user filled them in. You'd want to make sure any input was valid for the field you expect before processing it. <?php if(isset($_POST["submit"]) && $_POST["submit"] === "send") { if(empty($_POST["name"]) || empty($_POST["replymail"]) || empty($_POST["subject"]) || empty($_POST["body"])) { // one or more post vars had an empty field } else { // validate input // assign post vars as needed // call mail function // mail returns a boolean value, true indicates it was sent, but // does not indicate whether or not it will actually arrive } } else { ?> <pre> <form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post"> Name: <input type="text" name="name" size="30"> From: <input type="text" name="replyemail" size="30"> Subject: <input type="text" name="subject" size="30"> Body: <textarea rows="6" cols="54" name="body"></textarea> <input type="submit" name="submit" value="send"> </pre> <?php } ?> HTH Quote Link to comment https://forums.phpfreaks.com/topic/135307-form-data-doesnt-transfer-to-my-php-script/#findComment-705649 Share on other sites More sharing options...
Gier NL Posted December 4, 2008 Author Share Posted December 4, 2008 Thank you guys! I checked and the post i got the code from was a few years old indeed. Quote Link to comment https://forums.phpfreaks.com/topic/135307-form-data-doesnt-transfer-to-my-php-script/#findComment-705760 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.