我试图通过添加一个允许我使用字符串数据而不是文件路径添加附件的方法来扩展来自Worx的PHP邮件程序类.
我提出了这样的事情:
public function addAttachmentString($string, $name='', $encoding = 'base64', $type = 'application/octet-stream')
{
$path = 'php://memory/' . md5(microtime());
$file = fopen($path, 'w');
fwrite($file, $string);
fclose($file);
$this->AddAttachment($path, $name, $encoding, $type);
}
Run Code Online (Sandbox Code Playgroud)
但是,我得到的只是一个PHP警告:
PHP Warning: fopen() [<a href='function.fopen'>function.fopen</a>]: Invalid php:// URL specified
Run Code Online (Sandbox Code Playgroud)
原始文档没有任何体面的例子,但我在互联网上发现了一对(包括一个在SO上),根据它们我的用法看起来是正确的.
有没有人使用过这个?
我的另一种方法是创建一个临时文件并清理 - 但这意味着必须写入光盘,并且此函数将用作大批量进程的一部分,我希望尽可能避免慢速光盘操作(旧服务器).这只是一个短文件,但脚本电子邮件的每个人都有不同的信息.