Old 10-09-2006, 12:27   #1 (permalink)
Dirti
Professional Idiot
 
Dirti's Avatar
 
Join Date: Aug 2006
Location: Uk
Posts: 59
Annoying email form issue.

I have a site that runs through one page using includes and a little php navigation script. Here's the issue, i have a simple php email form running on one of the included pages but it doesn't seem to want to send any email when included. It works fine if i go direct to the page just not when it's actualy included in the other page. Any ideas?

Code below..

The email form:
Code:
<?php $name = $_POST['name']; $email = $_POST['email']; $body = $_POST['body']; if ($name != "" AND $email != "" AND $body != "") { $sendto = "email@email.com"; $subject = "Email subject"; $message = "Message from site From: $name Email: $email Message: $body"; mail("$sendto", "$subject", "$message"); echo "Your message has been sent!"; } ?> <h2>Contact Me</h2><br /> <div id="email"><form method="post" name="mailform" action="<?=$_SERVER['PHP_SELF'] ?>"> <h4>Name: <br /> <input name="name" type="text" id="name"><br /><br /> Email:<br /> <input name="email" type="text" id="email"><br /><br /> Message:</h4> <textarea name="body" cols="45" rows="10"></textarea><br /><br /> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"> </form> <br />

And the little navigation script:

Code:
<?php switch($_GET['page']) { default: include('page.php'); break; case "about": include('page.php'); break; case "portfolio": include('page.php'); break; case "hireme": include('page.php'); break; case "contact": include('page.php'); } ?>
  Reply With Quote
Old 10-09-2006, 13:37   #2 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,717
The probelm I can see is that the form is calling itself, as it is included in a page the page it will call will be the holding page. Unless the holding page is told to include the mailsend part of the program it will not work. You can handle this two ways.

One put a hidden field in the form that the main page can use as a trigger to call in the formsend script. Or.

Two put the form in the main page but put the mailsend part in a seperate mailsend.php with just a plain "Thankyou" with a link option to return to the main site.
__________________
  Reply With Quote
Old 13-09-2006, 12:25   #3 (permalink)
Dirti
Professional Idiot
 
Dirti's Avatar
 
Join Date: Aug 2006
Location: Uk
Posts: 59
Cheers, i ended up doing it the external mailsend.php page way
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8