title: MSXML2.XMLHTTP send data to PHP script
body: <p>I have been looking into an option to send data read from an attached file in an Outlook message, directly to a PHP script that will then insert the date in a nice MySQL database.
  The extraction of the file and the splitting of data all ok, but here is the trick...</p>
  
  <p>From the internet (<a href="http://jeremyslade.com/2009/04/outlook-vba-macro-to-post-email-body-to-the-web/" rel="nofollow">here</a>) I found a nice post by Jeremy Slade who has managed to send some data to a cgi scipt, all good.</p>
  
  <p>So, clever as I thought I was, I thought I could re-write this into dealing with a PHP script.
  But then the works stopped.</p>
  
  <p>I have shortened the code to below snippet;</p>
  
  <pre><code>Sub TestURL()
  
      Set xhr = CreateObject("MSXML2.XMLHTTP")
      URL = "http://somedomain.com/php/test.php"
  
      data = "someVariable=Test"
  
      With xhr
  
          .Open "POST", URL, False
          .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
          .Send data
  
      End With
  
  
  End Sub
  </code></pre>
  
  <p>This should, in theory, open a MSXML2.XMLHTTP request at the given URL and send whatever data with it to the script.</p>
  
  <p>Funny enough, the script is called, but no data is passed ?</p>
  
  <p>I've tried setting the PHP script to both $_GET and $_POST for the [someVariable] element, yet on neither is there any response ?
  When I set the PHP to $_GET I matched the VBA MSXML2.XMLHTTP object to "GET" as well and vice versa...</p>
  
  <p>I've tried passing the 'data' variable as argument to the 'function' .send by including it in brackets
  i.e.</p>
  
  <pre><code>   .send (data)
  </code></pre>
  
  <p>But this doesn't work either...</p>
  
  <p>I'm a bit at a loss, because the script is called, a dataline is added to the table yet there is not an actual transfer of the 'sent' data ??</p>
  
  <p>I've tried connecting the data string to the URL that is passed to the HTTP object, essentially passing a 'GET' URL to the HTTP object.
  i.e.</p>
  
  <pre><code>    URL = URL &amp; "?" &amp; data
  </code></pre>
  
  <p>but to no avail...:-(</p>
  
  <p>The php script works in itself properly, if I pass data directly from the browser 
  i.e.</p>
  
  <pre><code>   http://somedomain.com/php/test.php?someVariable=Test 
  </code></pre>
  
  <p>the data is correctly added and the variable is read...</p>
  
  <p>Can some more enlightened spirits guide me in the right direction ?</p>
  
  <p>20141016 ********** UPDATE **********</p>
  
  <p>Ok, when digging into stuff I found there is also an option to refer to the XmlHttp object as "Microsoft.XmlHttp" ?</p>
  
  <p>Funny enough, when setting the object like that,
  i.e.</p>
  
  <pre><code>    Set xhr = CreateObject("Microsoft.XMLHTTP")
  </code></pre>
  
  <p>The code works and the data is added to the table and the .responsText is a success message.</p>
  
  <p>Yet if I return to the original code, I get a PHP error message that tells me that there is an error in my PHP syntax ?? This would imply that the actual 'data' that is being send differs between using "MSXML2.XMLHTTP" and using "Microsoft.XMLHTTP" ???</p>
  
  <p>Have tried to dig out the difference between the two from internet but can't find any post that provides me with a full understanding of the subject ?</p>
  
  <p>Despite the fact that my code now works, I still have the bothering question of not understanding the difference between the two and would appreciate a reply from someone who does :-) As I now have a code that works, but not an understanding of why it works...:-)
  Or mroeover not an understanding of why the "MSXML2" option does NOT work...</p>
  
  <hr>
  
  <p>Much appreciated,</p>
  
  <p>Kindest regards</p>
  
  <p>Martijn</p>