ajaxified php邮件不起作用

I'm running on a MAC and I am trying to use php mail with ajax implementation.

I have simplified my code to the point that it was reduced to strings:

In my .js file :

function ajaxMail2() {



        $('#sending').show();


        $.ajax({

            type:'POST',
            url:'ajax/mail.php',

            success:function(data, status) {
                $('#sending').hide();
                $('#success').fadeIn(1000,function() {
                    //$(this).delay(200).fadeOut(1000);
                });
            },

            error:function(data, status, e) {
                $('#sending').hide();
                $('#fail').fadeIn(1000,function() {
                    $(this).delay(200).fadeOut(1000);
                });
            }

        });


    }

and on my .php file :

<?php



$to = 'foo@gmail.com';
mail($to,'test','test');



?>

When the form is submitted, it goes to the success function but no email was sent to $to. Any ideas?

<?php
$to = 'foo@gmail.com';
if(mail($to,'test','test')) {
  echo "sent";
}
else {
  echo "error";
}
exit;
?>

and your js

.....
success:function(data, status) {
     if("sent" == data) { 
         $('#sending').hide();
         $('#success').fadeIn(1000,function() {
            //$(this).delay(200).fadeOut(1000);
         });
    }
    else {
        alert("Could not send mail");
    }
},

this way you could check if mail was sent or not

Not sure if this solves your problem, but try adding headers:

$headers  = 'MIME-Version: 1.0' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";
$headers .= 'To: Someone <foo@gmail.com>' . "
";
$headers .= 'From: Me <my@mail.com>' . "
";

$to = 'foo@gmail.com';
if(mail($to,'test','test')) {
   .....