我有一个像这样动态创建的文件:
// Create and save the string on the file system
$str = "Business Plan: \nSome more text";
$fp = fopen("alex.txt", 'w+');
fwrite($fp, $str);
// email with the attachment
$to = 'alex.genadinik@gmail.com';
$subject = 'Your business plan attached';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: BusinessPlanApp@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('alex.txt')));
$contents = "some contents of the email";
mail($to, $subject, $contents, $headers);
该文件正在保存到文件系统中,并且一封带有正确正文和主题的电子邮件正在发送给我。
唯一出错的是附件是零字节的未命名文件。知道为什么会发生这种情况吗?是权限问题吗?或者在我的电子邮件中?
谢谢!