Hello,
So I am a php novice. The company I work for has been getting a lot of spam via our contact form lately so I need to secure it, which I have done with adding a hidden field that if the form is autofilled it will not send. But since it is hidden if a real person uses autofill there message will not go through. I tried putting in captchas, but could never get any of them to work.
Here is the form on the contact page
<form method="post" action="mailer">
<div class="form">Name:<input class="input" type="text" name="name" /></div>
<br>
<div class="form">Organization:<input class="input" type="text" name="company" /></div>
<br>
<div class="form">E-Mail:<input class="input" type="email" name="email" /></div>
<br>
<div class="form">Phone:<input class="input" type="tel" name="phone" /></div>
<br>
<div class="form">Preference:<select class="input" size="1" name="contact_preference">
<option class="input" selected="selected">E-Mail</option>
<option class="input" >Telephone</option>
</select>
</div>
<br class="antispam">
<div class="form antispam" >Leave this blank<input class="input" type="text" name="url" /></div>
<br>
<div class="form">Subject:<input class="input" type="text" name="subject" /></div>
<br>
<div class="form">Message:<textarea class="textarea" style="resize:none;" name="message" ></textarea></div>
<br>
<div class="form"><input class="submit" type="submit" value=" SUBMIT " name="submit" /></div>
</form>
and here is the code on the mailer page
if(isset($_POST['url']) && $_POST['url'] == ''){
$youremail = 'name@company.com';
$body = "CompanyName contact form submission:
Name: $_POST[name]
Company: $_POST[company]
E-Mail: $_POST[email]
Phone Number: $_POST[phone]
Contact Preference: $_POST[contact_preference]
Subject: $_POST[subject]
Message: $_POST[message]";
if( $_POST['email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
$headers = "From: $_POST[email]";
} else {
$headers = "From: $youremail";
}
mail($youremail, $subject, $body, $headers);
echo "The form you entered has been submitted. Thank you, " . $_POST[name] .", for your interest in <CompanyName>. ";
echo "Contact <a href=\"mailto:name@company.com\"><name></a> if you would like further assistance.";
}else {
echo "There was an error sending the data.<br /> ";
echo "Please contact <name> at <a href=\"mailto:name@company.com\">name@company.com</a> with your information.";
}
This form does what it is supposed to for the most part, but anything can be in the fields or they can be left blank. Also, the subject will not populate the email subject field.
Here is what I need help with in a convinient list
1) Get subject from form to populate email subject field
2) Make fields required (and potentially validate them to what they should be)
3) More effective way to stop spam
Keep in mind I am a PHP novice, I only use the include function, everyhting else Ive used has been found online but can't get a lot of it to work properly.
Thank you for your help!