POST请求XML格式错误

I have a problem with an EPP XML request. I have been getting a Command Syntax Error response from the API for quite some time now. I've been in contact with the technical department who just recently responded that my XML is being received as malformed, being split in the middle. I don't know why.

I compile the PHP to XML using the DOMDocument class. I return every XML build method using __toString() which returns $this->saveXML(); which dumps the tree as string. I then send a POST request. Every other method works fine, but not this.

Code here:

https://github.com/OssiPesonen/epp_depo

I actually dump my XML using:

header('Content-type: text/plain');
echo $xml;
die();

And every time it gives me:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
  <command>
    <create>
      <contact:create xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
        <contact:id>1</contact:id>
        <contact:role>5</contact:role>
        <contact:type>1</contact:type>
        <contact:postalInfo type="loc">
          <contact:isfinnish>1</contact:isfinnish>
          <contact:firstname>Essi</contact:firstname>
          <contact:lastname>Esimerkki Oy</contact:lastname>
          <contact:name>HR</contact:name>
          <contact:org>Esimerkki Oy</contact:org>
          <contact:birthDate>2005-04-03T00:00:00.0Z</contact:birthDate>
          <contact:identity>123423A123F</contact:identity>
          <contact:registernumber>20824760</contact:registernumber>
          <contact:addr>
            <contact:street>Test Street</contact:street>
            <contact:pc>00000</contact:pc>
            <contact:cc>FI</contact:cc>
            <contact:city>City</contact:city>
          </contact:addr>
        </contact:postalInfo>
        <contact:voice x="1234">+358401234567</contact:voice>
        <contact:email>testi@testi.fi</contact:email>
        <contact:legalemail>testi@testi.fi</contact:legalemail>
        <contact:disclose flag="0">
          <contact:addr/>
          <contact:email/>
        </contact:disclose>
      </contact:create>
    </create>
    <clTRID>E1144-588371f25ab80</clTRID>
  </command>
</epp>

This doesn't look malformed, right? Yet, the technical support responded to me, that after <contact:city> was split before the closing tag:

contact:city>
            <contact:sp>VA</contact:sp>
            <contact:pc>20166-6503</contact:pc>
            <contact:cc>US</contact:cc>
          </contact:addr>
        </contact:postalInfo>
        <contact:voice x="1234">+3581231234</contact:voice>
        <contact:fax>+04040as</contact:fax>
        <contact:email>jdoe@example.com</contact:email>
        <contact:legalemail>jdoe@example.com</contact:legalemail>
        <contact:disclose flag="0">
          <contact:addr/>
          <contact:email/>
        </contact:disclose>
      </contact:create>
    </create>
    <clTRID>E1144-5867f93f6503a</clTRID>
  </command>
</epp>
05-04-03T22:00:00.0Z</contact:birthDate>
          <contact:identity>010188-123A</contact:identity>
          <contact:registernumber>123456-7</contact:registernumber>
          <contact:addr>
            <contact:street>123 Example Dr.</contact:street>
            <contact:street></contact:street>
            <contact:street></contact:street>
            <contact:city>Dulles</

Any ideas what might cause this? Because I can't see it.

Edit

After exhausting my options I've uploaded the code to Github to be viewed.

https://github.com/OssiPesonen/epp_depo

Well, the answer was simple, yet I cannot understand why it's the solution.

I basically removed all the failsafes from the send() method and leaving just this:

private function send($buffer)
{
    if(fwrite($this->socket, $buffer)) {
        return true;
    }

    return false;
}

I don't really know what it was that cut the XML string in the previous one, but this will do for our platform.