Current location: Hot Scripts Forums » Programming Languages » PHP » Form Submission, PHP Coding Problem


Form Submission, PHP Coding Problem

Reply
  #1 (permalink)  
Old 12-02-04, 09:37 AM
kibby67 kibby67 is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Form Submission, PHP Coding Problem

I am currently setting up a html form that will allow the user to enter there information. When they hit the submit button I would like for the form to be sent to my e-mail address, a copy of it sent to the user e-mail address and for a thank you window to pop up. I have entered the code that I think is correct but when I pull up a browser to display the form part of the PHP code is showing at the bottom. Would really appriciate it if someone could take a look at this and give me any feed back of what I am doing wrong.
<?php

// get posted data into local variables
$Company = Trim($_POST[CompanyName]);
$Commodity = Trim($_POST[Commodity]);
$Tonnage = Trim($_POST[ExpectedTonnage]);
$Inbound = Trim($_POST[Inbound]);
$Outbound = Trim($_POST[Outbound]);
$RailService = Trim($_POST[RailService]);
$TruckingRate = Trim($_POST[TruckingRate]);
$SpecialRequirements = Trim($_POST[SpecialRequirements]);
$Storage = Trim($_POST[Storage]);
$Name = Trim($_POST[ContactName]);
$EmailFrom = Trim($_POST[EmailFrom]);
$Phone = Trim($_POST[PhoneNumber]);
$Fax = Trim($_POST[FaxNumber]);
$Confirmation = TRIM($_POST[Confirmation]);
$EmailTo = "myemail@mycompany.com>";


// error messages
if (Trim($CompanyName)=="")
{exit("Please enter your Company Name.");}

if (Trim($Commodity)=="")
{exit("Please enter the Commodity you would like quoted on.");}

if (Trim($ExpectedTonnage)=="")
{exit("Please enter the Expected Tonnage that you would like quoted on.");}

if (Trim($ContactName)=="")
{exit("Please enter your Name.");}

if (Trim($EmailFrom)=="")
{exit("Please enter your E-mail address.");}

if (Trim($PhoneNumber)=="")
{exit("Please enter your Phone number.");}

if (Trim(FaxNumber)=="")
{exit("Please enter your Fax number.");}

// prepare email body text
$Body .= "Rate Quote needed.\n";
$Body .= "message sent from email form.\n";
$Body .= "$CompanyName";
$Body .= "$Commodity";
$Body .= "$ExpectedTonnage";
$Body .= "$Inbound";
$Body .= "$Outbound";
$Body .= "$RailService";
$Body .= "$TruckingRate";
$Body .= "$SpecialRequirements";
$Body .= "$Storage";
$Body .= "$Contact Name";
$Body .= "$EmailFrom";
$Body .= "$PhoneNumber";
$Body .= "$FaxNumber";
$Body .= "$Confirmation";

// send email
$sendemail = mail($EmailTo, $Body, "From: $ContactName <$EmailFrom>");

// redirect to thank you page
if ($sendemail){print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.htm\">"; }
else{print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";}


// send copy of email to visitor
mail("$ContactName <$EmailFrom>", "We have recieved your message ",
"From: <myemail@mycompany>");

?>
</body>
</html>

This is the part that is showing up at the end of the form page when pulled up in a browser.

"; } else{print "";} // send copy of email to visitor mail("$ContactName <$EmailFrom>", "Armstrong Terminal has received your message ", "From: "); ?>

Any help would be greatly appriciated!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-02-04, 10:58 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
try changing from the send email to:

Code:
// send email 
$sendemail = mail($EmailTo, $Body, "From: $ContactName <$EmailFrom>");

// redirect to thank you page
if (!$sendemail) {
print '<meta http-equiv="refresh" content="0;URL=error.htm">';
exit();
}

// send copy of email to visitor
mail("$ContactName <$EmailFrom>", "We have recieved your message ", 
"From: <myemail@mycompany>");

//include thanks
include ("thanks.htm");
?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-02-04, 12:47 PM
kibby67 kibby67 is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
didn't work

tried what you suggested and now what is coming up on the bottom of the browser page is

", "We have recieved your message.", "From: "); //include thanks include ("thanks.htm"); ?>

Any more suggestions???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-02-04, 02:13 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
i have just realized you havent defined contactname!

if (Trim($ContactName)=="")
{exit("Please enter your Name.");}

but you use:

$Name = Trim($_POST[ContactName]);


Also:

$EmailTo = "myemail@mycompany.com>";

should be:

$EmailTo = "myemail@mycompany.com";
a random > in there
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form Submission script sixflagsga Script Requests 0 10-10-04 08:26 PM
Can anyone help me ? (problem using php variables in html db insert code) chronic_ PHP 2 06-13-04 12:19 PM
Limit the form submission according to time bionicsamir PHP 7 05-10-04 12:10 AM
Problem with date and form djavet PHP 3 05-02-04 01:37 AM
PHP Triad/Upload form eddyvlad PHP 6 10-07-03 12:17 AM


All times are GMT -5. The time now is 01:54 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.