Find the answer to your Linux question:
Results 1 to 2 of 2
Hi peeps, im a newb to PHP and canot understand why my script is not working properly. my code is Code: <?php if (isset($_REQUEST['email'])){ $to = "chris{at]absoluteurl*"; $subject = "Contact ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    11

    Basic PHP mail function help.

    Hi peeps, im a newb to PHP and canot understand why my script is not working properly.

    my code is

    Code:
    <?php
    if (isset($_REQUEST['email'])){
    	$to = "chris{at]absoluteurl*";
    	$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
    *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 appeiated.

    the form code is as below;

    Code:
    <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>

  2. #2
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,298
    header does a 301 redirect which means it happens in the browser. The script will carry on running on the server.

    So, you need to stop the script after a redirect.

    Code:
    header('Location:  absoluteurl*');
    exit();
    Also learn to validate user input - never trust the buggers!
    If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)


    My new blog. It's probably not as good as I think it is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...