0

in my code i am trying to send mail from server using PHPMailer and it's not working.my form is.

<div class="span12 contact-form centered">
                            <h3>Say Hello</h3>
                            <div id="successSend" class="alert alert-success invisible">
                                <strong>Well done!</strong>Your message has been sent.</div>
                            <div id="errorSend" class="alert alert-error invisible">There was an error.</div>
                            <form id="contact-form" action="ink.php">
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="cname" name="cname" placeholder="* Company Name..." />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="name" name="name" placeholder="* Contact Person..." />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <textarea class="span12" name="address" id="address" placeholder="* Address..."></textarea>                      </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="mobile" name="mobile" placeholder="* Mobile No..." />
                                        <div class="error left-align" id="err-mobile">Please enter Valid Mobile No.</div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="country" name="country" placeholder="* Country..." />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="city" name="city" placeholder="* City..." />                                        </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="telephone" name="telephone" placeholder="* Telephone..." />
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="email" name="email" id="email" placeholder="* Email..." />
                                        <div class="error left-align" id="err-email">Please enter valid email adress.</div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="web" name="web" placeholder="* Website..." />                                        </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <textarea class="span12" name="message" id="message" placeholder="* Message..."></textarea>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <button id="send-mail" class="message-btn">Send message</button>
                                    </div>
                                </div>
                            </form>
                        </div>

and my php code is ink.php.

<?php
include('config.php');
include('PHPMailer-master/PHPMailerAutoload.php');
$cname=$_POST['cname'];
    $name=$_POST['name'];
    $addr=$_POST['address'];
    $mobile=$_POST['mobile'];
    $country=$_POST['country'];
    $city=$_POST['city'];
    $telephone=$_POST['telephone'];
$email=$_POST['email'];
$web=$_POST['web'];
$msg=$_POST['message'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $data['success'] = false;
}
$mail = new PHPMailer;

//From email address and name
    $mail->From = "inquiry@vkinds.com";
    $mail->FromName = "Full Name";

    //To address and name
    $mail->addAddress("jesadiyadivyesh@gmail.com", "Recepient Name");

    //Address to which recipient will reply
    $mail->addReplyTo("jesadiyadivyesh@gmail.com", "Reply");

    //Send HTML or Plain Text email
    $mail->isHTML(true);
$mail->Subject = 'VK Industries Web Inquiry';
$mail->Body    = '<html><head><title>VK Industries Web Inquiry</title></head><body><table><tr><td>Company Name :  </td><td> '.$cname.'</td></tr><tr><td>Email id :  </td><td> '.$userEmail.'</td></tr><tr><td>Person Name :  </td><td> '.$name.'</td></tr><tr><td>Address :  </td><td> '.$addr.'</td></tr><tr><td>Mobilr No :  </td><td> '.$mobile.'</td></tr><tr><td>Country :  </td><td> '.$Country.'</td></tr><tr><td>City :  </td><td> '.$city.'</td></tr><tr><td>Telephone :  </td><td> '.$telephone.'</td></tr><tr><td>Email id :  </td><td> '.$email.'</td></tr><tr><td>Website : </td><td> '.$web.'</td></tr><tr><td>Message : </td><td> '.$msg.'</td></tr><tr></table></body></html>';
$mail->AltBody = $name;
if($mail->send()) {
$data['success'] = true;
} else {
$data['success'] = false;
}
echo json_encode($data);
?>

and i also have jquery function.

$("#send-mail").click(function () {

    var nameCompare = /^([0-9+]{6,15})$/; // Syntax to compare against input
    var name = $('input#mobile').val(); // get the value of the input field
    var error = false;
    if (name == "" || name == " " || !nameCompare.test(name)) {
        $('#err-mobile').show(500);
        $('#err-mobile').delay(4000);
        $('#err-mobile').animate({
            height: 'toggle'
        }, 500, function () {
            // Animation complete.
        });
        error = true; // change the error state to true
    }

    var emailCompare = /^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/; // Syntax to compare against input
    var email = $('input#email').val().toLowerCase(); // get the value of the input field
    if (email == "" || email == " " || !emailCompare.test(email)) {
        $('#err-email').show(500);
        $('#err-email').delay(4000);
        $('#err-email').animate({
            height: 'toggle'
        }, 500, function () {
            // Animation complete.
        });
        error = true; // change the error state to true
    }


  /*  var comment = $('textarea#comment').val(); // get the value of the input field
    if (comment == "" || comment == " ") {
        $('#err-comment').show(500);
        $('#err-comment').delay(4000);
        $('#err-comment').animate({
            height: 'toggle'
        }, 500, function () {
            // Animation complete.
        });
        error = true; // change the error state to true
    }*/

    if (error == false) {
        var dataString = $('#contact-form').serialize(); // Collect data from form
        $.ajax({
            type: "POST",
            url: $('#contact-form').attr('action'),
            data: dataString,
            timeout: 6000,
            error: function (request, error) {

            },
            success: function (response) {
                response = $.parseJSON(response);
                if (response.success) {
                    $('#successSend').show();
                    $("#cname").val('');
                    $("#name").val('');
                    $("#address").val('');
                    $("#mobile").val('');
                    $("#country").val('');
                    $("#city").val('');
                    $("#telephone").val('');
                    $("#email").val('');
                    $("#web").val('');
                    $("#message").val('');
                } else {
                    $('#errorSend').show();
                }
            }
        });
        return false;
    }

    return false; // stops user browser being directed to the php file
});

every time i send message it is showing success message but in my mail box mail is not received.

Divyesh Jesadiya
  • 1,105
  • 4
  • 30
  • 68
  • Have you checked your spam folders? Sometimes they go into spam! – Stack learner Apr 24 '16 at 07:19
  • use mailtrap.io and capture your mails, you can know if your mails are actually being sent or if the smtp you are using is at fault, your code seems pretty good! – Stack learner Apr 24 '16 at 07:30
  • Test one thing at a time - at the moment you don't know which part of your stack is not working. Test the email part by itself, check your mail server logs, since you're sending via mail() (PHPMailer's default) which uses your local mail server. – Synchro Apr 24 '16 at 07:45

0 Answers0