mad wet squirrel Posted May 1, 2009 Share Posted May 1, 2009 Ok, I just spent the last few hours setting up a form that posts an email through php, and everything is working fine, thanks to lots of surfing and tutorials. My Email sends fine, confirmation page is fine, but now I need to add a little more markup to my confirmation page other than "Email sent: thanks!" The problem is, Im not sure how if I should be wrapping the php code around my html, or vice versa. It seems as if the right way to go is to code the entire page in html, and then add the php where I want the specific confirmation message to display, but cant seem to get it right. Should my page start off and end with the php <? and ?> Or should it be standard html, with all the of the php within the certain area I want the confirmation to appear? Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/ Share on other sites More sharing options...
Prismatic Posted May 1, 2009 Share Posted May 1, 2009 use regular HTML for the page, add <?php ?> tags whenever you wish to invoke php, and save the file as a .php Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823217 Share on other sites More sharing options...
laffin Posted May 1, 2009 Share Posted May 1, 2009 That sounds too simple Prismatic, we demand a complicated anwer. LOL Yep, that simple Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823221 Share on other sites More sharing options...
mad wet squirrel Posted May 1, 2009 Author Share Posted May 1, 2009 Yay! quick responses!! but I'm still stuck.. I did try that for my first attempt, but get the following error. Parse error: syntax error, unexpected T_STRING in /home/matt/public_html/atauction/confirmation.php on line 1 Heres the php code in its entirety: <? $to = "[email protected]" . ", " ; $subject = "Request From " . "Online Web Form"; $server_name = "Web Form"; if (!empty($_POST['send']) || !empty($_GET['send'])) { $action = (!empty($_POST['send'])) ? $_POST['send'] : $_GET['send']; } else { $action = ''; } $build_message = false; if($action != "") { $build_message = true; $name = trim($_POST['name']); $title = trim($_POST['title']); $business = trim($_POST['business']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $website = trim($_POST['website']); $time = time(); $date = date("F j, Y", time()); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers .= "From: $email\r\n"; $headers .= "X-mailer: " . $server_name . " Server\r\n"; } if($build_message) { /* message */ $message = " Sender Name: $name\n Sender Title: $title\n Sender Company: $business\n Sender E-Mail: $email\n Sender Phone: $phone\n Sender Website: $website\n Date Sent: $date\n Message:\n----------------------------------------\n$message \n"; if(mail($to, $subject, $message, $headers)) { $result = "<b>Thank you!!!</b>.<br />I will get back to you very soon.<br />"; } else { $result = "Sorry: An error occured, please try again later."; } } print $result; ?> posted all by it self, it works fine. but when I try to wrap it in a div, is when I get the error. Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823224 Share on other sites More sharing options...
mad wet squirrel Posted May 1, 2009 Author Share Posted May 1, 2009 Actually, here is the entire file, with the php improperly nested in my html code. (but with .php extension.) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Contact Us</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="description" content="key words!" /> <link href="scripts/interior.css" rel="stylesheet" type="text/css" /> <link href="scripts/dropdown.css" media="all" rel="stylesheet" type="text/css" /> <link href="scripts/default.css" media="all" rel="stylesheet" type="text/css" /> <!-- Internet Explorer workaround, natch. --> <script type="text/javascript" src="scripts/jquery.js"></script> <script type="text/javascript" src="scripts/jquery.dropdown.js"></script> </head> <body bgcolor="#ffffff"> <div id="topnav"> <ul id="nav" class="dropdown dropdown-horizontal"> <li class="dir">SOLUTIONS <ul> <li><a href="auction_management.html">Auction Management</a></li> <li><a href="private_label.html">Private Label</a></li> <li><a href="fundraising.html">Fund Raising</a></li> <li><a href="inventory_recovery.html">Inventory Asset Recovery</a></li> </ul> </li> <li class="dir"><a href="clients.html">CLIENTS</a></li> <li class="dir">COMPANY <ul> <li><a href="management.html">Management</a></li> <li><a href="about.html">About Us</a></li> </ul> </li> <li class="dir"><a href="news.html">NEWS</a></li> <li class="dir"><a href="contact.html">CONTACT US</a></li> </ul> </div> <div id="maincontentarea"> <?php /////////////////////////// //Begin Configuration /////////////////////////// // Your email $to = "(hiding my email from spam bots!)" . ", " ; // Email Subject $subject = "Request From " . "At Auction Web Form"; // Server name, to display in the headers $server_name = "Web Form"; /////////////////////////// //End Configuration /////////////////////////// if (!empty($_POST['send']) || !empty($_GET['send'])) { $action = (!empty($_POST['send'])) ? $_POST['send'] : $_GET['send']; } else { $action = ''; } $build_message = false; if($action != "") { $build_message = true; $name = trim($_POST['name']); $title = trim($_POST['title']); $business = trim($_POST['business']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); $website = trim($_POST['website']); $NewAuctionSolution = trim($_POST['NewAuctionSolution']); $HelpManaging = trim($_POST['HelpManaging']); $NewRevenue = trim($_POST['NewRevenue']); $Attracting = trim($_POST['Attracting']); $IncreaseCustomerLoyalty = trim($_POST['IncreaseCustomerLoyalty']); $Fundraising = trim($_POST['Fundraising']); $Liquidation = trim($_POST['Liquidation']); $time = time(); $date = date("F j, Y", time()); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers .= "From: $email\r\n"; $headers .= "X-mailer: " . $server_name . " Server\r\n"; } if($build_message) { /* message */ $message = " Sender Name: $name\n Sender Title: $title\n Sender Company: $business\n Sender E-Mail: $email\n Sender Phone: $phone\n Sender Website: $website\n \n Note - 'on' means checked for the following:\n A new auction solution: $NewAuctionSolution\n Help managing our auction solutions: $HelpManaging\n New incremental revenue streams for our site: $NewRevenue\n Attracting new customers: $Attracting\n Increase repeat visitors to our site and improve customer loyalty: $IncreaseCustomerLoyalty\n New ways to enhance our fundraising or charity efforts: $Fundraising\n Help liquidating our overstocked or excess inventory: $Liquidation\n Date Sent: $date\n Message:\n----------------------------------------\n$message \n"; if(mail($to, $subject, $message, $headers)) { $result = "<b>Thank you!!!</b>.<br />I will get back to you very soon.<br />"; } else { $result = "Sorry: An error occured, please try again later."; } } // Output a result Message print $result; ?> </div> <div id="leftnavarea"> <a href="auction_management.html">SOLUTIONS</a> <br /> <a href="clients.html">OUR TEAM</a><br /> <a href="company.html">COMPANY</a><br /> <a href="news.html">NEWS</a><br /> <a href="contact.html" id="orange">CONTACT US</a></div> <div id="auctionticker"><img name="auction_ticker" src="images/auction_ticker.jpg" width="228" height="21" border="0" alt="Auction Ticker" /></div> <div id="logo"><a href="index.html"><img name="logo_img" src="interiorImages/logo.jpg" width="352" height="83" border="0" alt="At Auction Logo" /></a></div> <div id="contact"> <div id="breadcrumbsnav"> <a href="index.html">AT AUCTION</a> > CONTACT US</div> </div> <div id="titlebanner"><img name="title_banner" src="images/contact_header.jpg" width="949" height="80" border="0" alt="Auction Management Solutions" /></div> <div id="footernav" style=" position:absolute; left:375px; top:1254px; width:600px; height:20px; visibility:visible;"> <p> <a href="index.html">Home</a> | <a href="auction_management.html">Solutions</a> | <a href="clients.html">Clients</a> | <a href="company.html">Company</a> | <a href="news.html">News</a> | <a href="contact.html">Contact Us</a> </p> </div> <div id="legalinfo" style="position:absolute; left:400px; top:1284px; width:569px; height:20px; visibility:visible;"> <p>© Copyright 2009 At Auction, All Rights Reserved</p> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823226 Share on other sites More sharing options...
Phoenix~Fire Posted May 1, 2009 Share Posted May 1, 2009 you should probably shouldn't need to do the $action = ($POST)?$POST:$GET; thing... u can just use one or the other most of the time. <?php is more.... acceptable I guess.... some servers don't let you use <?... <div><?php echo $result; ?></div> that should work... <?php print '<div>' . $result . '</div>'; ?> also works... <?php if($result){ ?> <div> <?php print $result; ?> </div> <?php } ?> just play with it, lol You're probably adding the divs in the wrong place if you get that error... T_STRING meaning extra random text that shouldn't be here. use single quotes if you don't have variables or special characters inside it... so like echo 'Hello world'; NOT echo "Hello world"; ... but use echo "HELLO \n WORLD" not echo 'Hello \n World'; and use echo "$result"; not echo '$result'; just echo "it's"; tho single quotes take special characters literally... double quotes take extra processing time, to check for and evaluate special characters... it adds up? eventually :S Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823233 Share on other sites More sharing options...
mad wet squirrel Posted May 1, 2009 Author Share Posted May 1, 2009 heh, figured it out.. It doesnt like my DTD or something in the top... <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> breaks it, if I use a standard <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> Its all good. Thank you VERY much for the replies though. Just seeing that someone was looking gave me the strength to keep looking at it myself. Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823234 Share on other sites More sharing options...
Phoenix~Fire Posted May 1, 2009 Share Posted May 1, 2009 okay nicely done, I think it's reading your initial <?xml as if it was <? or <?php ... you'll probably need to change a server setting or add a .htaccess file to override the setting... Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823236 Share on other sites More sharing options...
Phoenix~Fire Posted May 1, 2009 Share Posted May 1, 2009 or like u say, just do away with the extra heading... anyways pce Quote Link to comment https://forums.phpfreaks.com/topic/156357-solved-integrating-php-code-with-html/#findComment-823239 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.