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", "[email protected]"); $mailptr=$_GET['ptr']; if($mailptr==1) { $to="[email protected]"; $subject="test"; $body="nothing"; mail($to, $subjectx, $body); } ?> Can somebody suggest help ? Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/ 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) Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386488 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.. Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386491 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 Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386497 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", "[email protected]"); $mailptr=1; if($mailptr==1) { $to="[email protected]"; $subject="test"; $body="nothing"; mail($to, $subjectx, $body); } ?> Got any other ideas ?? Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386499 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> Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386501 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. Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386502 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 Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386508 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 Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386510 Share on other sites More sharing options...
d.shankar Posted November 7, 2007 Author Share Posted November 7, 2007 Yeah its set $_POST only. Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386513 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. Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386515 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 Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386520 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. Link to comment https://forums.phpfreaks.com/topic/76341-solved-ajax-test-with-php-simple-one/#findComment-386523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.