Jump to content

Basic PHP mail/header function help.


chris1989

Recommended Posts

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!  :confused:

 

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

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  :shrug:.

 

Thanks.

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....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.