0

I am trying to send email using AJAX and PHP but no success:(
My success function alerts me that it is WORKING but i get nothing in my mail box. PHP form is located in my ROOT folder and it is working so i know it is not PHP problem. Been trying for hours to solve this but no effect. Can someone help out? THX!!! This is what my console.log shows:

name=MY NAME&email=dejo.dekic@yahoo.com&message=SOME MESSAGE pagepays.js
POST http://www.homepagepays.robertpeic.com/kontakt.php 200 OK 284ms My jquery code looks like this:

      $('#button').click(function(){
      var name = $('#name').val();
      var email = $('#email').val();
      var message = $('#message').val();

      var data ='name=' + name + '&email=' + email + '&message=' + message;
      console.log(data);
      $.ajax({
      type:"POST",
      url:'kontakt.php',
      data: data,
      success: function(){
      alert('Working!');
      }

      });
      return false;
      });
Dejo Dekic
  • 2,088
  • 4
  • 27
  • 50

2 Answers2

1

I don't see anything wrong with your jQuery. Does you php page actually send an email to you if you load it up with either variables in the URL, or with some default values within the page for the email?

You could try printing out the data that the php page is receiving by getting the data and then using this in your php page.

print("$name - $email - $message");

and then change your jQuery ajax call to this;

$.ajax({
  type:"POST",
  url:'kontakt.php',
  data: data,
  success: function(response){
    alert(response);
  }
});

This should tell you if the php page is working with the ajax call and the data you sent. If you don't get back the data you expected then there must be something with how the php page is getting its variables.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Novocaine
  • 4,692
  • 4
  • 44
  • 66
1

You might need to URI Encode your passed values. If any of the fields have = or &, it could throw your URL Off. Of course, based on my comments above, I think you should serialize your Form and encode that, it can also be done your way.

  var name = encodeURIComponent($('#name').val());
  var email = encodeURIComponent($('#email').val());
  var message = encodeURIComponent($('#message').val());

JSFiddle: http://jsfiddle.net/UXZQk/5/

Dutchie432
  • 28,798
  • 20
  • 92
  • 109