bloodlinek0 Posted October 7, 2009 Share Posted October 7, 2009 Hi guys, I'm a newbie to php and need help with the script below: At the moment when I receive the automated email of data, I'm not receiving any information with the form field names I receive blank info and the html markup eg: Name: <br> Company: <br> and so on. Also how can I make the from field in the email sent to me display as that of the user who has submitted the form and included his email in the form. Site: http://experiment.treadeverywhere.com/itmb/contact.html Script below: <?php /* Subject and Email Variables */ $emailSubject = 'Crazy PHP Scripting!'; $webMaster = 'dazan@treadeverywhere.com'; /*Gathering Data Varialbes */ $forenameField = $_POST['forename']; $companyField = $_POST['company']; $positionField = $_POST['position']; $addressField = $_POST['address']; $cityField = $_POST['city']; $potscodeField = $_POST['postcode']; $telephoneField = $_POST['telephone']; $emailField = $_POST['email']; $businessmobilesField = $_POST['businessmobiles']; $blackberrysolutionsField = $_POST['blackberrysolutions']; $otherField = $_POST['other']; $timescaleField = $_POST['timescale']; $body = <<<EOD <br><hr><br> Name: $forename <br> Company: $company <br> Postion: $position <br> Address: $address <br> City: $city <br> Postcode: $postcode <br> Telephone: $telephone <br> Email: $email <br> Business Mobiles: $businessmobiles <br> Blackberry Solutions: $blackberrysolutions <br> Other: $other <br> Timescale: $timescale <br> EOD; $success = mail($webMaster, $emailSubject, $body); /*Results Rendered as html*/ $theResults = <<<EOD <html> <head> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="Dazan Alyanai" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>Unsupported Browser</title> <link rel="shortcut icon" HREF="favicon.ICO"> <style type="text/css"> <!-- * {margin: 0; padding: 0} body {font-size: 62%; background-color: #666666; font: 1em Arial, Verdana; color: #333333; } #wrapper {margin: 10em auto; padding-top: 0em; position: relative; padding: 1em; width: 400px; height: 200px; background-color: #999999; } --> </style> </head> <body> <div id="wrapper"> <h1>! Unsupported Browser !</h1> <br> <p>This Browser has known compatibility issues with modern web standards.<br><br>We recommend installing or updating to one of the following browsers.</p> <br> <a href="http://www.mozilla.com/en-US/products/download.html?product=firefox-3.5.3&os=osx&lang=en-US" style="float: right">Firefox</a><a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx">IE 7+</a> </div> </body> </html> EOD; echo "$theResults"; ?> Thanks in advance. Regards Quote Link to comment Share on other sites More sharing options...
iQue Posted October 7, 2009 Share Posted October 7, 2009 I'm no expert but this might help...the script will do what you need to, but it's a little messy. Hopefully one of the php guru's can help put this right. Just to add but as far as I know :-\ the <BR> in your code will not be valid, you will need to use \n or echo Example: echo "<br>"; Contact.html <form method="post" action="http://www.domainname.net/contact.php"> <table width="375"> <tr> <td width="357"> <div align="justify"> <input type="text" name="name" size="38" /></td> </tr> </table> <table width="375"> <tr> <td width="357"> <input type="text" name="email" size="38" /> </td> </tr> </table> ....etc, etc.... <table width="375"> <tr> <td width="357"> <textarea rows="9" name="message" cols="30"></textarea> <input type="submit" value="Send" name="submit" /> </td> </tr> </table> </form> Contact.php <?php if(isset($_POST['submit'])) { $to = "mail@domainname.net"; $subject = "Web Query"; $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $body = "From: $email\n\nName: $name\n\nPhone Number: $phone\n\nMessage:\n$message"; echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.domainname.net/contact_thanks.html\">"; mail($to, $subject, $email, $body); } else { echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.domainname.net/contect_error.html\">"; } ?> Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 7, 2009 Author Share Posted October 7, 2009 Hey Thanks for that, appreciate the alternative code but as I'm still learning I'd like to be able to modify the code I have to get it to work so I'm also learning as well as fixing . But I guess if I don't get any feedback I'll have to go with the script example you've posted for me. Regards Quote Link to comment Share on other sites More sharing options...
iQue Posted October 8, 2009 Share Posted October 8, 2009 Just been looking though your code and your Variables have Field at the end... $forenameField but in your display, it has the following... $forename There is no variables call $forename ...so no data can be retrived?? try changing to this to $forenameField and add the Field part to the rest. Give it a try it might work? :-\ Quote Link to comment Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 Due to the quizzical way in which iQue suggested the fix I thought I'd confirm/clarify. At the top you are saving all the $_POST variables in $somethingField whereas when you construct the e-mail you are using just $something, if you substitute all those values it should work (providing you have no other issues). Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 8, 2009 Author Share Posted October 8, 2009 Hi guys, It's still not working...it's displaying the results in the same way. Do you think I should just start again..it seems as though it shouldn't be this complicated to debug such a small script!? Quote Link to comment Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 Once you know how to debug a script it's probably not that complicated, post your full code as it now stands. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 8, 2009 Author Share Posted October 8, 2009 <?php /* Subject and Email Variables */ $emailSubject = 'Crazy PHP Scripting!'; $webMaster = 'dazan@treadeverywhere.com'; /*Gathering Data Varialbes */ $forename = $_POST['forename']; $company = $_POST['company']; $position = $_POST['position']; $address = $_POST['address']; $city = $_POST['city']; $potscode = $_POST['postcode']; $telephone = $_POST['telephone']; $email = $_POST['email']; $businessmobiles = $_POST['businessmobiles']; $blackberrysolutions = $_POST['blackberrysolutions']; $other = $_POST['other']; $timescale = $_POST['timescale']; $body = <<<EOD <br><hr><br> Name: $forename <br> Company: $company <br> Postion: $position <br> Address: $address <br> City: $city <br> Postcode: $postcode <br> Telephone: $telephone <br> Email: $email <br> Business Mobiles: $businessmobiles <br> Blackberry Solutions: $blackberrysolutions <br> Other: $other <br> Timescale: $timescale <br> EOD; mail($webMaster, $emailSubject, $body); /*Results Rendered as html*/ $theResults = <<<EOD <html> <head> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="Dazan Alyanai" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>Unsupported Browser</title> <link rel="shortcut icon" HREF="favicon.ICO"> <style type="text/css"> <!-- * {margin: 0; padding: 0} body {font-size: 62%; background-color: #666666; font: 1em Arial, Verdana; color: #333333; } #wrapper {margin: 10em auto; padding-top: 0em; position: relative; padding: 1em; width: 400px; height: 200px; background-color: #999999; } --> </style> </head> <body> <div id="wrapper"> <h1>! Unsupported Browser !</h1> <br> <p>This Browser has known compatibility issues with modern web standards.<br><br>We recommend installing or updating to one of the following browsers.</p> <br> <a href="http://www.mozilla.com/en-US/products/download.html?product=firefox-3.5.3&os=osx&lang=en-US" style="float: right">Firefox</a><a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx">IE 7+</a> </div> </body> </html> EOD; echo "$theResults"; ?> Quote Link to comment Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 Ok, if that's giving blank values, try putting this at the top of the page. echo '<pre>'; print_r($_POST); echo '</pre>'; To see what the $_POST array contains, sounds abit like it's empty. The HTML tags being output is probably down to the header of the e-mail, it's probably being sent as plain text. To fix that replace your call to mail() with this...I'm not sure if both headers are technically required, but it's what I've used in the past. It should solve that problem. $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=us-ascii\r\n"; mail($webMaster, $emailSubject, $body, $headers); Quote Link to comment Share on other sites More sharing options...
iQue Posted October 8, 2009 Share Posted October 8, 2009 It’s just speculation but I just looked at some of the HTML code from your site, and I think it has something to do with that...not sure what?? ...I assume that's what you are using. I tested your PHP script (modified) to suit my HTML code and it works. So it could be something to do with your field names on the text input boxes. <?php /* Subject and Email Variables */ $emailSubject = 'Crazy PHP Scripting!'; $webMaster = 'your@email.net; /*Gathering Data Varialbes */ $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $body = <<<EOD Name: $name Email: $email Phone: $phone Message: $message EOD; mail($webMaster, $emailSubject, $body); /*Results Rendered as html*/ $theResults = <<<EOD <html> <head> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="Dazan Alyanai" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>Unsupported Browser</title> <link rel="shortcut icon" HREF="favicon.ICO"> <style type="text/css"> <!-- * {margin: 0; padding: 0} body {font-size: 62%; background-color: #666666; font: 1em Arial, Verdana; color: #333333; } #wrapper {margin: 10em auto; padding-top: 0em; position: relative; padding: 1em; width: 400px; height: 200px; background-color: #999999; } --> </style> </head> <body> <div id="wrapper"> <h1>! Unsupported Browser !</h1> <br> <p>This Browser has known compatibility issues with modern web standards.<br><br>We recommend installing or updating to one of the following browsers.</p> <br> <a href="http://www.mozilla.com/en-US/products/download.html?product=firefox-3.5.3&os=osx&lang=en-US" style="float: right">Firefox</a><a href="http://www.microsoft.com/windows/internet-explorer/worldwide-sites.aspx">IE 7+</a> </div> </body> </html> EOD; echo "$theResults"; ?> Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 8, 2009 Author Share Posted October 8, 2009 I've done that and now my email comes through correctly and the html markup is treated as html markup and not displaying as text. I'm one step closer! Was going to give up after this aswell. Now all I need to do is display the results (which are still not showing) the actual html markup can still be found at: http://experiment.treadeverywhere.com/itmb/contact.html I doubt very much something has gone wrong there but maybe I've overseen something that is required for the php to work. Rgds Quote Link to comment Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 Ok, looking at the form I can see that you have the action set to contactformprocess.php, so I assume the contents you posted originally is stored in the file contactformprocess.php? Did you try putting these lines... echo '<pre>'; print_r($_POST); echo '</pre>'; ... at the top of your page and try submitting the form, It should show you the contents of the $_POST array. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 8, 2009 Author Share Posted October 8, 2009 Hi cags, yes this is true, the php file is called that, I did enter that bit of code on the top and it has made a difference in actually rendering the html as html (ie showing hr instead of displaying the text <hr> but the actual data itself is not displaying. Id its working for others it must be my html but as far as I was aware when defining the variable the name in the [] was the name given to the field in the html and this is what I have done. Is that correct? Also after entering the snippet of code you provided, the results page shows array () with no data in it. Quote Link to comment Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 If thats all you got then it means the $_POST array is empty. Which means the problem is not with this script, the problem is something to-do with the posting of the data. Looking at your HTML in the link you provided I can see that you have set the action and the method attributes correctly. So the problem seems very strange, it's possible the JavaScript is causing an issue, try removing onSubmit="return ValidateForm(contactform); from the <form> node in the HTML and see if it makes a difference. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 8, 2009 Author Share Posted October 8, 2009 Got it! it was the enctype="text/plain" that needed to be removed from the html. Who would have thought three words could cause so much grief. Anyway one last thing and you'll be glad to know it's nothing to do with debugging it's to do with how do i do it My checkboxes are rendered as on in my email which is showing me what is checked and what isn't but the radio box field is blank, how do i display what has been selected from the radio box? Quote Link to comment Share on other sites More sharing options...
cags Posted October 8, 2009 Share Posted October 8, 2009 I did consider mentioning I'd never use enctype="text/plain", but I dismissed it as being harmless, just goes to show I guess. With regards to checkboxes on a form. I believe they only appear in the $_POST array if it is checked. And it will appear in the array under the index/key of the name attribute of the <input> node with the value of the value attribute. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 8, 2009 Author Share Posted October 8, 2009 Excellent thank you all.. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 17, 2009 Author Share Posted October 17, 2009 I'm Back I'm working on radio buttons now and I can't seem to get them to pass through to the email. I've looked at a few tutorials and still none the wiser. Basically I need to know what to do to pass data through via php from my form for radio buttons. If you need the php and html again I can repost it, but a good explanation and example of how it should be done will (hopefully) suffice. Thanks again. Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 <!-- HTML --> <input type="radio" name="gender" value="male" /> <input type="radio" name="gender" value="female" /> <?php if(isset($_POST['gender'])) { echo $_POST['gender']; } ?> Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 17, 2009 Author Share Posted October 17, 2009 How would that fit into the php file that transfers the data via email. When I add the code it just echoes the results on the confirmation page but nothing gets sent through to the email. The name of the radio button is Timescale. <?php /* Subject and Email Variables */ $emailSubject = 'ITMB Form Submission'; $webMaster = 'bloodlinek0@yahoo.com'; /*Gathering Data Varialbes */ $forename = $_POST['forename']; $company = $_POST['company']; $position = $_POST['position']; $address = $_POST['address']; $city = $_POST['city']; $potscode = $_POST['postcode']; $telephone = $_POST['telephone']; $email = $_POST['email']; $businessmobiles = $_POST['businessmobiles']; $blackberrysolutions = $_POST['blackberrysolutions']; $other = $_POST['other']; $timescale = $_REQUEST['timescale']; $comments = $_POST['comments']; $body = <<<EOD <br><hr><br> Name: $forename <br> Company: $company <br> Postion: $position <br> Address: $address <br> City: $city <br> Postcode: $postcode <br> Telephone: $telephone <br> Email: $email <br> Business Mobiles: $businessmobiles <br> Blackberry Solutions: $blackberrysolutions <br> Other: $other <br> Timescale: $timescale <br> Comments: $comments <br> EOD; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=us-ascii\r\n"; mail($webMaster, $emailSubject, $body, $headers); /*Results Rendered as html*/ $theResults = <<<EOD <html> <head> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="Dazan Alyanai" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>ITMB</title> <link rel="shortcut icon" HREF="favicon.ICO"> <script type="text/javascript" src="assets/flash/swfobject.js"></script> <script type="text/javascript"> var flashvars = {}; var params = {}; params.menu = "false"; params.quality = "best"; params.scale = "noscale"; var attributes = {}; swfobject.embedSWF("assets/flash/logo.swf", "logo", "341", "86", "9.0.0", "assets/flash/expressInstall.swf", flashvars, params, attributes); </script> <link rel="stylesheet" type="text/css" href="styles.css"> <style type="text/css"> <!-- --> </style> </head> <body> <div id="wrapper"> <div id="head"> <div id="nav" style="float: right"> <ul> <li class="link"><a href="index.html">Home</a></li> <li class="link"><a href="about.html">About Us</a></li> <li class="link"><a href="web.html">Web</a></li> <li class="link"><a href="plans.html">Plans</a></li> <li class="link"><a href="partnerships.html">Partnerships</a></li> <li class="link" id="active"><a href="contact.html">Contact</a></li> </u> </div> <div id="logo"> <img src="assets/images/logo.gif" alt="ITMB" /> </div> </div> <!--Flash Banner--> <div id="banner"> <img src="assets/images/contact_banner.jpg" /> </div> <!--Row 1 Header Content (About Us..)--> <div id="content_top"> <img src="assets/images/thank_you.gif" alt="Thank You"> </div> <!--Content--> <div class="text_only" style="height: 220px"> <img src="assets/images/tick.jpg" alt="Tick" style="float: left; padding: 20px 20px 0 20px"/> <h4>Thank You for your submission.</h4> <h4>Your request will be dealt with as soon as possible and one of our representatives will contact you shortly.</h4> <p>Return to the <a href="index.html" class="standlink">Home Page</a></p> </div> <!--Footer--> <br> <img src="assets/images/networks.jpg" alt="Networks" style="margin-left: 750px" /> <div id="footer"> <address>ITMB | Copyright 2009 | All Rights Reserved</address><address style="float: left"><a class="standlink" href="index.html">ITMB</a> Registered Company Number: 06925752</address> </div> </body> </html> EOD; echo "$theResults"; ?> Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 a.) why are you using the $_REQUEST array to fetch timescale rather than the $_POST array that you are using for everything else. b.) if you want it in the e-mail you just place the $timescale variable into the e-mail. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 17, 2009 Author Share Posted October 17, 2009 I've changed the REQUEST to POST and the variable is already visible in the email but still no info in the email sent through. Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 print_r($_POST) and check that timescale is in the array. Quote Link to comment Share on other sites More sharing options...
bloodlinek0 Posted October 17, 2009 Author Share Posted October 17, 2009 Sorry I'm getting lost! :'( I've never scripted before this is the first time I've tried to do anything myself. Can you show me an example using the php script I've already posted as the base? Quote Link to comment Share on other sites More sharing options...
cags Posted October 17, 2009 Share Posted October 17, 2009 print_r is a function that prints out the contents of an array. $_POST is the superglobal array that should contain all the variables submitted from your form. If $timescale has no value that infers that $_POST['timescale'] either doesn't exist or has a blank value. Therefore I am suggesting you print out the contents of the $_POST array to find out why $timescale has no value. Quote Link to comment 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.