Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在电子邮件中接收xml附件_Php_Android_Xml_Email - Fatal编程技术网

Php 无法在电子邮件中接收xml附件

Php 无法在电子邮件中接收xml附件,php,android,xml,email,Php,Android,Xml,Email,我有一个xml输出文件,这个文件是使用PHP数组创建的。我也使用PHP自动将xml文件作为电子邮件附件发送 现在我有了一个平板电脑应用程序,这个应用程序接收、读取和显示来自电子邮件附件的xml文件的输出。注意:我没有此应用程序代码的内部访问权限 但不幸的是,我在电子邮件中发送的通过PHP创建的平板电脑应用程序中没有收到xml文件 如何解决这个问题?多谢各位 我有以下错误: Warning: filesize() [function.filesize]: on line 20 Warning:

我有一个xml输出文件,这个文件是使用PHP数组创建的。我也使用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\u html/Test/Mail.php中的message_body 发送

这是邮件

<?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');

 ?>

文件位置不应该是URL,而是服务器路径。试试$path=folder/;如果从服务器的根目录运行脚本。打开@Fred ii后立即将错误报告添加到文件顶部-我现在更改了,我在电子邮件中收到了xml文件,但在tablet应用程序中,我没有收到xml文件给我一分钟,我会测试你的代码。测试对我来说很好。收到了电子邮件和文件。这是你的文件路径。另外,您确实在脚本$mail_TO=”的顶部填充了FROM和TO的区域$从_mail=;,正当