0

Hi I have a Contact form and a PHP file that handles the email after the form is successfully filled out. For some reason I am not receiving any emails from this form. Was just curious if my code was correct.

HTML FORM:

<form method="post" role="form" name="sentMessage" id="contactForm" action="/public_html/mail/contact_me.php" novalidate>
                            <div class="col-md-6">
                                <div class="form-group">
                                 <input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required >
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="form-group">
                                    <input type="email" class="form-control" placeholder="Your Email *" id="email" name="email" required >
                                    <p class="help-block text-danger"></p>
                                </div>
                                <div class="form-group">
                                    <input type="tel" class="form-control" placeholder="Your Phone *" id="phone" name="phone" required >
                                    <p class="help-block text-danger"></p>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <textarea class="form-control" placeholder="Your Message *"  id="message" name="message" required ></textarea>
                                    <p class="help-block text-danger"></p>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                            <div class="col-lg-12 text-center">
                                <div id="success"></div>
                                <button type="submit" class="btn btn-xl" >Send Message</button>
                            </div>
                        </form>

PHP CODE:

// Check for empty fields
if(empty($_POST['name'])        ||
   empty($_POST['email'])       ||
   empty($_POST['phone'])       ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

// Create the email and send the message
$to = 'will@blacart.com'; 
$email_subject = "Website Contact:  $name";
$email_body = "You have received a contact request from tandemmetal.com.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@tandemmetals.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;
Emericas
  • 1
  • 1

1 Answers1

0

You can try to use \r\n instead of \n.

$headers = "From: noreply@tandemmetals.com\r\n";
$headers .= "Reply-To: $email_address\r\n"; 

According to http://php.net/manual/ru/function.mail.php (in case, if your server on Windows).

Sergio Ivanuzzo
  • 1,820
  • 4
  • 29
  • 59