DOMDocument is producing trailing data in XML



I'm trying to create an XML file and then send it as an e-mail as-well as force a download, the problem is that the XML document contains a few random numbers at the end of it, making it useless.


Code:



header('Content-Disposition: attachment;filename=License.xml');
header('Content-Type: text/xml');
$document = new DOMDocument('1.0');
$document->formatOutput = true;
$element_account = $document->createElement("Account");
$attr_name = $document->createAttribute("Username");
$attr_pass = $document->createAttribute("Password");
$attr_key = $document->createAttribute("Key");

$attr_name->value = $user;
$attr_pass->value = $pass;
$attr_key->value = $key;

$element_account->appendChild($attr_name);
$element_account->appendChild($attr_pass);
$element_account->appendChild($attr_key);

$document->appendChild($element_account);

$file_to_attach = 'tmp/License'.$user.'.xml';

$document->save($file_to_attach);

require '../PHPMailer/PHPMailerAutoload.php';

$pemail = new PHPMailer();
$pemail->From = 'donotreply@OGServer.net';
$pemail->FromName = 'OGServer Licensing';
$pemail->Subject = 'Your OGServer License has arrived!';
$pemail->Body = 'Thank you for registering your product, you will find your License attached to the e-mail, if you have any questions about how to set up your license, you can view the tutorial here: http://ift.tt/1vz00Ur';
$pemail->AddAddress( $email );

$pemail->AddAttachment($file_to_attach, 'License.xml' );

$pemail->Send();

$filepath = realpath($file_to_attach);

echo readfile($file_to_attach);

No comments:

Post a Comment