[SOLVED] Form Post Problem

This is a discussion on "[SOLVED] Form Post Problem" within the PHP Forum section. This forum, and the thread "[SOLVED] Form Post Problem are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 8th, 2007, 15:10
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Question [SOLVED] Form Post Problem

Hi,

I'm having trouble making a simple enquiry form work.

I am using a very basic example.
When I click submit I get directed to my thankyou.php but no mail is sent or received.

If I remove all but the variable $server_package from sendmail.php
I get an empty mail sent.

Here is my form code below:


Form:

Code: Select all
<form method="post" action="sendmail.php" >
  
<div id="field1"><p class="content_titles">Server Package:</p></div> 

<div id="field2">
<select id="server_package">
<option>Select Server Package</option>
<option value="Server System 1">Server System 1</option>
<option value="Server System 2">Server System 2</option>
<option value="Server System 3">Server System 3</option>
<option value="Server System 4">Server System 4</option>
<option value="Server System 5">Server System 5</option>
<option value="Server System 6">Server System 6</option>
</select>
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="field1">
<p class="content_titles">Opporating System:</p>
</div>

<div id="field2">
<select id="opporating_system">
<option>Select Opporating System</option>
<option value="OS - Windows Server 2003">Windows Server 2003</option>
<option value="OS - Ubuntu">Ubuntu Linux 6.06 TLS</option>
</select>

</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="field1">
<p class="content_titles">Rental Period:</p>
</div>

<div id="field2">
<select id="rental_period">
<option>Select Rental Period</option>
<option value="One Day">One Day</option>
<option value="Up To 1 Week">Up To 1 Week</option>
<option value="Up To 1 Month">Up To 1 Month</option>
<option value="Up To 1 Year">Up To 1 Year</option>
</select>
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="field1">
<p class="content_titles">Rental Type:</p>
</div>

<div id="field2">
<select id="rental_type">
<option>Select Rental Type</option>
<option value="Managed">Managed</option>
<option value="Un-Managed">Un-Managed</option>
</select>
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="field1">
<p class="content_titles">Contact Name:</p>
</div>

<div id="field2">
<input name="contact_name" type="text" size="25" maxlength="100" />
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="field1">
<p class="content_titles">Contact Email:</p>
</div>

<div id="field2">
<input name="contact_email" type="text" size="25" maxlength="255" />
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<div id="field1">
<p class="content_titles">Contact Telephone:</p>
</div>

<div id="field2">
<input name="contact_telephone" type="text" size="25" maxlength="25" />
</div>

<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div align="center"><INPUT TYPE="submit" VALUE="Submit Rental Form"></div>
<p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
Sendmail.php:

Code: Select all
<?php


  $server_package = $_POST['server_package'];
  $opporating_system = $_POST['opporating_system'];
  $rental_period = $_POST['rental_period'];
  $rental_type = $_POST['rental_type'];
  $contact_name = $_POST['contact_name'];
  $contact_email = $_POST['contact_email'];
  $contact_telephone = $_POST['contact_telephone'];

  mail( "mail@xxxxxxxx.com", "Server Rental Enquiry",
    $server_package, $opporating_system, $rental_period, $rental_type, $contact_name, $contact_email, $contact_telephone, "From: $contact_name <$contact_email>" );
  header( "Location: http://xxxxxxxxxxxx.com/content/thankyou.php" );
?>
Can anyone see whats wrong?

I know there are no stripslashes or anti spam measures but I didn't see much point adding all those things untill I get the inital form up and running.

Ideally I would like the form to post all the info provided to it sent in a nice readable format when it arrives.

Thanks!!!!!
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)

  #2 (permalink)  
Old Oct 8th, 2007, 15:27
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Hi Weasal,

The reason is that you are sending way too many arguments to the mail function.

Separating the variables with commas declares a new argument, you will need to concatenate them with a period..

eg.

PHP: Select all

mail"mail@xxxxxxxx.com""Server Rental Enquiry",

    
$server_package '\n' $opporating_system '\n' .  $rental_period '\n' .  $rental_type '\n' $contact_name '\n' .  $contact_email '\n' .  $contact_telephone"From: $contact_name <$contact_email>" );
  
header"Location: http://xxxxxxxxxxxx.com/content/thankyou.php); 
As you say, some security wouldn't go astray but that should send all the content for you.

Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #3 (permalink)  
Old Oct 8th, 2007, 17:30
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Hey,

Thanks. That got the form to send but all I'm getting is jibberish lol

See below:

Code: Select all
\n\n\n\nMike Form Test\nmike@xxxxxxxxxxx.com\n01235 1234568
It doesnt seem to be mailing all the form options.
It just seems to be mailing the last three input boxes but not the drop down options.

Thanks

Mike
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
  #4 (permalink)  
Old Oct 8th, 2007, 17:36
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

PHP: Select all

<?php



  $server_package 
$_POST['server_package'];
  
$opporating_system $_POST['opporating_system'];
  
$rental_period $_POST['rental_period'];
  
$rental_type $_POST['rental_type'];
  
$contact_name $_POST['contact_name'];
  
$contact_email $_POST['contact_email'];
  
$contact_telephone $_POST['contact_telephone'];

  
mail"mail@xxxxxxxx.com""Server Rental Enquiry",
    
$server_package "\n" .  $opporating_system  "\n" $rental_period  "\n" $rental_type$contact_name  "\n" $contact_email  "\n" $contact_telephone"From: $contact_name <$contact_email>" );
  
header"Location: http://xxxxxxxxxxxx.com/content/thankyou.php);
?>
Woops forgot to double quote the new lines "\n"... and you need to give the select boxes name="etc" rather just an ID
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #5 (permalink)  
Old Oct 8th, 2007, 17:42
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Thats better but I'm still not getting any results from the drop down options.
Instead I'm getting blank spaces.

Am I missing something in my form?

Thanks,

Mike
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
  #6 (permalink)  
Old Oct 8th, 2007, 17:47
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Yes, you need to give the drop down boxes names the same way as with the input boxes.

name="opporating_system" etc...
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #7 (permalink)  
Old Oct 8th, 2007, 18:19
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Thats what's missing lol... I thought ID="" was the value I needed.. lol

Thanks buddy, much appreciated.

Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
  #8 (permalink)  
Old Oct 8th, 2007, 22:34
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

How would I get this to display results like so:

Code: Select all
Hi Sales@xxxxxxxxx.com

You Have received the following Server Form Enquiry:

From $contact_name , $contact_email

Server Package: FormResult
Opporating System: Form Result

etc...
Basicaly build an email body for my results so that they display with some significance rather than just have the form results mailed.

Thanks!

Another handy feature would be to have the mailed results show the time the mail was sent if thats possible?
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)

Last edited by weasel; Oct 8th, 2007 at 22:59.
  #9 (permalink)  
Old Oct 9th, 2007, 05:36
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Try this, you can just create an aritrary string out of the variables from the form.

One extra header handles the date

PHP: Select all

<?php

    $server_package 
$_POST['server_package'];
  
$opporating_system $_POST['opporating_system'];
  
$rental_period $_POST['rental_period'];
  
$rental_type $_POST['rental_type'];
  
$contact_name $_POST['contact_name'];
  
$contact_email $_POST['contact_email'];
  
$contact_telephone $_POST['contact_telephone'];
  
  
$toAddress 'Sales@xxxxxxxx.com';
  
  
  
// Create a string that looks pretty
  
  
$message "Hello $toAddress, \n\n
                  You have received the following server form enquiry. \n\n
                Server Package: $server_package \n
                "
// so on and so forth
  
$headers "From: $contact_name <$contact_email>\n"
  
$headers .= 'Date: ' gmdate('D, d M Y H:i:s') . ' +0000' "\n"// Send the date
   
mail$toAddress"Server Rental Enquiry"$message, );
  
header"Location: http://xxxxxxxxxxxx.com/content/thankyou.php);
?>
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #10 (permalink)  
Old Oct 9th, 2007, 09:33
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

I added the other strings but now it wont send anything.
I assume I have added the other strings correctly?

Code: Select all
  // Create a string that looks pretty
  
  $message = "Hello $toAddress, \n\n
                  You have received the following server form enquiry. \n\n
                  
                Server Package: $server_package \n 
                Opporating System: $opporating_system \n
                Rental Period: $rental_period \n 
                Rental Type: $rental_type \n 
                Contact Name: $contact_name \n 
                Contact Email: $contact_email \n 
                Contact Telephone: $contact_telephone \n
                "; // so on and so forth
  $headers = "From: $contact_name <$contact_email>\n"
  $headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' +0000' . "\n"; // Send the date
   mail( $toAddress, "Server Rental Enquiry", $message, );
  header( "Location: http://xxxxxxxxxxxxxxxxx.com/content/thankyou.php" );
?>
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
  #11 (permalink)  
Old Oct 9th, 2007, 09:35
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

You need to send the headers to the mail function

PHP: Select all

mail$toAddress"Server Rental Enquiry"$message$headers ); 

Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #12 (permalink)  
Old Oct 9th, 2007, 09:41
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Thanks,

I have added the $headers string to the mail function but still nothing.

Code: Select all
mail( $toAddress, "Server Rental Enquiry", $message, $headers );
Not even the thankyou appears
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
  #13 (permalink)  
Old Oct 9th, 2007, 09:46
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

There's nothing wrong with the script that I can see.

Have you changed the $toAddress variable to your email addy?
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
  #14 (permalink)  
Old Oct 9th, 2007, 11:39
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Yes buddy,
I changed the mail address and the thank you url accordingly but when I hit submit, it just goes to a blank page.

I have just been double checking that my changes directly reflect what you told me to change and I too cannot see any errors :/

I will PM you the URL if you wish?
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
  #15 (permalink)  
Old Oct 9th, 2007, 11:52
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Syntax error - nearly slipped past

$headers = "From: $contact_name <$contact_email>\n"

add a semi colon to the end

$headers = "From: $contact_name <$contact_email>\n";
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)

Last edited by Rakuli; Oct 9th, 2007 at 12:25.
  #16 (permalink)  
Old Oct 9th, 2007, 12:20
Up'n'Coming Member
Join Date: Jul 2007
Location: England
Posts: 67
Blog Entries: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form Post Problem

Much better
Thanks very much.. your help has been greatly appreciated!!!!!!!!!

Many thanks!
Last Blog Entry: Fire In The Hole! (Jan 23rd, 2008)
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP contact form problem fl0w PHP Forum 12 Jan 31st, 2008 17:56
[SOLVED] PHP contact form redirect to same form Posie PHP Forum 14 Jan 29th, 2008 20:28
[SOLVED] Weird Problem with Form in IE Jack Franklin PHP Forum 3 Dec 20th, 2007 15:58
[SOLVED] Email Submit Form Problem, The tutorial From The Php Forum longstand PHP Forum 3 Nov 12th, 2007 20:06
[SOLVED] Problem accessing specific form elements Sagaris JavaScript Forum 4 Sep 23rd, 2007 11:52


All times are GMT. The time now is 05:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43