Help setting up a contact form done in php


#1

Hello,

I am working on a template I purchased for a client, and I’ve set up everything on the server correctly. However, I am having problems with the contact form that is included as a php file. I am sending test emails from the form itself (that is currently online) but my client is not receiving any type of messages in his email.

I checked the Dreamhost forum and I added this code to my HTML:

thinking it could fix the problem, but it’s not doing anything.

Here is the code for the contact-send.php file:

<?php //Ensures no one loads page and does simple spam check. if(isset($_POST['name']) && empty($_POST['spam_check'])) { //Include our email validator for later use require 'email-validator.php'; $validator = new EmailAddressValidator(); //Declare our $errors variable we will be using later to store any errors. $errors = array(); //Setup our basic variables $input_name = strip_tags($_POST['name']); $input_email = strip_tags($_POST['email']); $input_message = strip_tags($_POST['message']); //We'll check and see if any of the required fields are empty. //We use an array to store the required fields. $required = array( 'Email field' => 'email', 'Message field' => 'message'); //Loops through each required $_POST value //Checks to ensure it is not empty. foreach($required as $key=>$value) { if(isset($_POST[$value]) && $_POST[$value] !== '') { continue; } else { $errors[] = $key . ' cannot be left blank'; } } //Make sure the email is valid. if (!$validator->check_email_address($input_email)) { $errors[] = 'Email address is invalid.'; } //Now check to see if there are any errors if(empty($errors)) { //No errors, send mail using conditional to ensure it was sent. if(mail('YOUREMAILADDRESS', "Message from $input_name ", $input_message, "From: $input_email")) { echo 'Your email has been sent.'; } else { echo 'There was a problem sending your email.'; } } else { //Errors were found, output all errors to the user. echo implode('
', $errors); } } else { die('Direct access to this page is not allowed.'); } ?>

I also have an email-validator php file that I can paste if necessary.

What am I doing wrong? Is this file wrong in any way? I need to fix this ASAP so my client receives incoming messages through the website, and I am not a programmer so I can’t fix it myself :frowning:

Any help will be greatly appreciated! Thanks


#2

If you haven’t done already, on the following line, you should replace ‘YOUREMAILADDRESS’ with a real email address like ‘someone@example.com’


#3