PHPMailer - 使用URL附加远程文件

T30*_*T30 10 php email phpmailer

PHPMailer检查is_file每个附件(在addAttachment函数中,在class.phpmailer.php文件中):

if (!@is_file($path)) {
    throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,我is_file只能提供完整的本地文件路径,而不是URL:

is_file('C:/wamp/www/myFolder/rocks.png');      //True
is_file('http://localhost/myFolder/rocks.png'); //False :(
Run Code Online (Sandbox Code Playgroud)

所以我无法从远程服务器附加任何文件.

我究竟做错了什么??这可能是许可问题吗?

编辑:

我知道还有其他方法可以检查文件是否存在.

但是is_filePhpMailer库中,我更喜欢不触摸它,我想知道是否可以使用它的方法使其工作.

谢谢.

Syn*_*hro 19

它不需要解决方法,您只是使用明确用于远程资源上的本地文件的函数.要附加远程资源而不涉及本地文件,只需执行以下操作:

$mail->addStringAttachment(file_get_contents($url), 'filename');
Run Code Online (Sandbox Code Playgroud)

我不推荐这种直接内联方法,因为它使错误处理更加困难(例如,如果URL无法响应).

这基本上是这个问题的重复.