ecabrera Posted February 9, 2012 Share Posted February 9, 2012 how come the the else donest not work it shows up "Please enter your feedback or insert your email" <form method="post" action="feedback.php"> Email: <input name="email" type="text"><br> Feedback:<br><textarea name="message" rows="15" cols="40"> </textarea> <br> <input type="submit" name="sendbtn" value="Send" /> </form> <?php $to = "ecabrera9@ymail.com"; $subject = "Feedback"; $email = $_POST['email']; $message = $_POST['message']; $headers = "From: $email"; if($_POST['sendbtn']){ if($email && $message) $sent = mail($to, $subject, $message, $headers); echo "Thank you for the feedback. We will be in touch with you very soon."; }else{ echo "Please enter your feedback or insert your email"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/ Share on other sites More sharing options...
Pikachu2000 Posted February 9, 2012 Share Posted February 9, 2012 What? Maybe you could explain that a little bit better? Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/#findComment-1316346 Share on other sites More sharing options...
jason310771 Posted February 9, 2012 Share Posted February 9, 2012 try the following to see what was actually entered in the fields. <form method="post" action="feedback.php"> Email: <input name="email" type="text"><br> Feedback:<br><textarea name="message" rows="15" cols="40"> </textarea> <br> <input type="submit" name="sendbtn" value="Send" /> </form> <?php $to = "ecabrera9@ymail.com"; $subject = "Feedback"; $email = $_POST['email']; $message = $_POST['message']; echo("email = '".$email."'<br />"); echo("message = '".$message."'<br />"); $headers = "From: $email"; if($_POST['sendbtn']){ if($email && $message) $sent = mail($to, $subject, $message, $headers); echo "Thank you for the feedback. We will be in touch with you very soon."; }else{ echo "Please enter your feedback or insert your email"; } ?> if any the content of the fields will be echod between the two sets of single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/#findComment-1316350 Share on other sites More sharing options...
QuickOldCar Posted February 9, 2012 Share Posted February 9, 2012 try this <form method="post" action="feedback.php"> Email: <input name="email" type="text"><br> Feedback:<br><textarea name="message" rows="15" cols="40"> </textarea> <br> <input type="submit" name="sendbtn" value="Send" /> </form> <?php $to = "ecabrera9@ymail.com"; $subject = "Feedback"; $email = $_POST['email']; $message = $_POST['message']; $headers = "From: $email"; if($_POST['sendbtn']){ if($email && $message){ $sent = mail($to, $subject, $message, $headers); echo "Thank you for the feedback. We will be in touch with you very soon."; }else{ echo "Please enter your feedback or insert your email"; } } Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/#findComment-1316354 Share on other sites More sharing options...
ecabrera Posted February 9, 2012 Author Share Posted February 9, 2012 QuickOldCar works thanks but why does it have to be put in a variable the $sent Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/#findComment-1316356 Share on other sites More sharing options...
Drummin Posted February 9, 2012 Share Posted February 9, 2012 To answer original question, look at your IF statement and how it's missing the opening bracket that corresponds to the ELSE as QuickOldCar pointed out. Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/#findComment-1316357 Share on other sites More sharing options...
spiderwell Posted February 9, 2012 Share Posted February 9, 2012 the mail function returns true or false depending on success or failure, you can capture that with the $sent = bit, you dont Have to do it. you could also do this way: if($email && $message ){ if (mail($to, $subject, $message, $headers)) { echo "Thank you for the feedback. We will be in touch with you very soon."; } else { echo 'unable to send email'; } }else{ echo "Please enter your feedback or insert your email"; } } Quote Link to comment https://forums.phpfreaks.com/topic/256771-else/#findComment-1316359 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.