Wolverine68 Posted August 15, 2011 Share Posted August 15, 2011 Can't get a simple request form with mail() function to work. When clicking on the Submit button, it goes to the feedback.php file but just shows a blank page. It doesn't display the "Thank you, your request has been submitted" message along with the date and time which I included in the coding. HTML form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Request Form</title> </head> <body background="#EEEEEE"> <h3 align="center">Request to Add to E-Mail List</h3> <div> <form action="feedback8.php" method="post"> <p><font color="blue">If you'd like to be added to the e-mail list, simply fill in your name and e-mail address, then click "Submit"</font></p> <hr width="100%"> <p>Name:     <INPUT TYPE="text" SIZE="35" name="name"></p> <p>E-mail:    <INPUT TYPE="text" SIZE="35" name="email"></p> <br><br> <input type="submit" name="submit" value="Submit"><br><br> <hr width="100%"> </div> </body> </html> PHP file: <?php $formBody="Name:$name\nEmail:$email"; $headers = "From:$email"; if ($submit) { mail("[email protected]", "Add to E-mail List Request", $formBody, $headers); } if ($submit) { print "Thank you. Your request has been submitted <br /> <br />"; print "Current date and time :"; print date("F j, Y g:i A T"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244865-problem-with-a-request-form-using-mail-function/ Share on other sites More sharing options...
cssfreakie Posted August 15, 2011 Share Posted August 15, 2011 Try the following: <?php /* some error checking */ error_reporting(E_ALL); ini_set("display_errors", 1); if(isset($_POST['submit']) // if someone presses submit && !empty($_POST['name']) // and name is filled in && !empty($_POST['email'])){ // and email is filled in // $name = $_POST['name']; //added these $email = $_POST['email']; // added these $formBody="Name: $name\nEmail:$email"; $headers = "From: $email"; // if(mail("[email protected]", "Add to E-mail List Request", $formBody, $headers)){ //email print "Thank you. Your request has been submitted <br /> <br />"; print "Current date and time :"; print date("F j, Y g:i A T"); }else{ // if the email didn't process echo 'oops something went wrong'; } } ?> The key this with forms is that you validate. Are the values as expected? (make sure you have a read on something called email header injection) Also, notice i am using a $_POST variable. since your form method is 'post' we require to use those values. edit: also make sure you look at the examples given in the manual:http://php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/244865-problem-with-a-request-form-using-mail-function/#findComment-1257865 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.