PHP - Feedback Form - Insert Into Database & Email Results
Hello:
Did my first post last week and am new to PHP. Making the jump from Classic ASP into PHP. I got some good advice last time. I have a feedback form I have been using, and it works fine for sending results to the website owner. How can I add to it so it will first add all the data to mySQL database, and then email the results to the site owner? Also, I hear about SQL injection attacks a lot - is my current code safe from that? This is what I have: contact.php Code: [Select] ... <form method="post" name="myform" action="sendmail.php"> Full Name: <input type="text" name="FullName" /> Address: <input type="text" name="Address" /> City: <input type="text" name="City" /> State: <input type="text" name="State" /> Zip: <input type="text" name="Zip" /> Phone: <input type="text" name="Phone" /> Email: <input type="text" name="Email" /> Website: <input type="text" name="Website" /> Comments: <textarea cols="43" rows="6" name="Comments"></textarea> <input type="submit" /><br /> </form> ... sendmail.php Code: [Select] <?php $FullName = $_REQUEST['FullName'] ; $Address = $_REQUEST['Address'] ; $City = $_REQUEST['City'] ; $State = $_REQUEST['State'] ; $Zip = $_REQUEST['Zip'] ; $Phone = $_REQUEST['Phone'] ; $Email = $_REQUEST['Email'] ; $Website = $_REQUEST['Website'] ; $Comments = $_REQUEST['Comments'] ; mail( "info@website.com", "Contact Request", "Full Name: $FullName\nAddress: $Address\n City: $City\n State: $State\n Zip: $Zip\n Phone: $Phone\n Email: $Email\n Website: $Website\n Comments: $Comments\n", "From: $Email" ); header( "Location: http://www.website.com/thanks.php" ); ?> Any help or coding examples would be most appreciated! Thanks! Similar TutorialsHi. Can someone show me the proper way to do a feedback form (like a "Contact US" form). I have read about SQL injections and would like to know I am protecting against it. And the proper way to store the submitted data in a database for a client's records. I have a basic form I use, but I am unable to store the data properly. Any help or a code idea would be appreciated. Thanks much. I am having trouble figuring out the right keywords to search for this, but what would I need to research if I want a user to send an email to a specific address (i.e. support@domain.com) and to have it create a new MySQL database entry, sort of like a help desk would generate? can anyone please help me that i m a new user of PHP and linux so please tell me how i can send an email when mySQL insert trigger have been generated. the scenario is like this, that when new value insert in a table (client_Table), then insert trigger is generated and the functionality of that trigger is that it gets the last inserted row Primary ID (suppose the value is '111') and get the specific audio file (with the name of "111") from specific location in Linux path (/var/lib/audio/"TablePrimaryID".wav) and send Email with audio file attachment and primary ID, to any specific Mail address. (with the help of gmail SMTP). Hi, I am new to php and I desperately need help inserting an image into my php submit form. The form works perfectly but I have no idea how to get an image to be shown when the recipeint fo the email receive it (would love to have my company logo at the top of the mail just after $message.. Below is my code : .... // Create Mail Message and Send Mail $to = 'x@domain.coma'; $subject = "Website Enquiry Received from www.domain.com"; $message = "The following message has been sent from the website." . "\n" . "\n" . "Date Sent: " . date("j F Y") . "\n" . "Date Sent: " . date("g:i a") . "\n" . "\n" . "From: $contactName $contactSurname" . "\n" . "\n" . "Their Contact & Personal Details" . "\n" . "=====================" . "\n" . "\n" . "Marital Status: $contactStatus" . "\n" . "Email: $contactEmail" . "\n" . "Cellphone Number: $contactNumber" . "\n" . "Address 1: $contactAddress1" . "\n" . "Address 2: $contactAddress2" . "\n" . "Suburb: $contactSuburb" . "\n" . "Postal Code: $contactPostalcode" . "\n" . "\n" . "\n" . $headers = "From: $contactName $contactSurname <$contactEmail>" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); mail($contactEmail, 'Confirmation of email: "' . $subject . '"', $message, $headers); // Thank You Message header('Refresh: 0; url=/quote_confirm.htm'); } } ?> the form results are being sent to the selected email address in the array ... but I need a copy sent to the admin email address as well. before adding the array addresses ... the forms results were being sent to the admin, but after adding the array ... the admin address is out of the loop. How do I get the admin@home.com address to receive a copy of the forms results? I'm not sure if it needs to be a Bcc or what? Thanks in advance. _________________________________________________ _______________________________________ $to = $_POST["to"]; if(!in_array($to,array("ian@elsewhere.com","adam@elsewhere.com","keith@elsewhere.com","sue@elsewhere.com","mark@elsewhere.com","scott@elsewhere.com","joyce@elsewhere.com","joe@elsewhere.com","ken@elsewhere.com","info@elsewhere.com"))) $to = "admin@home.com"; $subject = "Order"; Not sure exactly what my problem is here, but i have looked at this at least a hundred times and I just can't figure out what is going on. Everything works great except for the sending the email part. It displays the error "There was a problem sending the mail". The form field checking works fine, the insert into mysql works fine - - but it won't send the email. I have tried using double quotes and single quotes for the email information ($to, $subject, etc...) I have even eliminated the form data from the email information and it still doesn't send. I am hopelessly stuck at this point Any ideas?? Code below: <html> <body bgcolor = 'blue'> <div align = 'center'> <h1>test FORM</h1> </div> <p> <?php If ($_POST['submit']) //if the Submit button pressed { //collect form data $fname = $_POST['FName']; $lname = $_POST['LName']; $email = $_POST['Email']; $tel = $_POST['Tel']; $mess = $_POST['Mess']; $errorstring = ""; if (!$fname) $errorstring = $errorstring."First Name<br>"; if (!$lname) $errorstring = $errorstring."Last Name<br>"; if (!$email) $errorstring = $errorstring."Email<br>"; if ($errorstring !="") echo "<div align = 'center'><b>Please fill out the following fields:</b><br><font color = 'red'><b>$errorstring</b></font></div>"; else { $fname = mysql_real_escape_string($fname); $lname = mysql_real_escape_string($lname); $email = mysql_real_escape_string($email); $tel = mysql_real_escape_string($tel); $mess = mysql_real_escape_string($mess); $con = mysql_connect("localhost","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mec", $con); $sql="INSERT INTO formtest (FName, LName, Title, Tel, Email, Mess) VALUES ('$fname','$lname','$title','$tel','$email','$mess')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } $to = 'myemailaddress'; $subject = 'test form'; $message = 'Hello'; $headers = 'From Me'; $sent = mail($to, $subject, $message, $headers); if($sent) {print "Email successfully sent";} else {print "There was an error sending the mail";} mysql_close($con); } } ?> <p> <form action= 'testmecform.php' method= 'POST'> <table width = '640' border = '0' align = 'center'> <tr> <td align = 'right'><b>First Name</b></td> <td><input type = 'text' name = 'FName' value = '<?php echo $fname; ?>' size = '25'></td> <td><div align = 'right'><b>Telephone</b></div></td> <td><input type = 'text' name = 'Tel' value = '<?php echo $tel; ?>' size = '25'></td> </tr> <tr> <td align = 'right'><b>Last Name</b></td> <td><input type = 'text' name = 'LName' value = '<?php echo $lname; ?>' size = '25'></td> <td> </td> <td> </td> </tr> <tr> <td align = 'right'><b>Email</b></td> <td><input type = 'text' name = 'Email' value = '<?php echo $email; ?>' size = '25'></td> <td> </td> <td> </td> </tr> <tr> <th colspan = '4'><b>Please enter any additional information he </b></th> </tr> <tr> <th colspan = '4'><textarea name = 'Mess' cols = '50' rows = '10'><?php echo $mess; ?></textarea></th> </tr> <tr> <th colspan = '4'><b>Please make sure all information is correct before submitting</b></th> </tr> <tr> <th colspan = '4'><input type = 'submit' name = 'submit' value = 'Submit Form'></th> </tr> </table> </form> </body> </html> Hi... Got a slight problem with my code, it keeps telling me that there is an error in my syntax, yet I have used the same code before perfectly, and for the life of me cannot see the problem? ....any ideas? <?php if (!isset($_SESSION)) { session_start(); } // Connects to your Database mysql_connect("localhost", "justair1_mick", "guru1969") or die(mysql_error()) ; mysql_select_db("justair1_justair") or die(mysql_error()) ; $filename = ($_FILES['image']['name']); $group = $_POST['group']; $make_model = $_POST['make_model']; $seats = $_POST['seats']; $transmission = $_POST['transmission']; $doors = $_POST['doors']; $lg_bags = $_POST['lg_bags']; $sm_bags = $_POST['sm_bags']; $aircon = $_POST['aircon']; $day1 = $_POST['1_day']; $days2 = $_POST['2_days']; $days3_6 = $_POST['3_6days']; $week = $_POST['week']; $days8_13 = $_POST['8_13days']; $days14 = $_POST['14_days']; if(isset($filename)){ //This is the directory where images will be saved $target = "images/"; $target2 = $target . basename( $_FILES['image']['name']); //This gets all the other information from the form $fileA=($_FILES['image']['name']); } $updateSQL = "INSERT INTO car_groups (group, make_model, transmission, seats, doors, lg_bags, sm_bags, aircon, image) VALUES ('$group', '$make_model', '$transmission', '$seats', '$doors', '$lg_bags', '$sm_bags', '$aircon', '$filename')"; mysql_query($updateSQL) or die(mysql_error()); //Writes the photo to the server move_uploaded_file($_FILES['image']['tmp_name'], $target2); header ("Location: carhireInsert.php"); ?> It keeps telling me... "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group, make_model, transmission, seats, doors, lg_bags, sm_bags, aircon, image) ' at line 1" ..? Really stuck on this one... Any help would be apreciated.. thanks.. Mick. Hi, I'm currently learning PHP through tutorials and I am working on a webpage that filters statistics (crime records) from an SQL table and filters them by an option of years that the user has picked from a dropdown box. $desiredyear = $_POST['year'] is the year picked from the drop down box on a different page. I did not encounter any problems simply displaying the entire table until I tried to filter the crimes by year. I keep getting this error message. Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\RDEUsers\NET\400792\1.php on line 40 Here is the error line. Code: [Select] while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) And here is my code so far Code: [Select] <?php $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400792"); $conn = sqlsrv_connect($server,$connectionInfo); $desiredyear = $_POST['year']; $describeQuery='select year, force, homicide from crime where year = $desiredyear '; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Year</th><th bgcolor = "LightBlue" >Force</th><th bgcolor = "LightBlue">Homicide</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['year'].'</td>'; echo '<td>' .$row['force'].'</td>'; echo '<td>' .$row['homicide'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Please can somebody help me fix this? It's driving me mad and I've exhausted my limited knowledge on the subject. I just don't understand what I'm doing wrong. Hey all, I'm very new to php and am having an issue writing to my database with a passed value and info taking from a form and am lost as to what to do. The $comm_id is the value I am getting from another php page that I am passing in the link from the other page. I need to insert that value, the session variable, and the $cmt value, which is taken from the user input from the form. As it stands now, when I run this, the $comm_id and $u_id insert and the $cmt is blank, BUT $cmt is echoing on the screen with the proper value. Any tips or direction would be great as i've been trying to sort this out for days now and i'm stumped. <?php $host='localhost'; $user='username'; $password='password'; $dbname='db_a'; session_start(); $id_link=mysql_connect($host,$user,$password); mysql_select_db($dbname, $id_link); $comm_id = $_GET['commId']; $u_id = $_SESSION['userId']; echo $comm_id; echo $u_id; $cmt = $_POST["comm"]; mysql_query("insert into Comments values($u_id, $comm_id,'$cmt');"); echo $cmt; ?> <FORM ACTION="test.php" METHOD="POST"> <input type="text" name="comm"> <input type="SUBMIT"> </FORM> I almost have it but I am missing something. The form is being sent and the row is being created but there is not data. It is blank. I know it is something simple I am missing but I cannot figure it out
If anyone can look at my code below and tell me what I am missing to make the inputed info be seen, I would sure appreciate it.
<?php include_once('class/class_email.php'); // contact to database $connect = mysql_connect("localhost", "admin", "password") or die ("Error , check your server connection."); mysql_select_db("database"); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $company = $_POST['company']; $telephone = $_POST['telephone']; $comments = $_POST['comments']; $EID = $_POST['eid']; extract ($_POST); // Pick up the form data and assign it to variables // $id = intval($id); $fname = strip_tags($fname); $lname = strip_tags($lname); $email = strip_tags($email); $company = strip_tags($company); $telephone = intval($telephone); $query="INSERT INTO users(`id`, `fname`, `lname`, `email`,`company`,`telephone`) VALUES('$id','$fname','$lname','$email','$company','$telephone')"; echo $query; mysql_query($query) or die(mysql_error()); echo mysql_error(); $SQL_GetEquipment = "SELECT * FROM `new_equip` WHERE `id`='$EID' LIMIT 1;"; $result = mysqli_query($connect,$SQL_GetEquipment); $row = mysqli_fetch_assoc($result); $EmailBody = "$fname $lname has requested a quote from NAPE on Item $EID\n Information on quote request: \n Name: $fname $lname \n Email: $email \n Company: $company \n Number: $telephone \n Comments: $comments \n \n Information Requested for: {$row['itemname']}\n The URL to {$row['itemname']} is: http://www.mydomain.com.com/new-product.php?Item=$EID \n Click to send a quote now:\n http://www.mydomain.com.com/Admin/send-quote.php?id=$EID "; $e = new email(); //First value is the URL of your server, the second the port number $e->set_server( 'mail.mydomain.com.com', 26); //First value is your username, then your password $e->set_auth('noreply@mydomain.com', '112233'); //Set the "From" setting for your e-mail. The Name will be base64 encoded $e->set_sender( 'Quote Requested', 'noreply@mydomain.com' ); //for one recipient //$send_to = array('myemail@mydomain.com','myemail2@mydomain.com'); $send_to = ('myemail@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'])).''; } ?> Ok .I tried to look for the problem for about 1 hour but I can't see what's wrong whit the following code: In firebug the post values appear correctly like so:id=116&usern=asdawe&com=qweqw&page=116&submit=submit and the inserc() function works correctly because i tried it whit a array of data created by my; Code: [Select] <?php if(isset($_POST['submit'])) { $comment = new comment; $comment->storeform($_POST); $comment->insertc(); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<?php echo $result['article']->id ?>"/> <ul> <li> <input type="text" name="usern" id="usern" /> </li> <li> <textarea name="com" id="com" COLS=40 ROWS=6></textarea> </li> <input type="hidden" name="page" value="<?php echo $result['article']->id ?>" /> <input type="submit" name="submit" value="submit" /> </ul> </form> Code: [Select] <?php class comment{ public $id = null; public $usern = null; public $com = null; public $page = null; public function __construct($data=array() ) { if( isset($data['id']) ) $this->id= (int)$data['id']; if( isset($data['usern']) ) $this->usern= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['usern'] ); if( isset($data['com']) ) $this->com= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['com'] ); if( isset($data['page']) ) $this->page= (int)$data['page']; } public function storeform ( $params ) { // Store all the parameters $this->__construct( $params ); } public function insertc() { $con = new PDO(DBN,DB_USER,DB_PASS); $sql = "INSERT INTO comments (usern,com,page) VALUES (:usern,:com,:page)"; $st =$con->prepare($sql); $st->bindValue( ":usern", $this->usern, PDO::PARAM_STR ); $st->bindValue( ":com", $this->com, PDO::PARAM_STR ); $st->bindValue( ":page", $this->page, PDO::PARAM_INT ); $st->execute(); $this->id = $con->lastInsertId(); $con = null; } } ?> Hi everyone, I'm new to this group and new to php. I have created a multi-part form that allows the user the option to add multiple input fields to a form to upload images. Here is the form structu Code: [Select] <form action="Scripts/processreports2.php" method="post" enctype="multipart/form-data" name="report_form" target="uploader" class="reportfrm"> <fieldset> <legend>Upload your images</legend> <ol id="add_images"> <li> <input type="file" class="input" name="files[]" /> </li> <li> <input type="file" class="input" name="files[]" /> </li> <li> <input type="file" class="input" name="files[]" /> </li> </ol> <input type="button" name="addFile" id="addFile" value="Add Another Image" onclick="window.addFile(this);"/> </fieldset> <p>* indicates a required field.</p> <input name="submit" type="submit" id="submit" value="Send Info!" /> </form> Through php a maximum of three input fields are fed into an array that checks to make sure that the uploaded files are images and not some other type of file. The uploading porition of this script works. Now I am trying to get the values of the input fields as a string and insert them into the database as one record. Let's say the user has three files they want to upload. I have managed to get the files as a string ie; file1.jpg, file2.jpg, file3.jpg but what is happening is that I am getting three separate records with file1.jpg, file2.jpg, file3.jpg in them. If the user has only two files to upload then I get two separate records with file1.jpg and file2.jpg in them. (Hope that makes sense). I want one record. I have been struggling with this since Monnday and while every day I get closer, this is as close as I can get. Below is the php code. #connect to the database mysql_connect("localhost", "root", ""); mysql_select_db("masscic"); //Upload Handler to check image types function is_image($file) { $file_types = array('jpeg', 'gif', 'bmp'); //acceptable file types if ($img = getimagesize($file)){ //echo '<pre>'; //print_r($_FILES); used for testing //print_r($img); used for testing if(in_array(str_replace('image/', '', $img['mime']), $file_types)) return $img; } return false; } //form submission handling if(isset($_POST['submit'])) { //file variables $fname = $_FILES['files']['name']; $ftype = $_FILES['files']['type']; $fsize = $_FILES['files']['size']; $tname = $_FILES['files']['tmp_name']; $ferror = $_FILES['files']['error']; $newDir = '../uploads/'; //relative to where this script file resides for($i = 0; $i < count($fname); $i++) { //echo 'File name ' . $fname[$i] . ' has size ' . $fsize[$i]; used for testing if ($ferror[$i] =='UPLOAD ERR OK' || $ferror[$i] ==0) { if(is_image($tname[$i])) { //append the tmp_name($tname) to the file name ($fname) and upload to the server move_uploaded_file($tname[$i], ($newDir.time().$fname[$i])); echo '<li><span class="success">'.$fname[$i].' -- image has been accepted<br></span></li>'; }else echo '<li><span class="error">'.$fname[$i].' -- is not an accepted file type<br></span></li>'; } if (is_array($fname)) $files = implode(', ',$fname); //else $files = $fname; $sqlInsert = mysql_query("INSERT INTO files (file_names) VALUES('$files')") or die (mysql_error()); } } I have an HTML form that I have a "select" drop-down menu that is selecting the name of the person you should send to. The names are being pulled from the Database, and here is what that code for the drop-down in the form looks like: <?php echo '<select name= "First_Name" , "Last_Name">'; while( $array = mysql_fetch_assoc($result) ) { $text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"]; $value_for_select = $array["First_Name"] . " " . $array["Last_Name"] . "_" . $array["id"]; echo "<option></option>\n"; echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; } echo '</select>';?> This works perfectly. However, what I want it to do is send the form to the email address of the person that is selected in the drop-down. The email address' are already entered in each record of the database in a field called "Email". I am using the $value_for_select variable to pull the id of the record, but I am unsure how to then tell the form to send to the email address of that record? Anybody know a way that this can be done? Here is the code of the for that should be sent: <?php if($_POST){ $to = $email; $subject = "WHAT SHOULD THIS BE"; $message = "Date: $date\n\r". "Dear $First_Name, $Last_Name,\n\r". "Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah..\n\r". "Sincerely,\n". "$name \n". "$street \n". "$city, $zip \n". "$email \\n". $headers = "From: $email"; mail($to, $subject, $message, $headers); // SUCCESS! echo '<p class="notice">'. 'Thank you for your submission. '. '</p>'; // clear out the variables for good-housekeeping unset($date,$legislator,$bill,$name,$street,$city,$zip,$email); $_POST = array(); } ?> Please help! I have a form on our website that a user can fill out for custom product. I want the form data to be 1) stored into a mysql database AND after storing said data, 2) email the same data to our sales department. 1) The form data DOES get stored into mysql database (except for the first two fields, for some weird reason) 2) I added a "mail" section to the php file that stores the data into the database, but it is not working correctly. I have stripped the email portion down to sending just one of the fields in the "message" to make it easier for troubleshooting I have included here, both the form section of the html file, and the formdata.php file that processes the data for your analysis. I am relatively new to php so there are going to be some issues with security, but I can work on those after I get the store & email process to work correctly. Please review my code and see if anyone can be of assistance. I looked through the forums and couldn't find another issue that was the same as mine. If I just overlooked, please tell me the thread post #. Thanks THE FORM WHICH COLLECTS THE DATA ******************************* <form method=POST action=formdata.php> <table width="640" border=0 align="center"> <tr> <td align=right><b>First Name</b></td> <td><input type=text name=FName size=25></td> <td><div align="right"><b>Telephone</b></div></td> <td><input type=text name=Tel size=25></td> </tr> <tr> <td align=right><b>Last Name</b></td> <td><input type=text name=LName size=25></td> <td><div align="right"><b>Fax</b></div></td> <td><input type=text name=Fax size=25></td> </tr> <tr> <td align=right><b>Title</b></td> <td><input type=text name=Title size=25></td> <td><div align="right"><b>Email</b></div></td> <td><input type=text name=Email size=50></td> </tr> <tr> <td align=right><b>Company</b></td> <td><input type=text name=Comp size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Address</b></td> <td><input type=text name=Addr size=25></td> <td><div align="right"><b>Estimated Annual Volume</b></div></td> <td><input type=text name=EAV size=25></td> </tr> <tr> <td align=right><b>City</b></td> <td><input type=text name=City size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>State/Province</b></td> <td><input type=text name=SProv size=25></td> <td><div align="right"><b>Application</b></div></td> <td><input type=text name=Appl size=25></td> </tr> <tr> <td align=right><b>Country</b></td> <td><input type=text name=Ctry size=25></td> <td><div align="right"><b>Type of System</b></div></td> <td><input type=text name=Syst size=25></td> </tr> <tr> <td align=right><b>Zip/Postal Code</b></td> <td><input type=text name=ZPC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td><div align="right"><strong><font color="#FFFF00" face="Arial, Helvetica, sans-serif">COIL DESIGN</font></strong></div></td> <td><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PARAMETERS</strong></font></td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Primary Resistance (ohms)</b></td> <td><input type=text name=Pres size=25></td> <td><div align="right"><b>Primary Inductance (mH)</b></div></td> <td><input type=text name=Pind size=25></td> </tr> <tr> <td align=right><b>Secondary Resistance (ohms)</b></td> <td><input type=text name=Sres size=25></td> <td><div align="right"><b>Secondary Inductance (H)</b></div></td> <td><input type=text name=Sind size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Peak Operating Current (Amps)</b></td> <td><input type=text name=POC size=25></td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b>Output Energy (mJ)</b></td> <td><input type=text name=Egy size=25></td> <td><div align="right"><b>Output Voltage (kV)</b></div></td> <td><input type=text name=Volt size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right><b># HV Towers per Coil</b></td> <td><input type=text name=TPC size=25></td> <td><div align="right"><b># of Coils per Package</b></div></td> <td><input type=text name=CPP size=25></td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td align=right> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <th colspan=4><b>Please enter any additional information he </b></th> </tr> <tr> <th colspan=4><textarea name=Mess cols=50 rows=10 id="Message"></textarea></th> </tr> </table> </dl> <div align="center"> <p> <input type=hidden name=BodyTag value="<body bgcolor="#484589" text="#FFFFFF" link="#FFFF00" alink="#FFFFFF" vlink="#FF7F00">"> <input type=hidden name=FA value=SendMail> </p> <p><font color="#FFFF00" face="Arial, Helvetica, sans-serif"><strong>PLEASE MAKE SURE ALL INFORMATION<br> IS CORRECT BEFORE SUBMITTING</strong></font></p> <p> <input type=submit value="Submit Form"> </p> </div> </form> THE FILE THAT PROCESSES THE FORM DATA (formdata.php) *********************************************** <?php $con = mysql_connect("localhost","XXX","XXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("customform", $con); $sql="INSERT INTO formdata (Fname, Lname, Title, Comp, Addr, City, SProv, Ctry, ZPC, Tel, Fax, Email, EAV, Appl, Syst, Pres, Pind, Sres, Sind, POC, Egy, Volt, TPC, CPP, Mess) VALUES ('$_POST[Fname]','$_POST[Lname]','$_POST[Title]','$_POST[Comp]','$_POST[Addr]','$_POST[City]','$_POST[SProv]','$_POST[Ctry]','$_POST[ZPC]','$_POST[Tel]','$_POST[Fax]','$_POST[Email]','$_POST[EAV]','$_POST[Appl]','$_POST[Syst]','$_POST[Pres]','$_POST[Pind]','$_POST[Sres]','$_POST[Sind]','$_POST[POC]','$_POST[Egy]','$_POST[Volt]','$_POST[TPC]','$_POST[CPP]','$_POST[Mess]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Your Information Was Successfully Posted"; mysql_close($con); $to = "recipient email address here"; $subject = "Custom Form"; $email = $_POST['Email'] ; $message = $_POST['Comp'] ; $headers = "From: $Email"; $sent = mail($to, $subject, $message, $headers) ; if($sent) {print "Your mail was sent successfully"; } else {print "We encountered an error sending your mail"; } ?> Hi there, I'm trying to add a feedback form to my website, so that people can send me emails directly from my site. I found this code on another website, which works fine except that when the sender doesn't enter their reply email address it still sends it anyway - which is what this code is supposed to prevent. This is the code: <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "myname@mydomain.com", "Subject: $subject", $message, "From: $email" ); echo "Your message has been sent"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='feedback.php'> Your Email Address: <input name='email' type='text' size='50' /><br /><br /> Subject: <input name='subject' type='text' size='50' /><br /><br /> Message:<br /> <textarea name='message' rows='15' cols='56'> </textarea><br /> <input type='submit' name='sendEMail' value='Send Email' /> </form>"; } ?> Am I supposed to redirect the user to another page? I want it to simply say "please enter your email address" next to the email field box if the user forgets to enter it. Please help. The following code used to work in PHP 4, but it no longer works under PHP 5. Can someone take a look and let me know what needs fixing please? I'm not new to PHP, but I'm not an expert. Code: [Select] <? // Set page variables. $title = "Feedback Form"; $back = ""; $bg = '000066'; $text = 'ffffff'; $link = 'ffff00'; $vlink = 'ff0000'; $trans = 'spinoutin'; $btntag = 'text=000070 insetselection'; $txtbxtag = 'bgcolor=ffffff text=000070 cursor=ff autoactivate nohighlight'; $ip = $_SERVER['REMOTE_ADDR']; // Remove < and > from the email message. $msg = str_replace("<","",$msg); $msg = str_replace(">","",$msg); // Set email variables. $your_email = 'email@mydomain.com'; $your_name = 'Joe Blogs'; $your_link = 'http://www.mydomain.com/'; $confirm_sub = 'Message Sent'; $confirm_msg = "Hi $feedbackname, Thank you for your email message sent from the $sub. I will respond to it as quickly as I can. Thanks again, $your_name $your_link"; $contact_msg = "$feedbackname ($feedbackemail) wrote: $msg $ip"; // Begin the sendmail routine. if ($send) { if (!$feedbackname || !$feedbackemail || substr_count($feedbackemail, '@') < 1 || substr_count($feedbackemail, '.') < 1 || !$sub || !$msg || substr_count($spam, 'clark') < 1) { print <<<EOF <html> <title>Error!</title> <body background="$back" bgcolor="$bg" text=$text link=$link vlink=$vlink transition=$trans fontsize=medium> <center> <br><br> <font s=7 c=f0><b> Error!</b></font> <p> Please go back and correct the errors listed below: <p> <table> <tr><td> <ul> EOF; if (!$feedbackname) { print "<li>Your name is missing!<br>"; } if (!$feedbackemail || substr_count($feedbackemail, '@') < 1 || substr_count($feedbackemail, '.') < 1) { print "<li>Your email is missing or invalid!<br>"; } if (!$sub) { print "<li>The email subject is missing!<br>"; } if (!$msg) { print "<li>The email message is missing!"; } if (substr_count($spam, 'clark') < 1) { print "You need to correctly type in the Anti-Spam word. Hit Back and try again."; } print <<<EOF </ul> </table> <p> <A href="feedback.php">Back</A> <br><br><br><br> </center> </body> </html> EOF; } else { // Email that gets sent to you. mail($your_email, $sub, $contact_msg, "From: $feedbackname < $feedbackemail >"); // Email that gets sent to them. mail($feedbackemail, $confirm_sub, $confirm_msg, "From: $your_email"); // Print the thank you page. print <<<EOF <html> <head><title>Message Sent</title> </head> <body background="$back" bgcolor="$bg" text=$text link=$link vlink=$vlink transition=$trans> <H2>Feedback</H2> Thanks $feedbackname for sending your message to me!<P> You will receive a confirmation email momentarily.<P> </body> </html> EOF; } } else { // Print the contact form page. print <<<EOF <H3>Feedback Form</H3> To send an email to me simply fill out the form below.<P> <form method=post> Name: <input name=feedbackname $txtbxtag size=40><P> Email: <input name=feedbackemail $txtbxtag size=40><P> <INPUT type="hidden" name="sub" value="Feedback Form"> Message:<br> <textarea name=msg rows=10 cols=50 maxlength=500 $txtbxtag></textarea><P> <IMG SRC="images/sh-layout/turing.jpg" WIDTH="100" HEIGHT="30" BORDER="0" ALT="turing"><BR> Anti-Spam Measure - In lowercase letters, retype the word in the image above:<BR> <input name=spam $txtbxtag size=40><P> <INPUT TYPE=submit NAME=send $BTNTAG VALUE="Send"><BR> </form> EOF; } ?> Help! I'm stuck! This is the feedback form file I made. Code: [Select] <html> <head><title>Bob's Auto Parts - Customer Feedback</title></head> <body> <h1>Customer Feedback</h1> <p>Please tell us what you think.</p> <form action="processfeedback.php" method="post"> <p>Your name:<br/> <input type="text" name="name" size="40" /></p> <p>Your email address:<br/> <input type="text" name="email" size="40" /></p> <p>Your feedback:<br/> <textarea name="feedback" rows="8" cols="40" wrap="virtual" /></textarea></p> <p><input type="submit" value="Send feedback" /></p> </form> </body> </html> And this is the process feedback file I made. Code: [Select] <?php //create short variable names $name = trim($_POST['name']); $email = trim($_POST['email']); $feedback = trim($_POST['feedback']); //set up some static information $toaddress = "wolocaw@localhost"; $subject = "Feedback from web site"; $mailcontent = "Customer name: ".$name."\n". "Customer email: ".$email."\n". "Customer comments:\n".$feedback."\n"; $fromaddress = "From: webserver@example.com"; //invoke mail() function to send mail mail($toaddress, $subject, $mailcontent, $fromaddress); ?> <html> <head> <title>Bob's Auto Parts - Feedback Submitted</title> </head> <body> <h1>Feedback submitted</h1> <p>Your feedback (shown below) has been sent.</p> <p><?php echo nl2br($mailcontent); ?> </p> </body> </html> After I fill out the form, it brings me to a page that says "Feedback submitted" at the top and "Your feedback (shown below) has been sent." below it. And that's it. nl2br($mailcontent) doesn't do anything. What am I doing wrong? I don't understand! Hello: I have this form below that stores the data in a database, and sends an email to my client so he gets the information (And if there is a more proper way to code this, I am all ears): Code: [Select] <?php include('include/myConn.php'); ?> <html> ... <?php $error = NULL; $myDate = NULL; $ParentsName = NULL; $BestPhone = NULL; $Email = NULL; $StudentsName = NULL; $StudentsSchool = NULL; if(isset($_POST['submit'])) { $myDate = $_POST['myDate']; $ParentsName = $_POST['ParentsName']; $BestPhone = $_POST['BestPhone']; $Email = $_POST['Email']; $StudentsName = $_POST['StudentsName']; $StudentsSchool = $_POST['StudentsSchool']; if(empty($ParentsName)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the parent\'s name.</div>'; } if(empty($BestPhone)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the best phone number to reach you.</div>'; } if(empty($Email) || !preg_match('~^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$~',$Email)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter a valid email.</div>'; } if(empty($StudentsName)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the student\'s name.</div>'; } if(empty($StudentsSchool)) { $error .= '<div style=\'margin-bottom: 6px;\'>- Enter the student\'s school.</div>'; } if($error == NULL) { $sql = sprintf("INSERT INTO mySignUpData(myDate,ParentsName,BestPhone,Email,StudentsName,StudentsSchool) VALUES ('%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($myDate), mysql_real_escape_string($ParentsName), mysql_real_escape_string($BestPhone), mysql_real_escape_string($Email), mysql_real_escape_string($StudentsName), mysql_real_escape_string($StudentsSchool); if(mysql_query($sql)) { $error .= '<div style=\'margin-bottom: 6px;\'>Thank you for using the sign-up sheet.</div>'; mail( "me@mywebsite.com", "Sign-up Sheet Request", "Date Sent: $myDate\n Parent's Name: $ParentsName Best Phone: $BestPhone Email: $Email Student's Name: $StudentsName Student's School: $StudentsSchool\n ", "From: $Email" ); unset($ParentsName); unset($BestPhone); unset($Email); unset($StudentsName); unset($StudentsSchool); } else { $error .= 'There was an error in our Database, please Try again!'; } } } ?> <form name="myform" action="" method="post"> <input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" /> <div id="tableFormDiv2"> <fieldset> <hr /> </fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">* - Required</span></span> <span class="floatFormLeft"> </span></fieldset> <?php echo '<span class="textError">' . $error . '</span>';?> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Parent's Name:</span> <span class="floatFormLeft"><input type="text" name="ParentsName" size="45" maxlength="50" value="<?php echo $ParentsName; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Best Phone # To Reach You:</span> <span class="floatFormLeft"><input type="text" name="BestPhone" size="45" maxlength="50" value="<?php echo $BestPhone; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Email:</span> <span class="floatFormLeft"><input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Student's Name:</span> <span class="floatFormLeft"><input type="text" name="StudentsName" size="45" maxlength="50" value="<?php echo $StudentsName; ?>" /></span></fieldset> <fieldset><span class="floatLeftFormWidth2"><span class="textErrorItalic">*</span> Student's School:</span> <span class="floatFormLeft"><input type="text" name="StudentsSchool" size="45" maxlength="50" value="<?php echo $StudentsSchool; ?>" /></span></fieldset> </div> <input type="submit" name="submit" value="Click here to submit your registration form" class="submitButton2" /><br /> </form> </html> I want to add a feature that will also send an autoresponder email with a message to the user who submitted the form. How can that be done? Do I need to somehow revise this section: Code: [Select] mail( "me@mywebsite.com", "Sign-up Sheet Request", "Date Sent: $myDate\n Parent's Name: $ParentsName Best Phone: $BestPhone Email: $Email Student's Name: $StudentsName Student's School: $StudentsSchool\n ", "From: $Email" Please let me know and thanks in advance. Hello: I want to create a feedback form that will allow a user to select from 30 or so items on a page, and send the data to an email address. I think it's something like a shopping cart but without a need to process a payment. I want to list items (like a soccer ball, a basket ball, etc.) and allow the user to select the size of the ball, the color, the number of balls, etc. I want the user to be able to select 1 item or many items. Once they are done, they would hit submit, and the data would get sent to an email address. Do I need to use a session to do this? I was trying to work with this code: Code: [Select] <?php session_start(); session_register('product'); session_register('amount'); $_SESSION['product'] = $_POST['product']; $_SESSION['amount'] = $_POST['amount']; //SEND THE EMAIL CODE HERE ???? ?> <form method="post" action=""> <input type="text" size="10" name="product"><br /> <input type="text" size="10" name="amount"><br /> <input type="submit" value="Finish"> </form> But I'm pretty sure I'm not in the ballpark on how to do this. Anyone have any ideas? Thanks in advance. |