Jump to content

[SOLVED] AJAX test with PHP [Simple One]


d.shankar

Recommended Posts

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

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 ??

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>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.