PHP - Getting A Simple Contact Form Past Spam Filter?
Hi,
I am having issues getting a simple contact form getting past the junk filter and into the inbox. Is there something wrong with my code? I have tried to set the email to 'not junk' in the 2 different email providers, but not change. Here is my code: Code: [Select] <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: Contact Form'; $to = 'my_email@gmail.com'; $subject = 'Hello'; $human = $_POST['human']; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; $headers .= "Content-type: text/plain; charset=utf-8\n"; $headers .= "From: website user<someone_from@mysite.com> \n"; if ($_POST['submit']) { if ($name != '' && $email != '') { if ($human == '10') { if (mail ($to, $subject, $body, $from)) { echo '<p>Your message has been sent!</p>'; } else { echo '<p>Something went wrong, go back and try again!</p>'; } } else if ($_POST['submit'] && $human != '4') { echo '<p>You answered the anti-spam question incorrectly!</p>'; } } else { echo '<p>You need to fill in all required fields!!</p>'; } } ?> Code: [Select] <form method="post" action="mail_.php"> <label>Name</label> <input name="name" placeholder="Type Here"> <label>Email</label> <input name="email" type="email" placeholder="Type Here"> <label>Message</label> <textarea name="message" placeholder="Type Here"></textarea> <label>*What is 7+3? (Anti-spam)</label> <input name="human" placeholder="Type Here"> <input id="submit" name="submit" type="submit" value="Submit"> </form> Any help is greatly appreciated. Similar TutorialsHello there! I made a contact-form with PHP but the e-mails go directly into the spam folder. Then I ran a test on http://www.mail-tester.com and I got some errors. As you can tell, I am new to PHP and I don't know what to do. I appreciate any help! Errors: 1. HTML_MIME_NO_HTML_TAG HTML-only message, but there is no HTML tag 2. MIME_HTML_ONLY Message only has text/html MIME parts 3. MISSING_DATE Missing Date: header 4. "Your message is not signed by DKIM" 5. "There is no SPF record. Please add (number).easyname.com to your DNS zone file."
Here is my PHP: <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: mywebsite.com'; $to = 'someone@something.net'; $subject = 'Subject-line'; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html\r\n"; $headers .= 'From: '. $email. "\r\n" . $headers .= "Reply-To: ". $email. "\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(); $message = nl2br($message); $status = mail($to, $subject, $message, $headers); if($status) { echo '<p>Your Message has been send!</p>'; } else { echo '<p>Something went wrong. Please try again.</p>'; } ?> Here is my HTML: <div class="contact-form"> <form id="contact-form" method="post" action="contact-form-handler.php"> <input name="name" type="text" class="form-control" placeholder="Your Name" required> <br> <input name="email" type="email" class="form-control" placeholder="Your Email"> <br> <textarea name="message" class="form-control" placeholder="Message" rows="40" required></textarea><br> <input type="submit" class="form-control" value="SEND MESSAGE"> </form> </div>
I tried many things but nothing really worked. Also, I am a noob at PHP so I am kind of lost. Thanks for your help! Ok, so I want to make a comment spam filter for my site. I know the basic logic, but have yet to figure out how to write the functions. I have a database table called comments that has a column called "time", which contains a unix timestamp value of when it was posted. Basically what I want to do is this: When a user tries to post a comment, the script determines with a database query if they have posted a comment in the last 120 seconds. So basically I have to find the current time, and the time it was 120 seconds before the current time. Then I have to find any comments posted by the user that were made after the 120 second mark. My database query should then look something like this, right? Code: [Select] $query = mysql_query("SELECT * FROM comments WHERE author = ".$_SESSION['id']." AND time > '".$120secondsago"'"); Please correct me if my logic is wrong, which it very well may be, but how would I find the unix timestamp code from 120 seconds before the current time? Note that 120 seconds is just an example and also that I have not worked with dates in mysql very often. $query = mysql_query("SELECT * FROM comments WHERE author = ".$_SESSION['id']." AND time This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=320638.0 Hello, I have just finished very simple contact form at http://stjohnsclaims.co.uk/test5/index-6.html and I am strugling to redirect the page to index.html, or any other URL when buttom "submit" is pressed. html file always reads contact.php file and then echo ("Your claim form was successfully sent!"); on blank background. How can I redirect it? I know this is very trivial question, but I have alrready spend many hours trying to fix it with no result. Thank you html body.... <div class="indent1"> <h2>Claim Form</h2> <form action="contact.php" method="get" id="form"><div class="container"> <div class="col-5"><h4>Your Details:</h4> <div class="h"><input name="name" type="text" class="input1" />Name:</div> <div class="h"><input name="surname"type="text" class="input1" />Surname:</div> <div class="h"><input name="tel"type="text" class="input1" />Tel:</div> <div class="h"><input name="email"type="text" class="input1" />Email Adress:</div> <div class="h"><input name="address"type="text" class="input1" />Address:</div> <div class="h"><input name="city"type="text" class="input1" />City:</div> <div class="h"><input name="postcode"type="text" class="input1" />Postcode:</div><p> <h4>Accident Details</h4> <div class="h"><input name="date"type="text" class="input1" />Date of Accident:</div> <div class="h"><input name="type"type="text" class="input1" />Accident Type:</div> </div> <div class="col-6">Accident details/Injuries sustained:</div> <div class="col-7"> <textarea name="message" class="textarea" rows="40" cols="30"></textarea> <div class="container1"> <div class="fright"> <a href="#" onclick="document.getElementById('form').reset()" class="link-1"><em><b>Clear</b></em></a> <div class="indent-2"> <a href="#" onclick="document.getElementById('form').submit()" class="link-1"><em><b>Submit</b></em></a></div> </div> </div> </div> </div></form> --------------------------------------------------------------- contact.php on the server <? $subject="from ".$_GET['name']; $headers= "From: ".$_GET['email']."\n"; $headers.='Content-type: text/html; charset=iso-8859-1'; mail("kc@kamil-cizek.com", $subject, " <html> <head> <title>Contact letter</title> </head> <body> <br> " . "name: " .$_GET['name']. "<br>" . "email: " .$_GET['surname']. "<br>" . "fax: " .$_GET['tel']. "<br>" . "age: " .$_GET['email']. "<br>" . "gender: " .$_GET['address']. "<br>" . "name: " .$_GET['city']. "<br>" . "email: " .$_GET['postcode']. "<p>" . "fax: " .$_GET['date']. "<br>" . "age: " .$_GET['type']. "<p>" . "message: <p>" .$_GET['message']." </body> </html>" , $headers); echo ("Your claim form was successfully sent!"); ?> Hello, I am trying to use this contact form that emails out. however it wants to be placed beside the file that uses it. However i would need a bunch of these files than for what i am trying to do. I want it to be set up like this. website root | | scripts | scriptfile right now its like this website root | | about | | contact | | script file here is the from data in my webpage <form action="FormToEmail.php" method="post"> <table border="0" style="background:#ececec" cellspacing="5"> <tr align="left"><td>Name</td><td><input type="text" size="30" name="name"></td></tr> <tr align="left"><td>Email address</td><td><input type="text" size="30" name="email"></td></tr> <tr align="left"><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr> <tr align="left"><td> </td><td><input type="submit" value="Send"></td></tr> </table> </form> here is the script data <?php error_reporting(E_ALL ^ E_NOTICE); $my_email = "test@test.com.com"; $from_email = ""; /* Optional. Enter the continue link to offer the user after the form is sent. If you do not change this, your visitor will be given a continue link to your homepage. If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm" */ $continue = "/"; /* Step 3: Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace. IMPORTANT - The file name is case sensitive! You must save it exactly as it is named above! THAT'S IT, FINISHED! You do not need to make any changes below this line. */ $errors = array(); // Remove $_COOKIE elements from $_REQUEST. if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} // Validate email field. if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { $_REQUEST['email'] = trim($_REQUEST['email']); if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ") || stristr($_REQUEST['email'],"\\") || stristr($_REQUEST['email'],":")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} } // Check referrer is from same site. if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} // Check for a blank form. function recursive_array_check_blank($element_value) { global $set; if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} } } recursive_array_check_blank($_REQUEST); if(!$set){$errors[] = "You cannot send a blank form";} unset($set); // Display any errors and exit if errors exist. if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} // Build message. function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");} $message = build_message($_REQUEST); $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL.""; $message = stripslashes($message); $subject = "Doctor Dave Question"; $subject = stripslashes($subject); if($from_email) { $headers = "From: " . $from_email; $headers .= PHP_EOL; $headers .= "Reply-To: " . $_REQUEST['email']; } else { $from_name = ""; if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);} $headers = "From: {$from_name} <{$_REQUEST['email']}>"; } mail($my_email,$subject,$message,$headers); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form To Email PHP script from FormToEmail.com</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#ffffff" text="#000000"> <div> <center> <b>Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?></b> <br>Your message has been sent <p><a href="<?php print $continue; ?>">Click here to continue</a></p> </center> </div> </body> </html> thank you. on a side note the text box wher ei entered this in is anoyying. it jumps and bounces every letter i type. Hi, Today I have taken my first step towards familiarisation with php. I have created a simple form form a tutorial I read. The mail.php file is this: Code: [Select] <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $dropdown = $_POST['dropdown']; $formcontent=" From: $firstname \n Surname: $lastname \n Email: $email \n Dropdown: $dropdown"; $recipient = "fathernugen@googlemail.com"; $subject = "Newsletter Sign Up"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "You have been added to our newsletter subscription list!" . " -" . "<a href='newsletter.php' style='margin:0 auto; top: 100px; text-decoration:none;color:#ff0099;'> Return to Sitting Spiritually</a>"; ?> My problem is that users are redirected to a blank page with 'thank you return to sitting spiritually'. I would like to use a custom thank you page with a url like; www.sittingspiritually.co.uk/thankyou.php so the look of the site is not completely ruined by my php inadequacies. Is there a small piece of code i can add to the mail.php file so i can use a custom page for the success??? I hope some one can help, thanks in advance. so, I've been trying to build a contact form for about a week now. straight. no kidding. I'm entirely new to php and basically know nothing more than i can assume based on other scripting/coding experience. I know there's probably answers to similar questions all over the place, but I've been trying literally hundreds of different pre-built forms guaranteed to work and solutions to others' problems, etc etc and not a single one has operated correctly for me. I can't really do anything with a "you should try this/that approach" answer, nor can I be assumed to know anything about php; I pretty much just need someone to fix whatever the problem is and paste it back to me as this is the only thing keeping me from launching the site. this is what prints when trying to submit with the dropdown on the default value: Quote Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\5810110\html\contact\contact.php on line 32 There was an err0r processing your request. Please notify god@neurot1k.com & include details of what you did [wrong]. this prints when any item other than the default is selected in the dropdown: Quote Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\5810110\html\contact\contact.php on line 32 Warning: mail() [function.mail]: SMTP server response: 554 The message was rejected because it contains prohibited virus or spam content in D:\Hosting\5810110\html\contact\contact.php on line 33 There was an err0r processing your request. Please notify god@neurot1k.com & include details of what you did [wrong]. http://email.about.com/cs/standards/a/smtp_error_code_2.htm specifically states to ignore both these errors, yet http://cr.yp.to/docs/smtplf.html specifically states that it's a fault of mine. here's the html: Code: [Select] <div id="formHolder"> <form method="post" action="contact.php"> <table class="contactTable" align="center"> <tr> <td> Subject: </td> <td> <select name="sendto"> <option value="bs from N1K.com">General Inquiry</option> <option value="JOB OFFER">Design Contract</option> <option value="PURCHASE ORDER">Purchase Order/Offer</option> </select> </td> </tr> <tr> <td><font color=red>*</font>Name:</td> <td><input size=25 name="Name"></td> </tr> <tr> <td><font color=red>*</font>Email:</td> <td><input size=25 name="Email"></td> </tr> <tr> <td>Company:</td> <td><input size=25 name="Company"></td> </tr> <tr> <td>Phone:</td> <td><input size=25 name="Phone"></td> </tr> <tr> <td>Subscribe to<br> mailing list: </td> <td><input type="radio" name="list" value="No"> Pf, nothx.<br> <input type="radio" name="list" value="Yes" checked> H3X Y34!<br> </td> </tr> <tr> <td colspan=2>Message:</td> </tr> <tr> <td colspan=2 align=center> <textarea name="Message" rows=5 cols=35></textarea> </td> </tr> <tr> <td colspan=2 align=center> <input type=submit name="send" value="Submit"> </td> </tr> </table> </form> </div><!-- END formHolder --> and here's the php: <?php $to = "god@neurot1k.com" ; $from = $_REQUEST['Email'] ; $name = $_REQUEST['Name'] ; $headers = "From: $from"; $subject = $_REQUEST['sendto'] ; $fields = array(); $fields{"Name"} = "Name"; $fields{"Company"} = "Company"; $fields{"Email"} = "Email"; $fields{"Phone"} = "Phone"; $fields{"list"} = "Mailing List"; $fields{"Message"} = "Message"; $body = "I have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: god@neurot1k.com"; $subject2 = "autoconfirm from neurot1k.com"; $autoreply = "Thanks for the contact, I'll get back to you as soon as possible, usually within 48 hours. If you have any more questions, please try me on AIM: ycleptCrux"; if($from == '') { print "You have not entered an email, please go back and try again"; } else { if($name == '') { print "You have not entered a name, please go back and try again"; } else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2); if($send) { print "Thanks, I'll get back to you as soon as possible."; } else { print "There was an err0r processing your request. Please notify god@neurot1k.com & include details of what you did [wrong]."; } } } ?> the form was copy/pasted from http://php.about.com/od/phpapplications/ss/form_mail.htm and then respective variables were changed (email address, dropdown fields, etc). I didn't think it'd be SUCH a problem to copy/paste a pre-written block of code from About.com... HUGE thanks in advance to anyone willing to helo. I have used this same php contact form many times and never had this problem. I just checked it in online php code checker and comes up with no errors but when uploaded to the site and I got to test the form it goes to mysite.com/contact.php stuck on trailing code
\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.03" ); header( "Location: $thankyouurl" ); exit ; ?>
It has me stumped I can't work it out.
The full code is:
<? /* CHFEEDBACK.PHP Feedback Form PHP Script Ver 2.03 */ $mailto = 'contact@gmail.com' ; $subject = "Contact Form" ; $formurl = "http://www.mysite.com/contact.html" ; $errorurl = "http://www.mysite.com/error.html" ; $thankyouurl = "http://www.mysite.com/thanks.html" ; $name = $_POST['name'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); exit ; } if (empty($name) || empty($email) || empty($comments)) { header( "Location: $errorurl" ); exit ; } if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.03" ); header( "Location: $thankyouurl" ); exit ; ?>But when I look at the source code in browser I can see all of it is in red except for the last trailing bit which appears in black . Edited by bmbc, 07 June 2014 - 03:54 AM. (php is a weakness)
Here is the HTML portion for the form:
<form action="send_form_email.php" id="contacts-form" method="post"> Hi the user fill details and then the email his sent to me the only problem is that the emails keeps going to my spam, can someone help me out please I looked already php website and email format looks the same. This is the link to my form. http://www.people.eurico.co.uk/ here my form script Code: [Select] <?php // Set email variables $email_to = 'xxxxx@xxxxxxx.co.uk'; $email_subject = 'Call back form'; // Set required fields $required_fields = array('fullname','email','telephone','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'email' => 'Please enter a valid Email.', 'telephone' => 'Please telephone.', 'comment' => 'Please enter your Message to continue.' ); // Set form status $form_complete = FALSE; // configure validation array $validation = array(); // check form submittal if(!empty($_POST)) { // Sanitise POST array foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value)); // Loop into required fields and make sure they match our needs foreach($required_fields as $field) { // the field has been submitted? if(!array_key_exists($field, $_POST)) array_push($validation, $field); // check there is information in the field? if($_POST[$field] == '') array_push($validation, $field); // validate the email address supplied if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // Prepare our content string $email_content = 'peoplesmartlearning.co.uk: ' . "\n\n"; // simple email content foreach($_POST as $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok then send the email mail($email_to, $email_subject, $email_content); // Update form switch $form_complete = TRUE; } } function validate_email_address($email = FALSE) { return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE; } function remove_email_injection($field = FALSE) { return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field)); } ?> The HTML Code: [Select] <div class="call_us_form"> <p class="title">WE'LL CALL YOU BACK</p> <?php if($form_complete === FALSE): ?> <form class="contact_form" id="fm-form" method="post" action="index.php" > <fieldset> <div class="fm-req"> <label for="fm-firstname">Name</label> <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /> <?php if(in_array('fullname', $validation)): ?><script type="text/javascript">alert("Please enter a Name"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Email</label> <input type="text" id="email" class="detail" name="email" value=" <?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /> <?php if(in_array('email', $validation)): ?><script type="text/javascript">alert("Please enter a valid Email Address"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-firstname">Number</label> <input type="text" id="telephone" class="detail" name="telephone" value="<?php echo isset($_POST['telephone'])? $_POST['telephone'] : ''; ?>" /> <?php if(in_array('telephone', $validation)): ?><script type="text/javascript">alert("Please enter telephone number"); history.back();</script><?php endif; ?> </div> <div class="fm-req"> <label for="fm-lastname">Message</label> <textarea cols="40" rows="5" id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea> <?php if(in_array('comment', $validation)): ?><script type="text/javascript">alert("Please enter your message"); history.back();</script><?php endif; ?> </div> <input class="submit_button" type="submit" value="Call us" /> </fieldset> </form> <?php else: ?> <p>Thank you for your Message!</p> <p>We will get back to you as soon as we can</p> <script type="text/javascript"> setTimeout ('ourRedirect()', 5000) function ourRedirect () { location.href='index.php' } </script> <?php endif; ?> Guys: I'm implementing a form for user submission. At the end of the form, there is an image that displays some randomly generated code. The user will be required to enter the code shown on this image before he clicks the submit button. This is done to protect the form from spamming, automatic submission. After the submit button is clicked, I need to do this: if ($_POST['the code the user enters'] == the code on the image) { // proceed(); } Any idea on how to get the code displayed on the image ? Thanks.
Below is my contact from - and I have set anti spam question as I don't like captcha. How to I code the post/human bit so it is case insensitive?
<div class="one-half-column-right" id="contactform"> <form method="post" action="index.php#contactform"> <label>Name*</label> <div class="clear"></div> <input name="name" placeholder="Type Here"> <label>Email*</label> <div class="clear"></div> <input name="email" type="email" placeholder="Type Here"> <label>Message</label> <textarea name="message" placeholder="Type Here"></textarea> <label>*If today is Tuesday, what is tomorrow? <br> [lowercase answer please]<br> (Anti-spam)</label> <input name="human" placeholder="Type Here"> <input id="submit" name="submit" type="submit" value="Submit"> </form> <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: Website Form'; $to = ‘name@name.com’; $subject = 'website form enquiry'; $human = $_POST['human']; $headers .= 'From: '.$from."\r\n". 'Reply-To: '.$from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $body = "From: $name\n E-Mail: $email\n Message:\n $message"; if ($_POST['submit'] && $human == ‘wednesday’) { if (mail ($to, $subject, $body, $from)) { echo '<p style="font-family: Montserrat, Helvetica, Arial, sans-serif; font-weight: 600; text-align:center; font-size: 16px; color: #000; text-transform: uppercase; background-color: #FFD700"> Request has been sent. We will get back to within 48 hours!<br></p>'; } else { echo '<p style="font-family: Montserrat, Helvetica, Arial, sans-serif; font-weight: 600; text-align:center; font-size: 16px; color: #000; text-transform: uppercase; background-color: #FFD700"> Something went wrong, go back and try again!</p>'; } } else if ($_POST['submit'] && $human != '') { echo '<p style="font-family: Montserrat, Helvetica, Arial, sans-serif; font-weight: 600; text-align:center; font-size: 16px; color: #000; text-transform: uppercase; background-color: #FFD700"> You answered the anti-spam question incorrectly!</p>'; } ?> <!--// form //-->
I have a simple contact form I did a while ago for a small company. They emailed me saying they are getting bits of spam mail from the site occasionally and would like to get it stopped if possible. This is how my form looks: Code: [Select] <form method="post" action="mailer.php"> <div class="form_left"> <p>Name:<br> <input type="text" name="name" size="24" autofocus="true" placeholder="Type Here" required="true" /></p> </div> <div class="form_right"> <p>Email:<br> <input type="email" name="email" size="24" placeholder="Type Here" required="true" /></p> </div> <div class="form_left"> <p>Company Name:<br /> <input type="text" name="company" size="24" placeholder="Type Here" required="true" /></p> </div> <div class="form_right"> <p>Phone Number:<br /> <input type="text" name="phone" size="24" placeholder="Type Here" required="true" /></p> </div> <div class="form_left"> <p>Your Message:<br /> <textarea rows="6" name="message" cols="55" placeholder="Type Here" ></textarea></p> </div> <p class="submit"><input type="submit" value="Send Mail" name="submit" /></p> </form> Code: [Select] <?php if(isset($_POST['submit'])) { // $to = "mail@mydomain.com"; $to = "mail@mydomain.com"; $subject = "Web Enquiry"; $name = $_POST['name']; $email = $_POST['email']; $company = $_POST['company']; $phone = $_POST['phone']; $message = $_POST['message']; if (strlen(trim($message)) > 0) { $body = "From: $name \n\n Email: $email \n \n Company: $company \n\n Phone Number: $phone \n\n Message: $message"; if (mail($to, $subject, $body)) { echo "<h3>Thanks! Your email has been sent <br />We will answer your enquiry as soon as possible.</h3>"; } else { echo 'Cannot sent mail'; } } else { echo "<h3>Error! <br />Please ensure that all fields are filled out correctly in order to email us.</h3>"; } } ?> Any help or pointers as to how I could add in a little security would be appreciated. Hey, Wondering if this would work, it is based on the idea that everyone who is a real visitor will be using a browser, is that correct? Do robots use browsers too? if so, it wont work! haha. <? $browser = mb_substr($_SERVER['HTTP_USER_AGENT'], 0, 31); if (!empty($browser)){echo '<form action="send.php" method="post">';} ?> Just thought it was nice and simple, and couldnt see anywhere if it would work or not... Hello all, I used simple php email function but it send an email in junk folder or spam. Can anyone tell me why is this so? Her is the code: $host = "ssl://smtp.gmail.com"; $port = "465"; $to = " xx@gmail.com"; // note the comma $subject = " $_POST[company_website] "; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: About Wholesale Account' . "<$_POST[email]>\r\n"; $headers .= 'Cc: mail@gmail.com' . "\r\n"; $headers .= 'Bcc: cc@gmail.com' . "\r\n"; mail($to, $subject, $message, $headers); Hi, I Have a form after successful submission a mail must be send to particular recipient and thank you mail is send to the person who filled the form ,The problem is i am receiving mails in spam whats the reason for going in spam I have kept Capture code also Can please let me know what to do 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, 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. I wrote this html form: Code: [Select] <form action=filterwords.php method=post ENCTYPE="multipart/form-data" target="iFramestatus"> <input type=hidden name=action value=modified> <input type=hidden name=login value="%%login%%"> <input type=hidden name=ID value="%%ID%%"> <textarea cols=28 rows=4 name=Unused10>%%Unused10%%</textarea> <input type=submit name=submit value=" Update "> </form> Most of this form is filled out by my members area cgi script. I am trying to use filterwords.php to remove curse words from the textarea field "unused10" and then resubmit the data to my members area cgi script "pm.cgi" Here is my php script. <?php $action = $_REQUEST['action'] ; $login = $_REQUEST['login'] ; $ID = $_REQUEST['ID'] ; $text = $_REQUEST['Unused10'] ; $submit = $_REQUEST['submit'] ; function filterBadWords($str){ // words to filter $badwords=array( "[badword1]", "[badword2]"); // replace filtered words with random spaces $replacements=array( "[ ]", "[ ]", "[ ]" ); for($i=0;$i < sizeof($badwords);$i++){ srand((double)microtime()*1000000); $rand_key = (rand()%sizeof($replacements)); $str=eregi_replace($badwords[$i], $replacements[$rand_key], $str); } return $str; } $text = filterBadWords($text); ?> How do i send the modified data to pm.cgi? Did i use the filter script correctly? Thanks for the help |