PHPMailer AddAttachment远程文件

时间:2013-05-10 15:27:20

标签: php attachment phpmailer email-attachments

$remote_path = 'http://bucket.s3.amazonaws.com/whatever.txt';
$mail->AddAttachment($remote_path);

这不起作用,因为PHPMailer需要本地文件或二进制数据。它也尝试了这个:

$data = file_get_contents($remote_path);
$mail->AddAttachment($data);

如果我不需要,我不想将其下载到本地文件中。为什么file_get_contents版本不起作用?它是字符串而不是二进制数据吗?

编辑:我没有错误。

1 个答案:

答案 0 :(得分:7)

你应该看一个名为AddStringAttachment的替代phpmailer函数:

AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream')

http://phpmailer.worxware.com/index.php?pg=tutorial#3.2