www.webdeveloper.com
Results 1 to 3 of 3

Thread: AJAX "POST" email is not working

  1. #1
    Join Date
    Mar 2013
    Posts
    9

    AJAX "POST" email is not working

    The AJAX portion is
    Code:
    function emailXMLDoc(){
    var emailText = "TITLE:,Pending Order sent to Paypal";
    var x=document.getElementById("PurchaseOrder");
    for (var i=16;i<x.length-9;i++){
    emailText += "\n"+x.elements[i].id+","+x.elements[i].value;
    }
    var xmlhttp;
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("POST","ASP/PostOrderEmail.php",true);
    xmlhttp.setRequestHeader("submitteremail",document.forms[0].email.value,"body",emailText);
    xmlhttp.send();
    };
    The PostOrderEmail.php is very simple

    Code:
    <?php
    
    $messagetoadmin = $HTTP_POST_VARS['submitteremail'] ." has passed this information to Paypal:
    
    ";
    $messagetoadmin .= $HTTP_POST_VARS['body'];
    
    mail('sales@Yandina.com', 'Form Submitted: Pending Order', $messagetoadmin, 'From: '. $HTTP_POST_VARS['submitteremail']);
    ?>
    An alert in the AJAX code shows the message is good but the email doesn't arrive .

  2. #2
    Join Date
    Mar 2013
    Posts
    9
    I first tried putting the data to be "POST"ed in the xmlhttp.send(data here); but that didn't work so I tried including the data in the header. I kinda understand how the header delivers tokens that can be extracted with $HTTP_POST_VARS[- - - but I don't understand the way the data is transferred using xmlhttp.send(). How does it get into the .php email processing script?

  3. #3
    Join Date
    Sep 2008
    Posts
    260
    Not sure exactly what your code is suppose to do above with the emailXMLDoc() function. You appear to have hard coded values in areas that are suppose to be properties or keys. I would recommend just using jQuery to submit your form by Ajax. I'm somewhat new to jQuery but have a pretty good understanding. I googled this just now:

    Code:
    var dataString = ""; //your email data here
     
    $.ajax({  
      type: "POST",  
      url: "bin/process.php", //you will put your php file location here   
      data: dataString,  //this is your email data
      success: function() { };  //call back function for a successful submit 
    });  
    return false;
    It gets to the .php email processing script by referencing the .php file you want it to go to (the above "url" property).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles