我正在尝试创建一个XML文件,然后将其作为电子邮件发送,以及强制下载,问题在于XML文档包含一些随机数结束它,使它无用。DOMDocument正在生成XML中的尾数据
代码:
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 = '[email protected]';
$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://ogserver.net/licensing/tutorial.html';
$pemail->AddAddress($email);
$pemail->AddAttachment($file_to_attach, 'License.xml');
$pemail->Send();
$filepath = realpath($file_to_attach);
echo readfile($file_to_attach);
你是指数字自动生成? – 2014-11-02 13:00:56
我会假设,在我的文件结尾处只有几个随机数(通常是三个),每次生成文件时它们都不相同。 – Hobbyist 2014-11-02 13:04:33
你可以只发布/您的示例生成的XML的URL? – 2014-11-02 13:05:51