0

I have a long piece of Java script code and I need to add Email action in the middle of the code. However, I know that I cannot directly send Email with Java script so I used :

           $.ajax({
            type:"post",
            url:"mail.php",
            success:function(){
            alert("it was a success");
             }
           });
             window.location = url;
           }

          });

inside of my mail.php file I have very simple Email tag which is :

   <?php

  //send email
   mail('test@gmial.com','My Subject' , 'test');

  ?>

However it says "it was success" on JS but it does not do anything on PHP. I even tried to print something on PHP but it does not work. Any idea??

1 Answers1

0

Did you setup an mail server on your server?

Try this:

if( !mail('test@gmial.com','My Subject' , 'test') )
   echo "Probably no mail server found.";
else
   echo "mail server is not the problem."

And log it in js:

$.ajax({
            type:"post",
            url:"mail.php",
            success:function(res){
            console.log(res);
             }
           });
             window.location = url;
           }

          });