I've been trying to send an email whenever a user is trying to quit the page, i have used the beforeunload
event in jQuery.
jQuery Code:
$(window).on("beforeunload", function(e) {
console.log('posting');
$.post("file.php", {
d: logData,
s: 'New User Activity',
t: 'example@gmail.com',
r: 'From: info@address.com\r\n',
},
function(data, status) {
console.log(data);
);
});
This code always logs successfully the response from file.php
unless i'm using the mail() function, btw it only doesn't console.log
whatever after the mail() function.
file.php contents:
<?php
$fo = fopen("file.txt","a");
fwrite($fo,"Contents:\n".$_POST['d']."\nSubject: ".$_POST['s']."\nTo:".$_POST['t']);
fclose($fo); // THIS WORKS SUCCESSFULLY
mail("example@domain.com","Subject","Msg"); //I changed this to static values so i check if the problem
//is coming from the POST, but still no success
echo "fine"; //THIS DOESN'T SHOW UP IN THE CONSOLE
?>