Jump to content

Search the Community

Showing results for tags 'contact form'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 3 results

  1. I'm getting the following error on a contact form I'm trying to implement: Fatal error: Uncaught Error: Undefined constant "secretcode" in /home/foxclo98/test.foxclone.com/contact.php:33 Stack trace: #0 {main} thrown in /home/foxclo98/test.foxclone.com/contact.php on line 33 Here's the full code of the contact form: <?php $errorlevel=error_reporting(); error_reporting($errorlevel & ~E_WARNING); //...code that generates notices error_reporting($errorlevel); // initialization session_start(); $email_contact = "help@foxclone.com"; $email_website = "webmaster@foxclone.com"; // definition of permitted types/subject/category. use to dynamically build the option list, // pre-selecting any existing choice, and used in the validation logic $permitted_types = ['Questions', 'Report Problem', 'Suggestion', 'Other', 'Website Problem']; $secretcode = ['nospam']; $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/validation errors // post method form processing if($_SERVER['REQUEST_METHOD'] == 'POST') { // trim all the data at once $post = array_map('trim',$_POST); // if any of the fields are arrays, use a recursive call-back function here instead of php's trim function // inputs: name, email, type/subject/category, message - all required // validate the inputs $errors = []; //Other validation stuff. if ($post['secretcode'] != 'nospam') { $errors[secretcode] = 'You did not enter the correct secret code.'; } if($post['name'] === '') { $errors['name'] = 'Name is required.'; } if($post['email'] === '') { $errors['email'] = 'Email is required.'; } else { // while it is true that the following email format validation will produce an error // for an empty value, you should specifically tell the visitor what is wrong with what // they submitted if (false === filter_var($post['email'], FILTER_VALIDATE_EMAIL)) { $errors['email'] = 'The Email Address you entered does not appear to be valid.'; } } if($post['type'] === '') { $errors['type'] = 'You must select a Type/Subject/Category.'; } else { // you will only see the following error due to a programming mistake or someone/something submitting their own values if(!in_array($post['type'],$permitted_types)) { $errors['type'] = 'The selected Type is invalid.'; // you would want to log the occurrence of this here... } } if($post['message'] === '') { $errors['message'] = 'Message is required.'; } else { if(strlen($post['message']) < 10) { $errors['message'] = 'The Message must be at least 10 characters.'; } } // if no errors, use the submitted data if(empty($errors)) { // apply htmlentities() to help prevent cross site scripting when viewing the received email in a browser $formcontent = htmlentities("From: {$post['name']}\r\nEmail: {$post['email']}\r\nSubject: {$post['type']}\r\nMessage: {$post['message']}", ENT_QUOTES); if ($post['type'] === "Website Problem") { $recipient=$email_website; } else { $recipient=$email_contact; } $email = $post['email']; // add $post['email'] as a Reply-to: header if desired, it is one, valid email address at this point $mailheader = "From: $email\r\n" ; $mailheader .= "Cc: $email\r\n"; if(!mail($recipient, $post['type'], $formcontent, $mailheader)) { // an error // setup the user error message $errors['mail'] = 'The email could not be sent, the site owner has been notified.'; // system error handling goes here... - datatime, get the last error message, include the mail parameter values... // at this point, all parameters are either an internal value, have been validated they they are just an expected // value/format, or have had htmlentities() applied. } // if no errors at this point, success if(empty($errors)) { $_SESSION['success_message'] = "Mail Sent. Thank you {$post['name']}, we will contact you shortly.."; die(header("Refresh:0")); } } } // html document starts here... ?> <?php // display any success message if(!empty($_SESSION['success_message'])) { // for demo purposes, just output it as a paragraph. add any markup/styling you want echo '<p>'; echo htmlentities($_SESSION['success_message'], ENT_QUOTES); echo " - <a href='index.php#home' style='color:#ff0099;'> Return Home</a>"; echo '</p>'; unset($_SESSION['success_message']); } ?> <?php // display any errors if(!empty($errors)) { // for demo purposes, just output them as a paragraph. add any markup/styling you want echo '<p>'; echo implode('<br>',$errors); echo '</p>'; } ?> <?php // (re)display the form here..., re-populating the fields with any existing values ?> <?php require_once("header.php");?> <style> input, select { width: 20rem; line-height:30px; border:2px solid #2f496e; padding: 0; margin: 0; height: 30px; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; font: 500 1rem sans-serif; background: #fff; } .input { text-indent: 3px; } </style> </head> <body> <?PHP require_once("navbar.php"); ?> <!--****************** * CONTACT * *******************--> <div class="head__h1"> Need help? Have a suggestion? Why not send us an email?</div> <div class="subtext"> You'll receive a copy of your inquiry for your records </div> <div class ="download"> <div class="cont__row" style="background-color: #d9b44a;"> <div class="cont__column"> <form method="POST"> <label>Secret Code:</label><br> <input type="text" name="secretcode" id="secretcode" placeholder="Type nospam here"> <br> <br> <label>Name</label><br> <input type="text" name="name"><br> <br> <label>Email</label><br> <input type="email" name="email"><br> <br> <label>Select a Category</label> <br> <select name="type" id="category" size="1"> <option value=''> </option> <option value='Questions'>Questions</option> <option value="Report Problem">Report Problem</option> <option value='Suggestion'>Suggestion</option> <option value='Other'>Other</option> <option value="Website Problem"> Website Problem</option> </select> </div> <div class="cont__column"> <label>Message</label><br> <textarea name="message" rows="10" cols="50" style="font: 500 1rem sans-serif"></textarea><br> <br> <div class="button"> <input type="image" id="myimage" src="images/email1.jpg" style="height:40px; width:160px;"/> </form> </div> </div> </div> </div> <?PHP require_once("footer.php"); ?> I'd appreciate ssome help on this.
  2. Hello all, It's my first time here, I hope you will be indulgent. I am trying to create a contact form in php, using something that a former employee at my company has written for another website. Please note that I have no knowledge whatsoever of php (except what I've learned while creating it...). Here is the code I am working with. Can you go through and let me know if see anything that seems off to you? Thank you very much! <?php /* ******************************************************************************************** CONFIGURATION ******************************************************************************************** */ // destinataire est votre adresse mail. Pour envoyer à plusieurs à la fois, séparez-les par une virgule $destinataire = 'myemail'; // copie ? (envoie une copie au visiteur) $copie = 'oui'; // Action du formulaire (si votre page a des paramètres dans l'URL) // si cette page est index.php?page=contact alors mettez index.php?page=contact // sinon, laissez vide $form_action = ''; // Messages de confirmation du mail $message_envoye = "Votre message nous est bien parvenu. Merci !"; $message_non_envoye = "L'envoi du mail a échoué, veuillez réessayer SVP."; // Message d'erreur du formulaire $message_formulaire_invalide = "Vérifiez que tous les champs soient bien remplis et qu'il n'y ait pas d'erreur dans votre adresse courriel."; /* ******************************************************************************************** FIN DE LA CONFIGURATION ******************************************************************************************** */ /* * cette fonction sert à nettoyer et enregistrer un texte */ function Rec($text) { $text = htmlspecialchars(trim($text), ENT_QUOTES); if (1 === get_magic_quotes_gpc()) { $text = stripslashes($text); } $text = nl2br($text); return $text; }; /* * Cette fonction sert à vérifier la syntaxe d'un email */ function IsEmail($email) { $value = preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(??:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(??:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $email); return (($value === 0) || ($value === false)) ? false : true; } // formulaire envoyé, on récupère tous les champs. $name = (isset($_POST['name'])) ? Rec($_POST['name']) : ''; $email = (isset($_POST['email'])) ? Rec($_POST['email']) : ''; $tel = (isset($_POST['tel'])) ? Rec($_POST['tel']) : ''; $sujet = (isset($_POST['sujet'])) ? Rec($_POST['sujet']) : ''; $message = (isset($_POST['message'])) ? Rec($_POST['message']) : ''; // On va vérifier les variables et l'email ... $email = (IsEmail($email)) ? $email : ''; // soit l'email est vide si erroné, soit il vaut l'email entré $err_formulaire = false; // sert pour remplir le formulaire en cas d'erreur si besoin if (isset($_POST['envoi'])) { if (($name != '') && ($tel != '')) { // les 4 variables sont remplies, on génère puis envoie le mail //$headers = 'From:'.$name.' <'.$email.'>' . "\r\n"; //$headers .= 'Reply-To: '.$email. "\r\n" ; //$headers .= 'X-Mailer:PHP/'.phpversion(); $headers = "From: " . $name . "\r\n"; $headers .= "Reply-To: ". $email . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; // envoyer une copie au visiteur ? if ($copie == 'oui') { $cible = $destinataire.';'.$email; } else { $cible = $destinataire; }; // Remplacement de certains caractères spéciaux $message = str_replace("'","'",$message); $message = str_replace("’","'",$message); $message = str_replace(""",'"',$message); $message = str_replace('<br>','',$message); $message = str_replace('<br />','',$message); $message = str_replace("<","<",$message); $message = str_replace(">",">",$message); $message = str_replace("&","&",$message); // Envoi du mail $num_emails = 0; $tmp = explode(';', $cible); foreach($tmp as $email_destinataire) { $msg = '<html><body>'; $msg .= '<h1>Vous avez reçu une soumission</h1>'; $msg .= '</body></html>'; $msg = '<html><body>'; $msg = '<h3>Formulaire : </h3>'; $msg .= "<tr><td><strong>Prénom Nom : </strong> </td><td>" . $name . "</td></tr>"; $msg .= "<tr><td><strong>Courriel : </strong> </td><td>" . $email . "</td></tr>"; $msg .= "<tr><td><strong>Téléphone : </strong> </td><td>" . $tel . "</td></tr>"; $msg .= "<tr><td><strong>Sujet : </strong> </td><td>" . $sujet . "</td></tr>"; $msg .= "<tr><td><strong>Message :</strong> </td><td>" . $message . "</td></tr>"; } $msg .= "</table>"; $msg .= "</body></html>"; //$msg = $name.'</br>'.$email.'</br>'.$tel.'</br>'.$sujet.'</br>'.$message; if (mail($email_destinataire, $name, $msg, $headers)) $num_emails++; } } ?>
  3. Hi, I've been using the same contact form for over a year for several websites. I've successfully been able to tweak it to suit my needs for each project. However, I am currently trying to use it again, and the form appears to submit, but the email never shows up. I've tried it with two different emails. I tested the form on a previous site I designed, and it no longer works either. I can't test all the others because I no longer can access those clients' emails, but they are on the same server. I'm more of a designer than programmer & know enough PHP to be "dangerous", aka tweak existing code to make it do what I need. I used a verifier & it told me my php was fine & dandy. I'm not sure where the error lies... Thanks for any insight! This is my form in the HTML page: <form name="contactformlite" method="post" action="lite_process.php" onSubmit="return validate.check(this)" target="_self"> <table class="cflite"> <tr><td><h3>FREE Gas Card Entry Form</h3></td></tr> <tr> <td class="cflite_td"> <label for="Full_Name" class="required"> Full Name<span class="required_star"> * </span></label> <input type="text" name="Full_Name" id="Full_Name" maxlength="100" style="width:72%; display:block; margin-right:0px; float:right;"> </td> </tr> <tr> <td valign="top" class="cflite_td"> <label for="Email_Address" class="not-required">Email Address<span class="required_star"> * </span></label> <input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:72%; display:block; margin-right:0px; float:right;"> </td> </tr> <tr> <td valign="top" class="cflite_td"> <label for="Telephone_Number" class="required">Phone Number<span class="required_star"> * </span></label> <input type="text" name="Telephone_Number" id="Telephone_Number" maxlength="100" style="width:72%; display:block; margin-right:0px; float:right;"> </td> </tr> <tr> <td valign="top" class="cflite_checkbox"> <input type="checkbox" name="Prop_Mgr" id="Prop_Mgr" value="y"> <input type="hidden" name="Prop_Mgr" value="n" /> <label for="Prop_Mgr" class="not_required" style="margin:0px;">I am a retail property manager.</label> <br> <input type="checkbox" name="Contact_Request" id="Contact_Request" value="y"> <input type="hidden" name="Contact_Request" value="n" /> <label for="Contact_Request" class="not_required" style="margin:0px;">I would like more information on TWS' services.</label> <br> <input type="checkbox" name="Permission" id="Permission" value="y"> <input type="hidden" name="Contact_Request" value="n" /> <label for="Permission" class="required" style="margin:0px;"><span class="required_star"> * </span>I am a new facebook fan of TWS as of 2/25/14. I understand that this entry also signs me up for the monthly email newsletter, which I can unsubscribe from at any time. I agree to be contacted by TWS with the phone number or email address provided here.</label> </td> </tr> <tr> <td class="allfields"><span class="required_star"> * </span>Required for Entry.</td></tr> <tr> <td class="cflite_bottom"> <input type="submit" value="Enter Me Now!" id=submit></td> </tr> </table> </form> This is my first php file: <?php if(isset($_POST['Email_Address'])) { include 'lite_settings.php'; if($email_to == "youremailaddress@yourdomain.com") { die("This message is for the Webmaster. Please enter your email address into the file 'lite_settings.php'"); } function died($error) { echo "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 close this window and fix these errors.<br /><br />"; die(); } if(!isset($_POST['Full_Name']) || !isset($_POST['Email_Address']) || !isset($_POST['Telephone_Number']) || !isset($_POST['Prop_Mgr']) || !isset($_POST['Contact_Request']) || !isset($_POST['Permission'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $full_name = $_POST['Full_Name']; // required $email_from = $_POST['Email_Address']; // required $telephone = $_POST['Telephone_Number']; // required $prop_mgr = $_POST['Prop_Mgr']; // not required $contact_request = $_POST['Contact_Request']; // required $permission = $_POST['Permission']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The email address you entered does not appear to be valid.<br />'; } if(strlen($full_name) < 2) { $error_message .= 'Your name does not appear to be valid.<br />'; } if(strlen($telephone) < 12) { $error_message .= 'Your phone number does not appear to be valid. Use format 000-000-0000<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\r\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Full Name: ".clean_string($full_name)."\r\n"; $email_message .= "Email: ".clean_string($email_from)."\r\n"; $email_message .= "Telephone: ".clean_string($telephone)."\r\n"; $email_message .= "Prop_Mgr: ".clean_string($prop_mgr)."\r\n"; $email_message .= "Contact_Request: ".clean_string($contact_request)."\r\n"; $email_message .= "Permission: ".clean_string($permission)."\r\n"; $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); header("Location: $thankyou"); ?> <script>location.replace('<?php echo $thankyou;?>')</script> <? } ?> And the second "settings" file (I put in a fake email & site here, for privacy purposes): <?php $email_to = "fakename@email.com"; // your email address $email_subject = "Facebook Gas Contest Entry"; // email subject line $thankyou = "http://fakesite.com"; // thank you page ?> Lastly, here is my javascript: function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;} return true;} function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;} return true;} function $$(id){if(!has_id(id)&&!has_name(id)){alert("Field "+id+" does not exist!\n Form validation configuration error.");return false;} if(has_id(id)){return document.getElementById(id).value;}else{return;}} function $val(id){return document.getElementById(id);} function trim(id){$val(id).value=$val(id).value.replace(/^\s+/,'').replace(/\s+$/,'');} var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\n\n';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i<required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' is invalid\n';if(has_id(required.field[i][0])&&to_focus.length===0){to_focus=required.field[i][0];} tmp=false;}} if(!tmp){alert(error_message);} if(to_focus.length>0){document.getElementById(to_focus).focus();} return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length<1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;if($$(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length>0){return s.replace(/^\s+/,'').replace(/\s+$/,'');}else{return s;}}};
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.