chris1989 Posted February 4, 2010 Share Posted February 4, 2010 Hi peeps, I am a complete newb to PHP and can not understand why my script is not working properly. I have had a look round for a solution but i think that my problem is so easy or simple that no one has asked it before! my code is <?php if (isset($_REQUEST['email'])){ $to = "chris{at]url*"; $subject = "Contact Form Enquiry"; $message = $_REQUEST["message"]; $from = $_REQUEST["email"]; mail($to,$subject,$message,$from); header('Location: absoluteurl*');} else{ header('Location: absoluteurl*');} ?> *wont let me post links Now the email sends fine but its the bit where i ask if the email box is not filled in then it should go to the error page but it always forwards to the "thanks.php" page. Any help is appreciated. the form code is as below; <form name="contactform" method="post" action="contactscript.php"> <fieldset id="contactfield"> <legend id="contactleg">Contact Form</legend> Name: <input class="contactform" type="text" size="30" name="name" value="name"/><br /><br /> Email Address: <input class="contactform" type="text" size="30" name="email" value="email"/><br /><br /> Message: <br /><textarea rows="10" cols="30" name="message" value="message">Type your message here</textarea><br /> <input type="submit" value="Send Message" name="submit" /> </fieldset> </form> Link to comment https://forums.phpfreaks.com/topic/190905-basic-php-mailheader-function-help/ Share on other sites More sharing options...
jskywalker Posted February 4, 2010 Share Posted February 4, 2010 if (isset($_REQUEST['email'])){ this variable is probably always set.... if no emailaddress is in there, you will get an empty (but set) variable... Link to comment https://forums.phpfreaks.com/topic/190905-basic-php-mailheader-function-help/#findComment-1006744 Share on other sites More sharing options...
chris1989 Posted February 4, 2010 Author Share Posted February 4, 2010 if (isset($_REQUEST['email'])){ this variable is probably always set.... if no emailaddress is in there, you will get an empty (but set) variable... Right ok, anyway around this or a better way to do this? All im finding on google is saying to do it this way . Thanks. Link to comment https://forums.phpfreaks.com/topic/190905-basic-php-mailheader-function-help/#findComment-1006747 Share on other sites More sharing options...
jskywalker Posted February 4, 2010 Share Posted February 4, 2010 the function isset(), Determines if a variable is set and is not NULL (http://php.net/manual/en/function.isset.php) But you want it to contain a valid emailaddres, so you must check this some googlein reveald this site (http://www.linuxjournal.com/article/9585) to have a story about that subject, but there are others who have written about this too.... Link to comment https://forums.phpfreaks.com/topic/190905-basic-php-mailheader-function-help/#findComment-1006751 Share on other sites More sharing options...
trq Posted February 4, 2010 Share Posted February 4, 2010 if (isset($_POST['email']) && !empty($_POST['email'])) { Link to comment https://forums.phpfreaks.com/topic/190905-basic-php-mailheader-function-help/#findComment-1006752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.