User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,753 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,461 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1902 | Replies: 8
Reply
Join Date: Jun 2005
Posts: 10
Reputation: vismund is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vismund vismund is offline Offline
Newbie Poster

PHP Form mailing troubles

  #1  
Jun 1st, 2005
I am absolutely 100% new to php programming, so go easy on me.

I have looked at php tutorials on how to create a simple form on a html page and then using a php script, have the contents of the form emailed to me, then it redirect to a "thank you" page. However, the php script i have at the moment is just showing a blank screen when executed.

The php code i am using:

<?php
$name = $_GET['name'] ; $company = $_GET['company'] ; $emailaddress = $_GET['emailaddress'] ; $message = $_GET['message'] ;
mail( "paul@coatesdesign.net", "Website form", $message, $company, $name, "From: $email" ); header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>


and the form code i am using on the html page:

<form action="form.php" method="post" name="form" id="form">
Name : <input name="name" type="text" id="name" size="25">
Company: <input name="company" type="text" id="company" size="30">
Email Address: <input name="emailaddress" type="text" id="emailaddress" size="50">
<textarea name="message" cols="80" rows="6" id="message"></textarea>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
</form>


The page i have it on is here

thank you very much for you help in advance.
Paul.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2005
Location: Costa Rica
Posts: 46
Reputation: RamiroS is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
RamiroS's Avatar
RamiroS RamiroS is offline Offline
Light Poster

Re: PHP Form mailing troubles

  #2  
Jun 1st, 2005
Hello vismund!

The problem is that you are not using the mail() function the right way... it is just a couple of details (check the manual ):

mail functions uses 4 parameters only. Everything goes right until the end of mail( "paul@coatesdesign.net", "Website form", $message ... the 4th parameter should be the headers. You will need to enter the company and other data inside your $message variable. If you remove everything that follows , $message you can see it work... like this:

mail( "paul@coatesdesign.net", "Website form", $message); header( "Location: http://www.coatesdesign.net/thankyou.htm" );

Try this to solve the problem:

[php]
<?php
$name = $_GET['name'] ; $company = $_GET['company'] ; $emailaddress = $_GET['emailaddress'] ; $message = $_GET['message'] ;
mail( "paul@coatesdesign.net", "Website form", $message.$company. $name. "From: $email" ); header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>

[/php]
LOTRO Tips - Lord of the Rings Online Tips & Tricks
Reply With Quote  
Join Date: Apr 2005
Location: Auckland, New Zealand
Posts: 136
Reputation: sarahk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
sarahk's Avatar
sarahk sarahk is offline Offline
Junior Poster

Re: PHP Form mailing troubles

  #3  
Jun 2nd, 2005
try

$message = "$message\n\n$company\n$name";

for some formatting where \n gives you a new line.

When you're feeling like experimenting take a look at http://phpmailer.sourceforge.net and try some html emails.

Sarah
Reply With Quote  
Join Date: Jun 2005
Posts: 10
Reputation: vismund is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vismund vismund is offline Offline
Newbie Poster

Re: PHP Form mailing troubles

  #4  
Jun 2nd, 2005
Thank you both very much for your help.
Although, i'm still finding out that it isnt working and it still shows a blank page while on www.coatesdesign.net/form.php

heres the code i have now:
[PHP]<?php
$name = $_REQUEST['name'] ; $company = $_REQUEST['company'] ; $emailaddress = $_REQUEST['emailaddress'] ; $message = "$_REQUEST['message']\n\n$company\n$name" ;
mail( "deathonthestairs@hotmail.com", "Website form", $message, "From:
$email" ); header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>[/PHP]

Is there anything i am doing wrong?
Reply With Quote  
Join Date: Jun 2005
Posts: 10
Reputation: vismund is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vismund vismund is offline Offline
Newbie Poster

Re: PHP Form mailing troubles

  #5  
Jun 2nd, 2005
Ive got the email mailing to my email address now.
Although it just emails a blank email, with the header "Website form", doesnt say who sent it, even though i filled in the email address box. Also the "header" code doesnt redirect to that page.
heres the code im using:
[php]<?php
$name = $_GET['name'] ;
$company = $_GET['company'] ;
$emailaddress = $_GET['emailaddress'] ;
$message = $_GET['message'] ;

$message = "$message\n\n$company\n$name";

mail( "paul@coatesdesign.net", "Website form", $message, "From: $emailaddress" );
header( "Location: http://www.coatesdesign.net/thankyou.htm" );
?>[/php]

The error i get on the php page is:

Warning: Cannot modify header information - headers already sent by (output started at /home/coatesd/public_html/form.php:4) in /home/coatesd/public_html/form.php on line 13
Reply With Quote  
Join Date: Apr 2005
Location: Auckland, New Zealand
Posts: 136
Reputation: sarahk is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
sarahk's Avatar
sarahk sarahk is offline Offline
Junior Poster

Re: PHP Form mailing troubles

  #6  
Jun 2nd, 2005
Somewhere at the top of the page you have a space, maybe a blank line before your <?php
Something like that. Effectively it's starting your page, get rid of it, you can't have anything before the <?php if you want to use header() in your script.

Try putting an exit; afterwards as well.

Sarah
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP Form mailing troubles

  #7  
Jun 4th, 2005
Replace php
[PHP]header( "Location: http://www.coatesdesign.net/thankyou.htm" );[/PHP]
with javascript
[PHP]?>
<script>
<!--
window.location= "http://www.coatesdesign.net/thankyou.htm"
//-->
</script>
<?php[/PHP]
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Join Date: Jun 2005
Posts: 10
Reputation: vismund is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vismund vismund is offline Offline
Newbie Poster

Re: PHP Form mailing troubles

  #8  
Jun 4th, 2005
Thank you all very very much!!
I have it working now, with it redirecting to the thanks page using javascript.

for reference, heres my code:
[PHP]
<?
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$emailaddress = $_REQUEST['emailaddress'] ;
$message = $_REQUEST['message'] ;
$message = "$message\n\n$company\n$name";

mail( "paul@coatesdesign.net", "Website form", $message, "From: $emailaddress" );
?>
<script>
<!--
window.location= "http://www.coatesdesign.net/thankyou.htm"
//-->
</script>
<?php
exit;?>[/PHP]
thanks again
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP Form mailing troubles

  #9  
Jun 7th, 2005
well done!!

Just a remark: Never use header after any other php script is called.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC