我有一个xml输出文件,这个文件是使用PHP Array创建的。我也使用PHP自动将xml文件作为电子邮件附件发送。
现在我有一个平板电脑应用程序,此应用程序从电子邮件附件接收,读取和显示xml文件的输出。 (注意:我没有内部访问此应用程序的代码)。
但遗憾的是,我没有收到我在电子邮件中发送的平板电脑应用程序(我通过PHP创建的)中的xml文件。
如何解决这个问题?谢谢
我有这个错误:
Warning: filesize() [function.filesize]: on line 20
Warning: fopen(/usr/local/apache/htdocs/Test/filename.xml) [function.fopen]: on line 21
Warning: fread(): supplied argument is not a valid stream resource on line 22
Warning: fclose(): supplied argument is not a valid stream resource on line 23
注意:未定义的变量:第47行的/home7/homecre1/public_html/Test/Mail.php中的message_body 发送
这里是Mail PHP
<?php
/* Email Detials */
$mail_to = "";
$from_mail = "";
$from_name = "Test";
$reply_to = "";
$subject = "Test only";
$message = "";
/* Attachment File
Attachment location */
$file_name = "filename.xml";
$path = "www.domainname.com/folder/folder/";
// Read the file content
$file = $path.$file_name;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
/* Set the email header
Generate a boundary */
$boundary = md5(uniqid(time()));
// Email header
$header = "From: ".$from_name." \r\n";
$header .= "Reply-To: ".$reply_to."\r\n";
$header .= "MIME-Version: 1.0\r\n";
// Multipart wraps the Email Content and Attachment
$header .= "Content-Type: multipart/mixed;\r\n";
$header .= " boundary=\"".$boundary."\"";
$message .= "This is a multi-part message in MIME format.\r\n\r\n";
$message .= "--".$boundary."\r\n";
/* Email content
Content-type can be text/plain or text/html */
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "$message_body\r\n";
$message .= "--".$boundary."\r\n";
/* Attachment
Edit content type for different file extensions */
$message .= "Content-Type: application/xml;\r\n";
$message .= " name=\"".$file_name."\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= " filename=\"".$file_name."\"\r\n";
$message .= "\r\n".$content."\r\n";
$message .= "--".$boundary."--\r\n";
// Send email
if (mail($mail_to, $subject, $message, $header)) {
echo "Sent";
} else {
echo "Error";
}
?>
PHP数组到xml
<?php
header('Content-Type: text/xml');
$xml_Form = new SimpleXMLElement("<?xml version=\"1.0\"?><Form></Form>");
$xml_Form->addAttribute('label', 'Home Visit Form');
$Fields= $xml_Form->addChild('Field');
$Fields->addAttribute('name', 'CP_REASON_CODE');
$Fields->addAttribute('label', 'Reason Code');
$Fields->addAttribute('value', '');
$Fields->addAttribute('type', 'EditText');
$Fields->addAttribute('format', 'string');
$Fields= $xml_Form->addChild('Field');
$Fields->addAttribute('name', 'CP_NOTES');
$Fields->addAttribute('label', 'Notes');
$Fields->addAttribute('value', '');
$Fields->addAttribute('type', 'EditText');
$Fields->addAttribute('format', 'string');
$Fields= $xml_Form->addChild('Field');
$Fields->addAttribute('name', 'CP_PICTURE_RECEIPT');
$Fields->addAttribute('label', 'Receipt picture');
$Fields->addAttribute('value', '');
$Fields->addAttribute('type', 'Picture');
$Fields->addAttribute('format', 'string');
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml_Form->asXML());
//Echo XML - remove this and following line if echo not desired
echo $dom->saveXML();
//Save XML to file - remove this and following line if save not desired
$dom->save('CashPickup.xml');
?>