PHP - Php Contact Form Fields... What Am I Doing Wrong?
I'm making a contact form using PHP, I've got the look of the form done and I'm very happy with the look - but the actual email bit is a bit challenging. I'm using the code from a contact form on css-tricks.com, and the script does send emails... and I receive them but the emails are completely blank apart from the 'name: email: message:' stuff and the subject. What am I doing wrong? Here is the code I am using:
contact.html Code: [Select] <form method="post" action="contactengine.php" id="commentForm"> <div class="form"> <p><input type="text" name="fullName" id="firstName" class="required" title="Full name" /></p> <p><input type="text" name="emailAddress" id="emailAddress" class="required" title="Email Address" /></p> <p><textarea type="text" name="message" id="message" class="required" title="Message"></textarea></p> </div> <p><input type="submit" name="submit" value="Submit" class="submit-button" title="Send" /></p> </form> contactengine.php $EmailFrom = "enquiries@aplinnovations.co.uk"; $EmailTo = "info@aplinnovations.co.uk"; $Subject = "Contact Form Submission"; $fullName = Trim(stripslashes($_POST['Name'])); $emailAddress = Trim(stripslashes($_POST['Email'])); $message = Trim(stripslashes($_POST['Message'])); $Body = ""; $Body .= "Name: "; $Body .= $fullName; $Body .= "\n"; $Body .= "Email: "; $Body .= $emailAddress; $Body .= "\n"; $Body .= "Message: "; $Body .= $message; $Body .= "\n"; $success = mail($EmailTo, $Subject, $Body, "From: $emailAddress"); I really have no idea how to code in PHP, I know I'm a newbie and I'm sure this is a really dumb question... but please help! Thanks Similar TutorialsHi I am learning PHP and working on a Contact Us page with a required fields. For some reason it works great for the name and email, but always says please enter your phone number. If you guys have a better way of doing this please let me know. Also if the email is sent successfully I want it to goto the page "success.html" this part works good though just need some help please Here is the form: Code: [Select] <form action="contact.php" method="post" id="contactform"> <ol> <li> <label for="name">Full Name <span class="red">*</span></label> <input id="name" name="name" class="text" /> </li> <li> <label for="email">Your email <span class="red">*</span></label> <input id="email" name="email" class="text" /> </li> <li> <label for="phone">Phone Number <span class="red">*</span></label> <input id="phone" name="phone" class="text" /> </li> <li> <label for="company">Company</label> <input id="company" name="company" class="text" /> </li> <li> <label for="topic">Subject<span class="red">*</span></label> <input id="topic" name="topic" class="text" /> </li> <li> <label for="comments">Message <span class="red">*</span></label> <textarea id="comments" name="comments" rows="6" cols="50"></textarea> </li> <li class="buttons"> <input type="image" name="imageField" id="imageField" src="images/send.gif" /> </li> </ol> </form> The PHP code I tried: Code: [Select] <?php // Pick up the form data and assign it to variables $name = check_input ($_POST['name'], "Please enter your name"); $email = check_input ($_POST['email'],"Please enter your email"); $phone = check_input ($_POST['phone'], "Please enter your phone number"); $company = $_POST['company']; $topic = check_input ($_POST['topic'], "Please enter your subject"); $comments = check_input ($_POST['comments'], "Please enter your message"); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if (strlen($data) == 0) { die($problem); } else { return $data; } } // Build the email (replace the address in the $to section with your own) $to = 'email@email.com"'; $subject = "New message: $topic"; $message = "Email: $email \n Phone: $phone \n Company: $company \n $name said: $comments"; $headers = "From: $email"; // Send the mail using PHPs mail() function mail($to, $subject, $message, $headers); // Redirect header("Location: success.html"); ?> Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: I am writing an email form for my site with some simple validation. I have the error messages working just fine. They do what they are supposed to do. However, when the form is brought back up to have the errors fixed. It puts a "1" in the field box. I looked at the code and I do not see where the "1" is coming from. I am also in the process of trying to figure out how to send email through my mail account using smtp. I want to see if it is going to send me the information that I ask for or the "1". Currently all of my work is being done on my localhost server Here is the code that I am using Code: [Select] <?php $email_form = "<form action='' target='' id='contactform' method='post'>\n"; $email_form .="<p class='form_header'>Contact us</p>\n"; $email_form .= "<fieldset>\n"; $email_form .= "<P>\n"; $email_form .= "<label for='name'><em>*</em> Your Name:</label>\n"; $email_form .= "<input type='text' name='name' id='name' value=".(isset($_POST['name']))." />\n"; $email_form .= "</p>\n"; $email_form .= "<p>\n"; $email_form .= "<label for='email'><em>*</em> E-mail:</label>\n"; $email_form .= "<input type='text' name='email' id='email' value=".(isset($_POST['email']))." />\n"; $email_form .= "</p>\n"; $email_form .= "<p>\n"; $email_form .= "<label for='subject'>Subject:</label>\n"; $email_form .= "<input type='text' name='subject' id='subject' value=".(isset($_POST['subject']))." />\n"; $email_form .= "</p>\n"; $email_form .= "<p>\n"; $email_form .= "<label for='message'><em>*</em> Message:</label>\n"; $email_form .= "<textarea name='message' id='message'>".(isset($_POST['message']))."</textarea>\n"; $email_form .= "</p>\n"; $email_form .= "<input type='submit' id='submit' value='Submit!' name='submitted' /><br />\n"; $email_form .= "<p class='required'>Fields marked with an asterik(*) are required</p>\n"; $email_form .= "</fieldset>\n"; if (!isset($_POST['submitted'])) { echo "$email_form"; } else { $name = (isset($_POST['name'])); $email = (isset($_POST['email'])); $to = "your@email.co.uk"; $subject = (isset($_POST['subject'])); $body = (isset($_POST['message'])); if ($subject == "") { $subject = "Email from website"; } else { $subject == $subject; } if ($_POST['name'] != "") { $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING); if ($_POST['name'] == "") { $errors .= 'Please enter a valid name.<br/><br/>'; } } else { $errors .= 'Please enter your name.<br/>'; } if ($_POST['email'] != "") { $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors .= "$email is <strong>NOT</strong> a valid email address.<br/>"; } } else { $errors .= 'Please enter your email address.<br/>'; } if ($_POST['message'] != "") { $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING); if ($_POST['message'] == "") { $errors .= 'Please enter a message to send.<br/>'; } } else { $errors .= 'Please enter a message to send.<br/>'; } if (empty($errors)) { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: " . $email . "\r\n"; $success = mail($to, $subject, $body, $headers); } if ($success) { echo "<p>The following email has been sent</p>\n"; echo "<p>Name: $name</p>\n"; echo "<p>E-mail: $email</p>"; echo "<p>Subject: $subject</p>\n"; echo "<p><em>*</em> Message: $body</p>\n"; echo "<p>While you are waiting for a response from one of our staff members. Feel free to look at some of the following sections</p>\n"; echo "<a href='../waiting.php'>In The Mail</a>"; echo "Thank you for visiting Michael48060.</p>\n"; } else echo "$email_form"; } if (!empty($errors)) { echo "<div class='error_div'> <span class='errors'>" . $errors . "</span> </div>"; } ?> Hello All: Trying to work with PHP on a contact form with a jQuery Validation to make certain that the visitors fill out the required information. I'll try to show everything that I have, and then the error I am getting when the visitor hits "submit." I don't know PHP all that well, and trying to learn my way through it. I used a couple of tutorials to add the features I needed and did my own styling on the live site. Here is the PHP that is currently in the header of my markup: <?php //If the form is submitted if(isset($_POST['submit'])) { //Check to make sure that the First name field is not empty if(trim($_POST['firstname']) == '') { $hasError = true; } else { $firstname = trim($_POST['firstname']); } //Check to make sure that the Last name field is not empty if(trim($_POST['lastname']) == '') { $hasError = true; } else { $lastname = trim($_POST['lastname']); } //Check to make sure that the Street Address 01 field is not empty if(trim($_POST['street01']) == '') { $hasError = true; } else { $street01 = trim($_POST['street01']); } //If Street02 is filled out, give it a value $street02 = $_POST['street02']; //Check to make sure that the City field is not empty if(trim($_POST['city']) == '') { $hasError = true; } else { $city = trim($_POST['city']); } //Check to make sure that the State field is not empty if(trim($_POST['state']) == '') { $hasError = true; } else { $state = trim($_POST['state']); } //Check to make sure that the Zip field is not empty if(trim($_POST['zip']) == '') { $hasError = true; } else { $zip = trim($_POST['zip']); } //If Email is filled out, give it a value $email = $_POST['email']; //If Telephone is filled out, give it a value $telephone = $_POST['telephone']; //Default Subject Value $subject = "VMC Inquiry"; //Check checkboxes foreach($_POST['check'] as $value) { $check_msg = "Checked: $value\n"; } //If Message is filled out, give it a value $comment = $_POST['comment']; //If there is no error, send the email if(!isset($hasError)) { $emailTo = 'xxxx.xxxx@gmail.com'; //Put your own email address here $body = "Name: $firstname $lastname \n\nStreet Address: $street01 \n\nStreet Address*: $street02 \n\nCity: $city \n\nState: $state \n\nZip: $zip \n\nEmail*: $email \n\nTelephone*: $telephone \n\nCheck Box: $check_msg \n\nMessage:\n $comment"; $headers = 'From: XXXXX <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> So basically I am using classes to say whether or not something is required, which ties into the jQuery validation. If it isn't required, whatever the visitor types into the box is put into something like "$telephone" which is then printed in the e-mail. The markup for the forms in the body is the following: Code: [Select] <p class="contact-text-right">For more information, or to have a list of our properties mailed to you, please fill out the form below.</p> <div id="contact-wrapper"> <?php if(isset($hasError)) { //If errors are found ?> <p class="error">Please check if you've filled all the fields with valid information. Thank you.</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?> <p class="accept"><strong><?php echo $firstname;?>,Your Email Successfully Sent!</strong></p> <?php } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <div id="names"> <label for="firstname"><strong>First Name:</strong></label> <input type="text" name="firstname" id="firstname" value="" class="required" /> <label for="lastname"><strong>Last Name:</strong></label> <input type="text" name="lastname" id="lastname" value="" class="required" /> </div> <div id="address01"> <label for="street01"><strong>Street Address:</strong></label> <input type="text" name="street01" id="street01" value="" class="required" /> </div> <div id="address02"> <label for="street02"><strong>Street Address*:</strong></label> <input type="text" name="street02" id="street02" value="" /> </div> <div id="city"> <label for="city"><strong>City:</strong></label> <input type="text" name="city" id="city" value="" class="required city" /> <label for="state"><strong>State:</strong></label> <input type="text" name="state" id="state" value="" class="required state" /> <label for="zip"><strong>Zip Code:</strong></label> <input type="text" name="zip" id="zip" value="" class="required zip" /> </div> <div id="email"> <label for="email"><strong>E-mail*:</strong></label> <input type="text" name="email" id="email" value="" class="email"/> <label for="telephone"><strong>Telephone*:</strong></label> <input type="text" name="telephone" id="telephone" value="" class="telephone" /> <p class="bottom">*Optional fields.</p> </div> <div class="checkbox"> <p><input type="checkbox" name="check[]" value="properties">XXX</p> <p><input type="checkbox" name="check[]" value="contact-regarding">XXXX</p> <p class="indent">(Please list properties or ask specific questions in the space below.)</p> </div> <div id="comment"> <label for="comment"></label> <textarea name="comment" id="comment" ></textarea> </div> <div id="button"> <input type="submit" value="Send Message" name="submit" /> </div> </form> All seems well until I hit submit on the live site. I think get this error returned to me: Warning: Invalid argument supplied for foreach() in ......./html/development/contact.php on line 64 The e-mail goes through, with all the information, no problems! I just can't get this error message to go away. Line 64 of contact.php is where the checkbox coding is: //Check checkboxes foreach($_POST['check'] as $value) { $check_msg = "Checked: $value\n"; } I know I've submitted a lot of code here, and tried to narrow you down to the exact spot I think the problem is, but hopefully some of you PHP gurus can pick out the flaw in a heartbeat. I really appreciate all the help. B Hello, I have coded a contact form in PHP and I want to know, if according to you, it is secure! I am new in PHP, so I want some feedback from you. Moreover, I have also two problems based on the contact form. It is a bit complicated to explain, thus, I will break each of my problem one by one. FIRST:The first thing I want to know, is if my contact form secure according to you: The HTML with the PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables to elements $first = htmlentities($_POST['first']); $last = htmlentities($_POST['last']); $sub = htmlentities($_POST['subject']); $email = htmlentities($_POST['email']); $web = htmlentities($_POST['website']); $heard = htmlentities($_POST['heard']); $comment = htmlentities($_POST['message']); $cap = htmlentities($_POST['captcha']); //Declaring the email address with body content $to = 'alithebestofall2010@gmail.com'; $body ="First name: '$first' \n\n Last name: '$last' \n\n Subject: '$sub' \n\n Email: '$email' \n\n Website: '$web' \n\n Heard from us: '$heard' \n\n Comments: '$comment'"; //Validate the forms if (empty($first) || empty($last) || empty($sub) || empty($email) || empty($comment) || empty($cap)) { echo '<p class="error">Required fields must be filled!</p>'; header ('refresh= 3; url= index.php'); return false; } elseif (filter_var($first, FILTER_VALIDATE_INT) || filter_var($last, FILTER_VALIDATE_INT)) { echo '<p class="error">You cannot enter a number as either the first or last name!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Incorrect email address!</p>'; return false; } elseif (!($cap === '12')){ echo '<p class="error">Invalid captcha, try again!</p>'; return false; } else { mail ($to, $sub, $body); echo '<p class="success">Thank you for contacting us!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p>Your first name: <span class="required">*</span></p> <p><input type="text" name="first" size="40" placeholder="Ex: Paul"/></p> <p>Your last name: <span class="required">*</span></p> <p><input type="text" name="last" size="40" placeholder="Ex: Smith"/></p> <p>Subject: <span class="required">*</span></p> <p><input type="text" name="subject" size="40" placeholder="Ex: Contact"/></p> <p>Your email address: <span class="required">*</span></p> <p><input type="text" name="email" size="40" placeholder="Ex: example@xxx.com"/></p> <p>Website:</p> <p><input type="text" name="website" size="40" placeholder="Ex: http//:google.com"/></p> <p>Where you have heard us?: <span class="required">*</span></p> <p><select name="heard"> <option>Internet</option> <option>Newspapers</option> <option>Friends or relatives</option> <option>Others</option> </select></p> <p>Your message: <span class="required">*</span></p> <p><textarea cols="75" rows="20" name="message"></textarea></p> <p>Are you human? Sum this please: 5 + 7 = ?: <span class="required">*</span></p></p> <p><input type="text" name="captcha" size="10"/></p> <p><input type="submit" name="submit" value="Send" class="button"/> <input type="reset" value="Reset" class="button"/></p> </form> SECOND PROBLEM:If a user has made a mistake, he gets the error message so that he can correct! However, when a mistake in the form occurs, all the data the user has entered are disappeared! I want the data to keep appearing so that the user does not start over again to fill the form. THIRD: When the erro message is displayed to notify the user that he made a mistake when submitting the form, the message is displaying on the top of the page. I want it to appear below each respective field. How to do that? In JQuery it is simple, but in PHP, I am confusing! I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> Hi- the code below lets me upload a CSV file to my database if I have 1 field in my database and 1 column in my CSV. I need to add to my db "player_id" from the CVS file and "event_name" and "event_type" from the form... any ideas??? here's the code: Code: [Select] <?php $hoststring =""; $database = ""; $username = ""; $password = ""; $makeconnection = mysql_pconnect($hoststring, $username, $password); ?> <?php ob_start(); mysql_select_db($database, $makeconnection); $sql_get_players=" SELECT * FROM tabel ORDER BY player_id ASC"; // $get_players = mysql_query($sql_get_players, $makeconnection) or die(mysql_error()); $row_get_players = mysql_fetch_assoc($get_players); // $message = null; $allowed_extensions = array('csv'); $upload_path = '.'; //same directory if (!empty($_FILES['file'])) { if ($_FILES['file']['error'] == 0) { // check extension $file = explode(".", $_FILES['file']['name']); $extension = array_pop($file); if (in_array($extension, $allowed_extensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) { if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) { $keys = array(); $out = array(); $insert = array(); $line = 1; while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) { foreach($row as $key => $value) { if ($line === 1) { $keys[$key] = $value; } else { $out[$line][$key] = $value; } } $line++; } fclose($handle); if (!empty($keys) && !empty($out)) { $db = new PDO( 'mysql:host=host;dbname=db', 'user', 'pw'); $db->exec("SET CHARACTER SET utf8"); foreach($out as $key => $value) { $sql = "INSERT INTO `table` (`"; $sql .= implode("`player_id`", $keys); $sql .= "`) VALUES ("; $sql .= implode(", ", array_fill(0, count($keys), "?")); $sql .= ")"; $statement = $db->prepare($sql); $statement->execute($value); } $message = '<span>File has been uploaded successfully</span>'; } } } } else { $message = '<span>Only .csv file format is allowed</span>'; } } else { $message = '<span>There was a problem with your file</span>'; } } ob_flush();?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>CSV File Upload</title> </head> <body> <form class="form" action="" method="post" enctype="multipart/form-data"> <h3>Select Your File</h3> <p><?php echo $message; ?></p> <input type="file" name="file" id="file" size="30" /> <br/> <label>Event Name:</label><input name="event_name" type="text" value="" /> <br/> <label>Event Type:</label><input name="event_type" type="text" value="" /> <br/> <input type="submit" id="btn" class="button" value="Submit" /> </form> <br/> <h3>Results:</h3> <?php do { ?> <p><?php echo $row_get_players['player_id'];?></p> <?php } while ($row_get_players = mysql_fetch_assoc($get_players)); ?> </body> </html> Im having a problem with my form mail on my websites. Now the problem I have only happens with sites that I upload to my hosting accounts with Host gator. The mail will only deliver to the domain email address it wont deliver to gmail or yahoo or any other email address. I tested the script on an old domain with an Irish hosting account and it works perfectly it delivers to gmail and yahoo and my domain email account. Ive been pulling my hair out talking to Hostgator staff all weekend they keep blaming gmail and yahoo and insist the problem is not on there end. Anyway I was wondering is there anything I can add to my PHP script to make sure it delivers to gmail and yahoo or is there anything wrong with my script as hostgator are saying. Maybe there is a security issue or something Im very new to php so i could be missing something simple.
Thanks for the Help
<?php /* Set e-mail recipient */ $myemail = "info@shaneswebdesign.com"; /* Check all form inputs using check_input function */ $yourname = check_input($_POST['yourname'], "Enter your name"); $subject = check_input($_POST['subject'], "Write a subject"); $email = check_input($_POST['email']); $website = check_input($_POST['website']); $likeit = check_input($_POST['likeit']); $how_find = check_input($_POST['how']); $comments = check_input($_POST['comments'], "Write your comments"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* If URL is not valid set $website to empty */ if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website)) { $website = ''; } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $yourname E-mail: $email URL: $website Area of Interest? $how_find Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: http://www.shanesweb...m/thanks.php'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Please correct the following error:</b><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } ?> Hi all, firstly thank you in advance to anyone who replies to this thread. I'll be honest I'm a newbie when I comes to PHP and really am a long way to mastering it. If someone could have a look at my code and tell me where I'm going wrong here then it would be a great help.
The problem here is, when I click on the submit button it sends me to the PHP script page and doesn't actually send a email to the address.
Please Help and again, thank you in advance.
Below is the HTML,
<section> Hey, I have my contact form in my website working fine I'm just asking a simple question because I don't know so much about php and php syntax I have my html file calling this code below when i'm clicking on the submit button Just take a look at the last line when there is the 'echo' script I want it to go to this link, and instead it's just writing the link what is the right command/code that should i use? <? $subject="from ".$_GET['fName']; $headers= "From: ".$_GET['fEmail']."\n"; $headers.='Content-type: text/html; charset=UTF-8' . "\r\n"; mail("mymail@example.com", $subject, " <html> <head> <title> My Title </title> </head> <body> <br> ".$_GET['fName']. " <br> ".$_GET['fPhone']." <br> ".$_GET['fEmail']." <br><br> ".$_GET['pBody']." </body> </html>" , $headers); echo "http://avrikim123.co.cc/sent.html"; ?> A while ago I purchased a website template which included a contact form, and a PHP script to process the form. I cannot find the contact form so I'm trying to figure out how to code it on my own, or find a similar one to put in it's place. The PHP file is located he http://warp.nazwa.pl/dc/innovation/php/contact/sendMessage.php The form itself is on this page: http://warp.nazwa.pl/dc/innovation/contact.html Here is the code from the JScript file. Code: [Select] // alias to jQuery library, function noConflict release control of the $ variable // to whichever library first implemented it var $j = jQuery.noConflict(); // if true the send button is blocked var g_blockSendButton = false; /*************************************** SETUP CONTACT FORM ****************************************/ function setupInputControls() { // change border color wehen controls take focus $j(".commonInput, .commonTextarea, .contactInputHuman").focus( function() { $j(this).css("border", "1px solid #3399cc"); } ); // restore border color wehen controls lost focus $j(".commonInput, .commonTextarea, .contactInputHuman").blur( function() { $j(this).css("border", "1px solid #ccc"); $j(this).css("border-right", "1px solid #eee"); $j(this).css("border-bottom", "1px solid #eee"); } ); // when input name lost focus, validate the value $j("#inputName").blur( function() { if($j(this).val() != "") { $j("#contactNameErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactNameErrorMsg").html(" Please enter your name").css("visibility", "visible"); } } ); // when input email lost focus validate the value $j("#inputEmail").blur( function() { if($j(this).val() != "") { // create regular expression object var regExp = new RegExp(/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?$/i); // check email address, if result is null the email string dont match to pattern var resultExp = regExp.exec($j(this).val()); if(resultExp == null) { $j(this).css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Sorry, but this email address is incorrect").css("visibility", "visible"); } else { $j("#contactEmailErrorMsg").css("visibility", "hidden"); } } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Please enter your email address").css("visibility", "visible"); } } ); // when input subject lost focus validate the value $j("#inputSubject").blur( function() { if($j(this).val() != "") { $j("#contactSubjectErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactSubjectErrorMsg").html(" You forgot to specify a subject").css("visibility", "visible"); } } ); // when input message lost focus validate the value $j("#inputMessage").blur( function() { if($j(this).val() != "") { $j("#contactMessageErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactMessageErrorMsg").html(" Please enter your message").css("visibility", "visible"); } } ); // when input human lost focus validate the value $j("#inputHuman").blur( function() { if(parseInt($j(this).val(), 10) == 4) { $j("#contactHumanErrorMsg").css("visibility", "hidden"); } else { $j(this).css("border", "1px solid #FF0000"); $j("#contactHumanErrorMsg").html(" You really don't know?").css("visibility", "visible"); } } ); } // end of function setupInputControl function setupSendButton() { $j("#contactSendButton").click( function() { // prevent multiple send call by user if(true == g_blockSendButton) { return; } g_blockSendButton = true; // get all data from contact form and save it in local variables var inputName = $j("#inputName").val(); var inputEmail = $j("#inputEmail").val(); var inputSubject = $j("#inputSubject").val(); var inputMessage = $j("#inputMessage").val(); var inputHuman = $j("#inputHuman").val(); // create regular expression object var regExp = new RegExp(/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9]([-a-z0-9_]?[a-z0-9])*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z]{2})|([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3})(:[0-9]{1,5})?$/i); // check email address, if result is null the email string dont match to pattern var resultExp = regExp.exec(inputEmail); // check user answer, resultHuman = true if ok, false if answer is bad var resultHuman = parseInt(inputHuman, 10) == 4; // check the error by logical sum var error = (resultHuman != true) || (resultExp == null) || (inputName == "") || (inputEmail == "") || (inputSubject == "") || (inputMessage == ""); // if there was an error we must display some informotion and mark // input cotrol with wrong data if(error) { $j("#contactNameErrorMsg").css("visibility", "hidden"); $j("#contactEmailErrorMsg").css("visibility", "hidden"); $j("#contactSubjectErrorMsg").css("visibility", "hidden"); $j("#contactMessageErrorMsg").css("visibility", "hidden"); $j("#contactHumanErrorMsg").css("visibility", "hidden"); $j("#contactErrorPanel").slideUp(300); // errors processing if(inputName == "") { $j("#inputName").css("border", "1px solid #FF0000"); $j("#contactNameErrorMsg").html(" Please enter your name").css("visibility", "visible"); } if(inputEmail == "") { $j("#inputEmail").css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Please enter your email adress").css("visibility", "visible"); } else if(resultExp == null) { $j("#inputEmail").css("border", "1px solid #FF0000"); $j("#contactEmailErrorMsg").html(" Sorry, but this email address is incorrect").css("visibility", "visible"); } if(inputSubject == "") { $j("#inputSubject").css("border", "1px solid #FF0000"); $j("#contactSubjectErrorMsg").html(" You forgot to specify a subject").css("visibility", "visible"); } if(inputMessage == "") { $j("#inputMessage").css("border", "1px solid #FF0000"); $j("#contactMessageErrorMsg").html(" Please enter your message").css("visibility", "visible"); } if(resultHuman != true) { $j("#inputHuman").css("border", "1px solid #FF0000"); $j("#contactHumanErrorMsg").html(" You really don't know?").css("visibility", "visible"); } // unblock send button g_blockSendButton = false; } else // if no error, if all data is set correctly { // let's define function called after ajax successfull call function phpCallback(data) { // if success if(data == "ok") { $j("#contactErrorPanel").text(""); $j("#contactErrorPanel").css("background-color", "#ccFFcc"); $j("#contactErrorPanel").append("Your email was sent."); $j("#contactErrorPanel").css("border", "1px solid #339933"); $j("#contactErrorPanel").slideDown(300, function(){ g_blockSendButton = false;}); $j("#inputName").val(""); $j("#inputEmail").val(""); $j("#inputSubject").val(""); $j("#inputMessage").val(""); $j("#inputHuman").val(""); } else // if error/problem during email sending in php script { $j("#contactErrorPanel").text(""); $j("#contactErrorPanel").css("background-color", "#FFcccc"); $j("#contactErrorPanel").css("border", "1px solid #993333"); $j("#contactErrorPanel").append("There was an error sending your email."); $j("#contactErrorPanel").slideDown(300, function(){ g_blockSendButton = false;}); } } // end of function phpCallback // all data is correct so we can hide error/success panel $j("#contactErrorPanel").slideUp(300); // build data string for post call var data = "inputName="+inputName; data += "&"+"inputEmail="+inputEmail; data += "&"+"inputSubject="+inputSubject; data += "&"+"inputMessage="+inputMessage; // try to send email via php script executed by server $j.post("php/contact/sendMessage.php", data, phpCallback, "text"); // unblock send button } // end else all dara } ); } // end of function setupSendButton /*************************************** MAIN CODE - CALL THEN PAGE LOADED ****************************************/ // binding action to event onload page $j(document).ready( function() { // common.js setupGlobal(); setupCommunityButtons(); setupToolTipText(); setupSearchBox(); setupCufonFontReplacement(); setupSideBarMiniSlider(); setupMultiImageLightBox(); setupSidebarTabsPanel(); setupLoadingAsynchronousImages(); setupToolTipImagePreview(); setupTextLabelImagePreview(); // this file setupInputControls(); setupSendButton(); } ); Can anyone help me figure out how to do this by any chance? Hello All, I've successfully figure out how to make a form that connects to My Database, INSERTS the END USERS INFO into my database, and THEN sends a email notification back to the ME that contains the the END USERS INFO. Is there a line of CODE in PHP to use that I can ALSO send the END USERS INFO from the form THEY FILLED OUT with all their details that was sent back to ME in the initial e-mail? Also how do I get the date and time to post in the in my e-mail received with from the END USERS containing the date and time of the form filled out. It shows up in my Database HOWEVER, not in my RECEIVED e-mail. Here is my code below: <pre> Code: [Select] <?php if (isset($_POST['submitted'])) { include('connect2myDB.php'); $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; $sqlinsert = "INSERT INTO travelers (salutation, first_name, last_name, email, zip_code, newsletter, registation_date) VALUES ('$salutation', '$first_name','$last_name','$email','$zip_code','$newsletter', NOW()))"; } ?> <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'mrjap1jobs@gmail.com'; // GATHERING the FORM DATA VARIABLES $salutation = $_POST['salutation']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $newsletter = $_POST['newsletter']; $registation_date = $_POST['registation_date']; // THIS DATA DOES NOT SHOW UP IN MY RECEIVED E-MAIL HOWEVER, IT DOES SHOW UP IN MY DATABASE.... HOW DO I FIX THIS? $body = <<<EOD <br /><hr><br /> <strong>Salutation:</strong> $salutation <br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Zip Code:</strong> $zip_code <br /> <strong>Newsletter:</strong> $newsletter <br /> <strong>Registration Date:</strong> $registation_date <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> </pre> thanks mrjap1 MOD EDIT: code tags added. Hello,
I need a contact form with fields:
Name:
Email:
Phone:
Message:
I have html contact form but when a visitor clicks on submit button then a pop up says thnq for contacting us and he need to be on the same page. the details has to get in mail to me.
hello All, Thank you EVERYONE for all of your help... it was much appreciated. I have created a form that does the following: (1) Connects to the database that created. (2) Inserts the users data into the database (3) Displays a thank you you page after a successful form submission (4) Send an e-mail to me with all the users details I NOW need to be able to send a Custom html page to the end users e-mail with all their data... a Confirmation e-mail for their reference. Is there some special PHP Code that can HANDLE such a task? If so please tell me how might be able to integrate this in my existing code. thanks mrjap1 Hello All, I need some VERY DETAILED direction from anyone who can tell me how to complete this task. I set up my database "riptide" in Php MyAdmin for the following data to be submitted by user. Also a " form.php " form with the following fields. Salutation: Mr. Mrs. Ms. Miss. Dr. Prof. (radio buttons) input name="salutation" type="radio" value="Mr." checked First Name: (text input field) input name="first_Name" Last Name: (text input field) input name="last_Name" E-mail: (text input field) input name="email" Zip Code: (text input field) input name="zip_code" Would you like to receive our email newsletter? Yes No (radio buttons) input type="radio" name="newsletter" value="yes" id="newsletter_0" checked Okay here is my dilemma... I need to make web form that will do the following: (1) Connects to my database (2) INSERTS the form data filled out from my user into my MySQL database. (3) I need an email that will be sent to both me and the user who filled out the web form (4) A Thank you page "displaying" all the details the user filled out in the web form. (5) Plus all fields are required and need " validation " especially the e-mail address. I made a page called "process_form. php" that will handle all of this once the submit button is clicked. How do I make this happen? Thanks in advance James sir i need this contact form php code to make it work,
i make thi deign for my website but dont know what have to put in send.php
here i the code
<h4>Send a Message</h4> <div class="contact-form" method="post" action="send.php"> <form role="form"> <div class="form-group"> <label for="name">Name</label> <input type="text" name="name" placeholder="" id="name" class="form-control"> </div> <div class="form-group"> <label for="email">Email</label> <input type="text" name="email" placeholder="" id="email" class="form-control"> </div> <div class="form-group"> <label for="phone">Skype</label> <input type="text"name="subject" id="phone" class="form-control"> </div> <div class="form-group"> <label for="phone">Message</label> <textarea placeholder="" name="message" rows="5" class="form-control"></textarea> </div> <button class="btn btn-danger" type="submit">Submit</button> </form> Edited by soumikr, 22 December 2014 - 11:35 AM. HELLO EVERYONE I HAVE A HTML FORM ON A HTML PAGE FOR USE AS A FEEDBACK FORM. I WANT TO WRITE THE USER-ENTERED DETAILS INTO A MYSQL DATABASE I AM USING A WEB HOSING SERVICE WHO HAVE TOLD ME THAT TO CONNECT TO THE DATABASE I NEED TO USE PDO (PHP DATABASE OBJECT). HERE IS MY PRESENT PHP CODING TO DO THIS TASK AS OF DATE: <?php if(isset($_POST['email'])) { function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['firstname']) || !isset($_POST['lastname']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['bustype']) || !isset($_POST['description'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $firstname = $_POST['firstname']; // required $lastname = $_POST['lastname']; // required $email = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $bustype = $_POST['bustype']; // required $description = $_POST['description']; // required $con = new PDO("mysql:host=mysql.hostinger.in;dbname=databasename",'username', 'password'); $query = "INSERT INTO `databasename` (`id`, `firstname`, `lastname`, `bustype`, `email`, `telephone`, `description`, `timestamp`,) VALUES (NULL, '$firstname', '$lastname', '$bustype', '$email', '$telephone', '$description', CURRENT_TIMESTAMP,)"; $q = $con->prepare($query); $q->execute(array(':$firstname' => $_POST['firstname'], ':$lastname' => $_POST['lastname'], ':$bustype' => $_POST['bustype'], ':$email' => $_POST['email'],':$telephone' => $_POST['telephone'], ':$description' => $_POST['description'], )); echo "<h2>Thank you for filling in our contact. We shall get back to you as soon as possible.</h2>"; $con = null; ?> Hey everyone, I have a really simple php contact form that I managed to mess up and can't for the life of me figure out what the problem is. It accepts the responses and will continue to the "success" page like it's supposed to, but it doesn't mail the data from the form fields when it does. I was hoping you'd be able to take a look and maybe find the error(s)... I know it's probably something really simple and stupid but I can't figure it out. Thanks in advance!! Code: [Select] <?php //----------------------------------------------------- //----------------------------------------------------- $address= "jm.horvatin@gmail.com"; //----------------------------------------------------- //----------------------------------------------------- $firstname = $_REQUEST["First Name: "]; $lastname = $_REQUEST["Last Name: "]; $phone = $_REQUEST["Phone Number: "]; $referred = $_REQUEST["I was referred by: "]; $address = $_REQUEST["Address: "]; $city = $_REQUEST["City: "]; $province = $_REQUEST["Province: "]; $postal = $_REQUEST["Postal Code: "]; $email = $_REQUEST["Email Address: "]; $mime_boundary = md5(time()); $headers = "From: $name <$email>\n"; $headers .= "Reply-To: $subject <$email>\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n"; $message = "--$mime_boundary\n\n"; $message .= "New Web Registration: \n\n\n"; $message .= "First Name: $firstname \n\n"; $message .= "Last Name: $lastname \n\n"; $message .= "Phone Number: $phone \n\n"; $message .= "I was referred by: $referred \n\n"; $message .= "Address: $address \n\n"; $message .= "City: $city \n\n"; $message .= "Province: $province \n\n"; $message .= "Postal Code: $postal \n\n"; $message .= "Email Address: $email \n\n"; $message .= "--$mime_boundary--\n\n"; $mail_sent = mail($address, $subject, $message, $headers); header("location:paypal.html"); ?> ?> Code: [Select] <form action="get_mail.php" method="POST" class="contactform"> <p>First Name <input name="firstname" type="text" / class="box" value="" size="35"> Last Name <input name="lastname" type="text" class="box" value="" size="40"/> <br> Phone <input name="phonenumber" type="text" value="" class="box"> I was referred by <input name="referred" type="text" class="box" value="" size="45"> <br> Address <input name="address" type="text" class="box" value="" size="35"> City <input name="city" type="text" class="box" value="" size="20"> Province <input name="province" type="text" class="box" value="" size="7"> Postal Code <input name="postal" type="text" class="box" value="" size="6"> Email Address <input name="email" type="text" class="box" value="" size="40"> <br> <br> Automatic month-to-month: This is a month-to-month program and is considered active and ongoing until cancelled as described in the Cancellation policy. CANCELLATION POLICY: ShapeIt! member must give notice of cancellation by Email to totalfitnessbc@gmail.com at least 5 business days from the above stated debit date. Even if you notify your instructor, you still are required to send and email to <a href="mailto:totalfitnessbc@gmail.com">totalfitnessbc@gmail.com</a> Save a record of this email to serve as your cancellation receipt. 30-day money back guarantee is contingent upon receiving an email of cancelation to totalfitnessbc@gmail.com within the first 30 days of signing this agreement.</p> <p><br> I certify that I have fully read and understand the terms of this Agreement and will comply with the contents herein. Prepay memberships are non-refundable after the 30 day money back guarantee period expires. <br> <br> <input type="submit" class="contactform" value="Proceed to Payment" target="_blank"> <br class="clear" /> </p> </form> Hi,
I recently bought a HTML template and it came with a contact form which work fines.
The only issue I have is that when the email arrives it only shows the persons first name, not their surname unless the name is kept as one e.g.. Adam-Smith
I can't see why this is and has been bugging me for the past couple of days!
Any ideas?
$email_to = "contact@website"; $name = $_POST["user-name"]; $email = $_POST["user-email"]; $message = $_POST["user-message"]; $text = "Name: $name Email: $email Message: $message"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html; charset=utf-8" . "\r\n"; $headers .= "From: <$name>" . "\r\n"; mail($email_to, "Contact", $text, $headers); ?> Thanks |