【问题标题】:Cakephp .xls file attachment through email component通过电子邮件组件的 Cakephp .xls 文件附件
【发布时间】:2013-01-04 19:31:09
【问题描述】:

我正在使用 CakePHP,需要发送带有 .xls 文件附件的邮件。

虽然我尝试了很多但没有成功。

注意 - 仅供参考,邮件中仅附有 PDF 文件。

请在下面找到我的代码 -

$this->Email->to = 'email address';    
$this->Email->from = 'From email address';
$this->Email->subject = 'Subject'; 
$this->Email->template = 'template name'; 
$Path = TMP;
$fileName = 'testfile.xls';        
$this->Email->filePaths = array($Path);
$this->Email->attachments = array($fileName);                
$this->Email->send();

每次我执行这段代码sn-p时,连邮件都在接收,但没有附件。

【问题讨论】:

  • 您使用的是哪个版本的蛋糕?看起来像 1.x 语法

标签: excel email cakephp attachment xls


【解决方案1】:

文档 (http://book.cakephp.org/2.0/en/core-utility-libraries/email.html#sending-attachments) 对此非常清楚。 您需要将其作为数组提交,文件名作为键,路径作为数组键“文件”:

$email->attachments(array(
    'photo.png' => array(
        'file' => '/full/some_hash.png',
        'mimetype' => 'image/png',
    )
));

我不知道你的“filePaths”属性是从哪里得到的。

【讨论】:

  • 感谢您的回复....您能否建议 .xls 文件的 mimetype 在给定代码中使用,因为我已尝试使用 'application/vnd.ms-excel' 但它不起作用如果我使用'image/png'(这绝对是错误的),我会附加文件?
  • cake 不是黑盒 ;) 查看代码,您应该能够弄清楚 cake 内部使用的是什么:github.com/cakephp/cakephp/blob/master/lib/Cake/Network/… - 所以要么让 cake 弄清楚,要么手动将其设置为 application/vnd.ms-excel那么。
猜你喜欢
  • 1970-01-01
  • 2020-01-10
  • 2012-05-17
  • 1970-01-01
  • 1970-01-01
  • 2011-05-08
  • 2019-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多