2016-01-13 99 views
-1

我想在邮件中附加5个动态文本文件但不工作。将多个文件附加到CakePHP中的电子邮件

我在邮件发送单个附件的工作完美我的代码是:

$Email->attachments('path/to/example.txt'); 

但我在邮件发送多附件不能正常工作。

我的代码是:

$Email->attachments('path/to/example.txt','path/to/example1.txt','path/to/example3.txt','abs/path/to/example4.txt','path/to/example5.txt'); 
+2

您可能希望在文档细看第一,并检查如何'附件()'方法是精神疾病中使用。 ps,请始终提及您的确切CakePHP版本并相应地标记您的问题 - 谢谢。 – ndm

+0

感谢您的宝贵意见。我的蛋糕php版本是2.3。 – devrider

+0

我检查附件文件的文档,但没有定义如何发送多个attachment.And也我的单一电子邮件附件工作fine.only不工作多个附件。请帮助我。 – devrider

回答

0

尝试使用多个连接验证码:

$Email->attachments(array(
      'example.txt' => array(
       'file' => 'path/to/example.txt', 
       'mimetype' => 'text/plain' 
      ), 
example1.txt' => array(
       'file' => 'path/to/example1.txt', 
       'mimetype' => 'text/plain' 
      ), 
example3.txt' => array(
       'file' => 'path/to/example3.txt', 
       'mimetype' => 'text/plain' 
      ), 
example4.txt' => array(
       'file' => 'path/to/example4.txt', 
       'mimetype' => 'text/plain' 
      ), 
example5.txt' => array(
       'file' => 'path/to/example5.txt', 
       'mimetype' => 'text/plain' 
      ) 

     )); 
+0

非常感谢@ashish – devrider

+0

除非您遇到'mimetype'问题或者想要重命名附加文件,否则这个数组结构对于附加多个文件并创建更多的代码比创建更多的代码有点矫枉过正,因此更难以维护。你只需要指定一个文件路径的数组,如[这里显示](http://stackoverflow.com/a/34761362/311992)。 – drmonkeyninja

0

尝试

$Email->attachments(
    array(
     'path/to/example.txt', 
     'path/to/example1.txt', 
     'path/to/example3.txt', 
     'abs/path/to/example4.txt', 
     'path/to/example5.txt' 
    ) 
); 
+0

不能正常工作.... !!!! – devrider

0

正如documentationattachments方法描述带有一个数组作为第一个参数,以便您的代码如下所示: -

$Email->attachments(array(
    'path/to/example.txt', 
    'path/to/example1.txt', 
    'path/to/example3.txt', 
    'abs/path/to/example4.txt', 
    'path/to/example5.txt' 
)); 

这也清楚地陈述在API documentation (总是值得检查)。

如果你看看attachments()的实际代码,你会发现如果你只传递一个字符串作为第一个参数,那么它会被转换为array。你的代码不工作,因为该方法不需要多个参数。

+0

不适用于多个附件。适用于单个附件。 – devrider

+0

不知道为什么这是它应该如何工作,以及我过去如何使用它。 – drmonkeyninja