Forum Moderators: coopster

Message Too Old, No Replies

PHP Newbie needs help

My code will not parse

         

numerouno

2:26 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



Hi all,

I have created a lovely looking form in HTML which I want users to fill in and the contents be emailed to me. I am trying to use the PHP sendmail function with no success - very frustrated!

My PHP code is:

<?php
ini_set("sendmail_from","info@example.com");
mail( "info@example.com", "Booking Enquiry", $_POST['title']
$_GET ['name'] ,
['surname'] ,
['house'] ,
['address1'] ,
['address2'] ,
['town'] ,
['county'] ,
['postcode'] ,
['telephone'] ,
['cottage'] ,
['from'] ,
['to'] ,
['adults'],
['children'] ,
['dogs'] ,
['content'] ,
['declaration'] ,
"From $_POST['email']","-finfo@example.com");
header( "Location: http://www.example.com/thankyou.html" );
?>

The idea is to just to get the form working them develop it using PHP/MySQL as I learn more. Please, please can anyone tell me how to solve the problem!

[edited by: eelixduppy at 2:31 pm (utc) on Sep. 28, 2007]
[edit reason] exemplified urls [/edit]

joelgreen

3:29 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



How about this? If your form method=post then replace all GET below with POST

<?php
ini_set("sendmail_from","info@example.com");
mail( "info@example.com", "Booking Enquiry", "{$_POST['title']}
{$_GET['name']} ,
{$_GET['surname']} ,
{$_GET['house']} ,
{$_GET['address1']} ,
{$_GET['address2']} ,
{$_GET['town']} ,
{$_GET['county']} ,
{$_GET['postcode']} ,
{$_GET['telephone']} ,
{$_GET['cottage']} ,
{$_GET['from']} ,
{$_GET['to']} ,
{$_GET['adults']},
{$_GET['children']} ,
{$_GET['dogs']} ,
{$_GET['content']} ,
{$_GET['declaration']} ,
From {$_POST['email']}");
header( "Location: http://www.example.com/thankyou.html" );
?>

numerouno

3:59 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



Thanks :) think you have solved the PHP problem, however the PHP is not returning any data I have entered the HTML form, just getting blank email apart from {$_POST['email']} is showing users email.

Guess it will be something in my HTML?

<form action="sendmail.php" method="post" class="booking_text" id="contact">

<fieldset>

<label for="title"><span>Title</span>
<select name="title">
<option value=>Mr</option>
<option value=>Mrs</option>
<option value=>Miss</option>
<option value=>Ms</option>
<option value=>Dr</option>
</select>
</label>

<label for="name">
<span>Name</span>
<input type="text" name="name" id="name" />
</label>
<label for="surname"><span>Surname</span>
<input type="text" name="surname" id="surname" /></label>
</fieldset>
<fieldset>
<label for="house"><span>House name or number</span>
<input type="text" name="house" id="house" /></label>
<label for="address1"><span>Address 1</span>
<input type="text" name="address1" id="address1" /></label>
<label for="address1"><span>Address 2</span>
<input type="text" name="address2" id="address2" /></label>
<label for="town"><span>Town or city</span>
<input type="text" name="town" id="town" /></label>
<label for="county"><span>County</span>
<input type="text" name="county" id="county" /></label>
<label for="postcode"><span>Postcode</span>
<input type="text" name="postcode" id="postcode" /></label>
</fieldset>

<fieldset>
<label for="telephone"><span>Telepone Number</span>
<input type="text" name="telephone" id="telephone" /></label>
<label for="email"><span>Email Address</span>
<input type="text" name="email" id="email" /></label>
</fieldset>

<fieldset>
<label for="cottgae"><span>Cottage required</span>
<select name="cottage">
<option value=>Croc</option>
<option value=>Tims Barn</option>
</select>
</label>
<label for="from"><span>Cottage date from</span>
<input type="text" name="from" id="from" /></label>
<label for="to"><span>Cottage date to</span>
<input type="text" name="to" id="to" /></label>
<label for="adults"><span>Number of adults</span>
<select name="adults">
<option value=>0</option>
<option value=>1</option>
<option value=>2</option>
<option value=>3</option>
<option value=>4</option>
<option value=>5</option>
<option value=>6</option>
<option value=>7</option>
</select>
</label>
<label for="children"><span>Number of children</span>
<select name="children">
<option value=>0</option>
<option value=>1</option>
<option value=>2</option>
<option value=>3</option>
<option value=>4</option>
<option value=>5</option>
</select>
</label>
<label for="dogs"><span>Number of dogs</span>
<select name="dogs">
<option value=>0</option>
<option value=>1</option>
<option value=>2</option>
<option value=>3</option>
<option value=>4</option>
<option value=>5</option>
</select>
</label>
</fieldset>

<fieldset>
<label for="content"><span>Additional information</span>
<textarea name="content" rows="10" cols="27"></textarea></label>
</fieldset>
<fieldset>
<label for="declaration" id="declaration">
<span>DECLARATION: I have read and understand Arran-Holidays conditions of hire</span>
<input type="checkbox" name="declaration" id="declaration" style="width : 15px; border: 0px"/>
</label>
</fieldset>
<div><input type="submit" value="submit" /></div>
</form>

joelgreen

4:59 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



Replace all the $_GET with $_POST in the code i posted before

numerouno

5:03 pm on Sep 28, 2007 (gmt 0)

10+ Year Member



Should have read you reply closer, using $POST has solved the problem, fantastic i'm now getting the data mailed to me.

The only prob i've got now is data is not being returned for the selection drop down boxes and the checkbox. Any solution very gratefully received!

joelgreen

9:39 am on Oct 1, 2007 (gmt 0)

10+ Year Member



Look at what you have:
<option value=>0</option>
<option value=>1</option>
...

the value is empty. It should have been like this

<option value=0>0</option>
<option value=0>1</option>
...

Or at least like this
<option>0</option>
<option>1</option>
...

[Checkboxes]

Checkbox will return value only if checked. If the checkbox value is not set in the $_POST then checkbox was not marked.