UK Webmaster Talk - Online Marketing - SEO


 

PHP help for an amateur

This is a discussion on PHP help for an amateur within the Php and MySQL forums, part of the Programming / Scripting / Coding category; Hi, I am new on here and having trouble developing a php script for a web to email form. When ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Website Design & Development > Programming / Scripting / Coding > Php and MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 09-10-2006, 19:01   #1 (permalink)
Newbie
 
Join Date: Oct 2006
Posts: 10
iTrader: 0 / 0%
wurzel is an unknown quantity at this point
Default PHP help for an amateur

Hi,

I am new on here and having trouble developing a php script for a web to email form. When I submit the form, the browser brings up a dialog box asking whether to open or save the 'sendmail.php'

This is the problematic script:

<?php
$email = $_REQUEST['email'] ;
$yourmessage = $_REQUEST['yourmessage'] ;
$name = $_REQUEST['name'] ;
$address = $_REQUEST['address'] ;
$postcode = $_REQUEST['postcode'] ;
$phoneno = $_REQUEST['phoneno'] ;
$preferred_means_of_contact = $_REQUEST['preferred_means_of_contact'] ;

mail( "myemail@mydomain.com", "Feedback Form Results",
"$yourmessage", "From: $email", "$embody = $name $address $postcode $phoneno $preferred_means_of_contact" ) ;
header( "Location: http://www.mydomain.co.uk/contact_thanks.html" ) ;
?>

Any help would be greatly appreciated.
wurzel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 09-10-2006, 23:25   #2 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

I'd guess that your web server is not configured to execute PHP for a .php file.

Is this your own PC or a webhost ?
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 08:03   #3 (permalink)
Newbie
 
Join Date: Oct 2006
Posts: 10
iTrader: 0 / 0%
wurzel is an unknown quantity at this point
Default

Thanks for the reply, Alex. The server is configured for php - in fact, the script works fine if I just request the email address and message - any more, and it creates problems.
wurzel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 09:23   #4 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

Looks like a local config problem, bunged it onto my test server and it works OK with data passed in each field.

Don't any any more time at the moment to help, maybe later if I have time.
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 10:23   #5 (permalink)
Newbie
 
Join Date: Oct 2006
Posts: 10
iTrader: 0 / 0%
wurzel is an unknown quantity at this point
Default

Thanks Alex, I will let you know if I manage to crack it in the meantime
wurzel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 16:08   #6 (permalink)
Newbie
 
Join Date: Oct 2006
Posts: 10
iTrader: 0 / 0%
wurzel is an unknown quantity at this point
Default

I have modified the script and removed '$embody'. So the script no looks like this:

Code:
<?
  $email = $_REQUEST['email'] ;
  $yourmessage = $_REQUEST['yourmessage'] ;
  $name = $_REQUEST['name'] ;
  $address = $_REQUEST['address'] ;
  $postcode = $_REQUEST['postcode'] ;
  $phoneno = $_REQUEST['phoneno'] ;
  $preferred_means_of_contact = $_REQUEST['preferred_means_of_contact'] ;

  mail( "myname@btinternet.com", "Feedback Form Results",
    "$yourmessage", "From: $email", "$name", "$address", "$postcode", "$phoneno", "$preferred_means_of_contact");
  header( "Location: http://www.mydomain.co.uk/contact_thanks.html" );
?>
When I submit the form, the browser displays the following error message:

Quote:
Warning: mail() expects at most 5 parameters, 9 given in /home/fhlinux181/b/mydomain.co.uk/user/htdocs/sendmail.php on line 11

Warning: Cannot modify header information - headers already sent by (output started at /home/fhlinux181/b/mydomain.co.uk/user/htdocs/sendmail.php:11) in /home/fhlinux181/b/mydomain.co.uk/user/htdocs/sendmail.php on line 12
Any further help greatly appreciated.
wurzel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 16:35   #7 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

Make the <?php the very first line in the file, otherwise the blank lines will be output prior to the php being executed. Once some content has been sent, then you are no longer able to send a header value.

Alternatively you can look at output buffering in the PHP manual if you want to send headers in your code after the content.
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 17:32   #8 (permalink)
Newbie
 
Join Date: Oct 2006
Posts: 10
iTrader: 0 / 0%
wurzel is an unknown quantity at this point
Default

Tried putting php tag on first line - no difference.....will have a fiddle with output buffering tonight.

Many thanks
wurzel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-2006, 20:00   #9 (permalink)
Newbie
 
Join Date: Oct 2006
Posts: 10
iTrader: 0 / 0%
wurzel is an unknown quantity at this point
Arrow

I have cracked it!!!!

Code:
<?php
  $email = $_REQUEST['email'] ;
  $yourmessage = $_REQUEST['yourmessage'] ;
  $name = $_REQUEST['name'] ;
  $address = $_REQUEST['address'] ;
  $postcode = $_REQUEST['postcode'] ;
  $phoneno = $_REQUEST['phoneno'] ;
  $actual_message = $yourmessage."\n--------------------\n".$name."\n".$address."\n".$postcode."\n".$phoneno."\n" ;
  
  mail( "myname@btinternet.com", "Feedback Form Results",
    "$actual_message", "From: $email");
  header( "Location: http://www.mydomain.co.uk/contact_thanks.html" );
?>
Did it by putting all the parameters into $actual_message, and then adding that to mail.

Thanks for your help, Alex
wurzel is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-10-2006, 09:11   #10 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

Good to see you're working now. Much better feeling when you resolve the issue yourself rather than having help
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
amateur, php

Thread Tools
Display Modes

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


All times are GMT +1. The time now is 18:50.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

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