d.shankar Posted November 7, 2007 Share Posted November 7, 2007 I have two files the first one contains an AJAX script that sends parameter "1" to the php page. If 1 is received then it sends mail else it won send. Here's the code.. The AJAX script to run <?php ?> <script> var client = new XMLHttpRequest(); client.onreadystatechange = function() { client.open("POST", "http://localhost/chkmail.php",true) client.send("ptr=1"); } </script> <?php ?> The php page that contains an email code to send if it gets the parameter 1 <?php ini_set("sendmail_from", "me@myself.com"); $mailptr=$_GET['ptr']; if($mailptr==1) { $to="tome@gmail.com"; $subject="test"; $body="nothing"; mail($to, $subjectx, $body); } ?> Can somebody suggest help ? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 first of all $mailptr=$_GET['ptr']; should be $mailptr=$_POST['ptr']; as your using the post method client.open("POST", "http://localhost/chkmail.php",true) Quote Link to comment Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 Still the same problem. Checked all bulk and spam folders.. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 is your SMTP up and running do you receive mail from mail function in PHP Quote Link to comment Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 Yea my smtp is working fine. When i hardcode the below php script it works , but it is not getting fetched from AJAX <?php ini_set("sendmail_from", "me@myself.com"); $mailptr=1; if($mailptr==1) { $to="tome@gmail.com"; $subject="test"; $body="nothing"; mail($to, $subjectx, $body); } ?> Got any other ideas ?? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 well try this javascript code <script> var client = new XMLHttpRequest(); client.open("POST", "http://localhost/chkmail.php",true); client.onreadystatechange = function() { alert('sent');} client.send("ptr=1"); </script> Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted November 7, 2007 Share Posted November 7, 2007 You know you don't have to quote yourself everytime you post, we'll be able to read it perfectly fine without the quote. Quote Link to comment Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 Hello rajiv. The alert is getting displayed but the mail isnt sent. Btw mr.halofreek , it has become a habit for me .. so sorry Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 are you using the $_GET or the $_POST in your chkmail.php php it should work now unless I am overlooking something Quote Link to comment Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 Yeah its set $_POST only. Quote Link to comment Share on other sites More sharing options...
HaLo2FrEeEk Posted November 7, 2007 Share Posted November 7, 2007 Seriously, just hit reply, then type your post, don't hit quote, you don't need those tags, ok. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 script> var params = "ptr=1"; var client = new XMLHttpRequest(); client.open("POST", "http://localhost/chkmail.php",true); client.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); client.setRequestHeader("Content-length", params.length); client.setRequestHeader("Connection", "close"); client.onreadystatechange = function() { alert('sent');} client.send(params); </script> more information can be found at http://www.openjs.com/articles/ajax_xmlhttp_using_post.php Quote Link to comment Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 It works gr8 ! Thanks a lot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.