0

I've got a contact form on my website. However, whenever I click submit I do not receive anything to our e-mail address, although it does say it has been submitted.

I know a good amount of HTML but not a lot about PHP, so any help is welcome.

Below is the code:

<form id="contact-form" role="form" action="" method="POST">
    <div class="ajax-hidden">
        <div class="form-group wow fadeInUp">
            <label class="sr-only" for="c_name">Name</label>
            <input type="text" id="c_name" class="form-control" name="c_name" placeholder="Name">
        </div>
        <div class="form-group wow fadeInUp" data-wow-delay=".1s">
            <label class="sr-only" for="c_email">Email</label>
            <input type="email" id="c_email" class="form-control" name="c_email" placeholder="E-mail">
        </div>
        <div class="form-group wow fadeInUp" data-wow-delay=".2s">
            <textarea class="form-control" id="c_message" name="c_message" rows="7" placeholder="Message"></textarea>
        </div>
        <button type="submit" class="btn btn-lg btn-block wow fadeInUp" data-wow-delay=".3s">Send Message</button>
    </div>
    <div class="ajax-response"></div>
</form>
<script>
$('button').click(function () {
    var c_name = $("#c_name").val();
    var c_email = $("#c_email").val();
    var c_message = $("#c_message").val();
    $.ajax({ //create an ajax request to load_page.php
        type: "POST",
        url: "assets/php/contactForm.php",
        data: {
            "c_name": c_name,
            "c_email": c_email,
            "c_message": c_message
        },
        success: function (data) {
            if (data) {

                alert(data);
            } else {
                alert('Successfully not posted.');
            }
        }
    });
});
</script>

Contactform.php

<?php

// Contact
$to = 'krischlebus@gmail.com';
$subject = 'Portfolio ContactForm';

if(isset($_POST['c_name']) && isset($_POST['c_email']) && isset($_POST['c_message'])) {
    $name    = $_POST['c_name'];
    $from    = $_POST['c_email'];
    $message = $_POST['c_message'];

    if (mail($to, $subject, $from, $name, $message)) { 
        $result = array(
            'message' => 'Sent, thanks!',
            'sendstatus' => 1
        );
        echo json_encode($result);
    } else { 
        $result = array(
            'message' => 'Ooops, problem..',
            'sendstatus' => 1
        );
        echo json_encode($result);
    } 
}
?>
Lalit Kumar B
  • 47,486
  • 13
  • 97
  • 124

2 Answers2

0

Check your server's mail logs to see if the mail actually leaves from your server. (And to note the obvious, check your spam box before you do anything more.) If mail() returns TRUE it merely indicates that the message was accepted for delivery. Not that it was actually delivered.

Markus AO
  • 4,771
  • 2
  • 18
  • 29
0

Try installing and running PHPMailer, it's a much more thorough emailing system (free) and also gives rather more informative error responses if it fails to send the email.

Mail function is notoriously lame. You need to get headers EXACTLY correct on it and even then it can still fail to deliver as email clients such as gmail and hotmail, and most others use SFP and FROM address verification so your from address needs to be the same domain of the server you're sending the mail from.

To check the system works: Disable ALL spam filtering and catching systems on your receiving email and receiving server . Check the from domain is the same as the sending domain, check your spam folders, check your servers catch-all email address folder for dud/junk emails (usually something like mail@server.co.uk ).

But most importantly, use a better integrated mailer such as PHPMailer or SwiftMail.

Martin
  • 22,212
  • 11
  • 70
  • 132