laflair13 Posted January 5, 2015 Share Posted January 5, 2015 Basically what I am needing is when a visitor comes to my site and request info on a product, the form sends the product id or name. I have the site set up like product.php?Item=26 and the item number changes based on the product. The page items are being populated with info stored in the mysql databse. I need the email being sent to say something like Visitors Name has requested info on Item 26Name - Visitors NameEmail - email@me.comPhone - 123-456-7890Company - Visitors CompanyItem info requested forHere is the products nameURL to product page Basically the "item info" is being pulled from the database. I have asked on different forums and I cannot get a good answer that I can use to make this happen. I might not be explaining it right. Page the form is on is (and all other new-product.php pages) http://www.packagingequipment4sale.com/new-product.php?Item=26 Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/293695-sending-mysql-data-with-contact-form/ Share on other sites More sharing options...
CroNiX Posted January 5, 2015 Share Posted January 5, 2015 In your form that pops up, I'd create a hidden input that contains the Item ID so that it gets sent with the form. Then whatever handles your form processing can look the item up by the ID and populate the product details in the email. Quote Link to comment https://forums.phpfreaks.com/topic/293695-sending-mysql-data-with-contact-form/#findComment-1501849 Share on other sites More sharing options...
CroNiX Posted January 5, 2015 Share Posted January 5, 2015 Actually I do see you already have that at the top of the form. I'm not sure what the problem is. Just grab the ID when the form is submitted and lookup the product in the db to get it's details. Quote Link to comment https://forums.phpfreaks.com/topic/293695-sending-mysql-data-with-contact-form/#findComment-1501850 Share on other sites More sharing options...
laflair13 Posted January 5, 2015 Author Share Posted January 5, 2015 (edited) Thats the issue, I dont know how to do that. All I am after is the email has the product name and page url when its sent to me. I can get it to send just the basic "name,email,phone" but I cannot get it to send the product info. Here is my code. Form Code <div id="quote"> <a href="#TB_inline?height=200&width=400&inlineId=TBForm&modal=false" class="thickbox"><img src="images/quote.gif" class="imgquote" width="297" height="72" border="0px" /></a><br /> <div id="TBThanks" style="visibility:hidden;"> <p> Thank you, we will send you a quote shortly. </p> </div><!--ends TBThanks--> <div id="TBForm" class="TBForm" style="visibility:hidden"> <p> <form id="FormTB" action=""> <input type="hidden" id="Form_ID" name="Form_ID" value="<?php echo $eid; ?>" /> <center><strong>Request a Quote</strong></center><br /> <table width="100%"> <tr> <td width="30%">*Your Name:</td><td width="20%"> </td><td width="50%"><input type="text" id="Form_Name" name="Form_Name" /></td> </tr> <tr> <td width="30%">Company Name:</td><td width="20%"> </td><td width="50%"><input type="text" id="Form_Company" name="Form_Company" /></td> </tr> <tr> <td>*Your E-Mail:</td><td> </td><td><input type="text" id="Form_Email" name="Form_Email" /></td> </tr> <tr> <td width="30%">*Phone Number:</td><td width="20%"> </td><td width="50%"><input type="text" id="Form_Number" name="Form_Number" /></td> </tr> <tr><td colspan="3"> </td></tr> <tr> <td width="100%" align="center" colspan="3"> <input type="button" class="button" name="Form_Submit" value="Request Quote" /> </td> </tr> <tr><td colspan="3"> </td></tr> <tr> <td width="100%"> <b><?php echo $itemname; ?></b><br /><br /> Manufacturer: <?php echo $manu;?><br /> Model: <?php echo $model;?><br /> Category: <?php echo $Category;?><br /> </td> </tr> </table> </form> </p> </div><!--ends TBForm--> <br /><br /> </div><!--ends quote--> JS that is in the header <script language="javascript" type="text/javascript"> $(function() { $(".button").click(function() { $.ajax({ type: "POST", url: "AJAX_Quote.php", data: $('form#FormTB').serialize(), dataType: 'json', beforeSend: function() { var name = $("#Form_Name").val(); var email = $("#Form_Email").val(); var eid = $("#Form_ID").val(); var company = $("#Form_Company").val(); var number = $("#Form_Number").val(); var dataString = 'name='+ name + '&email=' + email + '&eid=' + eid + '&Company=' + company + '&Number=' + number; //alert (dataString);return false; if (!name || !email || !message || !eid || !company || !number) { $('#output').html('All fields are required'); return false; } emailpat = /^([a-z0-9])+([\.a-z0-9_-])*@([a-z0-9])+(\.[a-z0-9_-]+)+$/i; if (!emailpat.test(email)) { $('#output').html('The e-mail address is not valid.'); return false; } }, success: function(response) { if (response.status == 'success') { $('#quote').html(''); } $('#output').html(response.errmessage); } }); }); }); </script> and the AJAX_Quote.php <?php include_once('class/class_email.php'); $Name = $_POST['name']; $Email = $_POST['email']; $Company = $_POST['Company']; $Number = $_POST['Number']; $EID = $_POST['eid']; $Location=$_POST['location']; $OurPrice=$_Post['ourprice']; $SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;"; $R_GetEquipment = mysql_query($SQL_GetEquipment, $Link); $row = mysql_fetch_assoc($R_GetEquipment); $Location = "N/A"; $OurPrice = "N/A"; if (strlen($row['location']) > 0) { $Location = $row['location']; } if (strlen($row['ourprice']) > 0) { $OurPrice = $row['ourprice']; } $EmailBody = "$Name has requested a quote from NAPE \n Information on quote request: \n Name: $Name \n Email: $Email \n Company: $Company \n Number: $Number \n \n Location: $Location \n Our Price: $OurPrice \n \n Send a quote now: http://www.packagingequipment4sale.com/admin/Admin_Quote.php?Email=$Email&EID=$EID "; $e = new email(); //First value is the URL of your server, the second the port number $e->set_server( 'mail.packagingequipment4sale.com', 26); //First value is your username, then your password $e->set_auth('noreply@packagingequipment4sale.com', 'nape112233'); //Set the "From" setting for your e-mail. The Name will be base64 encoded $e->set_sender( 'Quote Requested', 'noreply@packagingequipment4sale.com' ); //for one recipient $send_to = 'dlaflair01@gmail.com'; //you may also specify multiple recipients by creating an array like this: //$send_to = array('foo1@localhost.local', 'foo2@localhost.local', 'foo3@localhost.local'); $subject = 'Quote Request from NAPE'; $body = "$EmailBody"; if( $e->mail($send_to, $subject, $body, $headers) == true ) { //message was received by the smtp server //['last'] tends to contain the queue id so I like to save that string in the database echo 'last: '.htmlspecialchars($e->srv_ret['last']).''; }else{ //something went wrong echo 'all: '.nl2br(htmlspecialchars($e->srv_ret['all'])).''; echo 'full:'.nl2br(htmlspecialchars($e->srv_ret['full'])).''; } ?> Edited January 5, 2015 by laflair13 Quote Link to comment https://forums.phpfreaks.com/topic/293695-sending-mysql-data-with-contact-form/#findComment-1501851 Share on other sites More sharing options...
CroNiX Posted January 5, 2015 Share Posted January 5, 2015 Well it looks like you are already grabbing the product info in AJAX_Quote.php here: $SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;"; $R_GetEquipment = mysql_query($SQL_GetEquipment, $Link); $row = mysql_fetch_assoc($R_GetEquipment); So when building the $EmailBody text, you just need to add whatever extra columns you want to output based on what they're called in the db. It should already be present in $row. Something like: $EmailBody = "$Name has requested a quote from NAPE \n Information on quote request: \n Name: $Name \n Email: $Email \n Company: $Company \n Number: $Number \n \n Location: $Location \n Our Price: $OurPrice \n \n Product Name: {$row['product_name']}\n //display the product name Send a quote now: http://www.packagingequipment4sale.com/admin/Admin_Quote.php?Email=$Email&EID=$EID "; 1 Quote Link to comment https://forums.phpfreaks.com/topic/293695-sending-mysql-data-with-contact-form/#findComment-1501855 Share on other sites More sharing options...
laflair13 Posted January 5, 2015 Author Share Posted January 5, 2015 (edited) Thank You very much. I will give it a shot. **EDIT Nothing happens when I click the "request quote" button on the form. The form doesnt disappear or anything, like its not being clicked. This section <input type="button" class="button" name="Form_Submit" value="Request Quote" /> Edited January 5, 2015 by laflair13 Quote Link to comment https://forums.phpfreaks.com/topic/293695-sending-mysql-data-with-contact-form/#findComment-1501858 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.