PHP – Jquery contact form sends blank emails

I’ve been searching for a solution. Seen other topics, none was helpful so far. So wanted to ask mine. Sorry if it’s duplicating another question.

Here is my html markup
in <-head><-/head>

    <script src=""></script>
    .error { display:none; }
    .success { display:none; }

<script type="text/javascript">
            var error = false;
            var name = $('#name').val();
            var email = $('#email').val();
            var message = $('#message').val();
            if(name.length == 0){
                var error = true;
            } else {
            if(email.length == 0 || email.indexOf('@') == '-1'){
                var error = true;
            } else {
            if(message.length == 0){
                var error = true;
            } else {
            } if(error == false){
                $('#send_message').attr({'disabled' : 'true', 'value' : 'Gönderiliyor...' });
                $.post("send_message.php", $("#contact_form").serialize(),function(result){
                    if(result == 'sent'){
                    } else {
                        $('#send_message').removeAttr('disabled').attr('value', 'Gönder');

in <-body><-/body>

<div class="container-fluid">
                        <p id="returnmessage"></p>
                        <form action="send_message.php" id="contactForm" method="post">
                            <h2 style="font-size:14px;line-height:18px;font-weight:600;padding-bottom:0;">Bize Yazın</h2>
                            <ul class="contactform">
                                    <div id="name_error" class="error" style="color:#aa3939; font-size:8px; line-height:8px;"> <i class="fa fa-exclamation"></i> Lütfen adınızı giriniz.</div>
                                    <span class="contact-input-icon" style="text-align:left"><i class="fa fa-user"></i></span>
                                    <div class="input-field">
                                        <input type="text" style="border:1px solid rgba(220,220,220,0.5)" name="name" id="name" value="" class="required requiredField" placeholder="Ad Soyad"/>
                                    <div id="email_error" class="error" style="color:#aa3939; font-size:8px; line-height:8px;"> <i class="fa fa-exclamation"></i> Lütfen eposta adresinizi giriniz.</div>
                                    <span class="contact-input-icon"><i class="fa fa-envelope"></i></span>
                                    <div class="input-field">
                                        <input type="email" style="border:1px solid rgba(220,220,220,0.5)" name="email" id="email" value="" class="required requiredField email" placeholder="Eposta"/>
                                <li class="textarea">
                                    <div id="message_error" class="error" style="color:#aa3939; font-size:8px; line-height:8px;"> <i class="fa fa-exclamation"></i> Lütfen mesajınızı giriniz.</div>
                                    <span class="contact-input-icon"><i class="fa fa-pencil"></i></span>
                                    <div class="input-field">
                                        <textarea name="message" style="border:1px solid rgba(220,220,220,0.5)" id="message" rows="6" cols="20" class="required requiredField" placeholder="Mesajınız"></textarea>
                                    <div id="mail_success" class="success" style="color:#00CC00"><i class="fa fa-check"></i> İlginiz için teşekkürler. En kısa sürede sizinle irtibata geçeceğiz.</div>
                                    <div id="mail_fail" class="error" style="color:#aa3939"><i class="fa fa-times"></i> Üzgünüz, mesajınız iletilemedi. Daha sonra lütfen tekrar deneyin.</div>
                                <li class="buttons">
                                    <input type="hidden" style="border:1px solid rgba(220,220,220,0.5)" name="submitted" id="submitted" value="true" />
                                    <button type="submit" style="border:1px solid #3f97cf" class="button cf_submit_p" id="send_message"><i class="fa fa-paper-plane-o" style="font-size:20px;color:#3f97cf"></i></button>
                    </div> <!--end container-fluid-->

and in send_message.php file;


    if($_SERVER['REQUEST_METHOD'] === 'POST'){

    //önce değişkenleri topluyoruz.
    $email_to =   ''; //epostanın gönderileceği adres
    $name     =   $_POST['name'];
    $email    =   $_POST['email'];
    $message  =   $_POST['message'];

    $msgTo = "From: $name rnEmail: $email rnMessage: rn$message";

    /*$header değişkeni ilave olanaklar için. Böylelikle yanıtla ya da ilet dediğimizde,
     posta kutusu kime cevap vereceğini bilecek */
    $headers  = "FROM: $emailrn";
    $headers .= "REPLY-TO: $emailrn";

    if(mail($email_to, $msgTo, $headers)){
        echo 'sent'; // Mailin gönderildiğini AJAXa paslıyoruz.
        echo 'failed';// ... ya da gönderilemediğini


There’s something missing, checked the class and id names many times, tried altering the names many times, but I guess, the form does not get the values.. The validation part works great, even displays success message after submit, and sends emails too.. But only the From, Message, Email parts, not the variables.

Can you please help.



Source: forms

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.