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

Link to comment
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", "me@myself.com");
$mailptr=1;
if($mailptr==1)
{
$to="tome@gmail.com";
$subject="test";
$body="nothing";
mail($to, $subjectx, $body);
}
?>

 

Got any other ideas ??

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.