如何在CakePHP 2.0中发送带有附件的电子邮件? [英] How do I send an email with an attachment in CakePHP 2.0?

查看:104
本文介绍了如何在CakePHP 2.0中发送带有附件的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用CakePHP 2.0发送附件的电子邮件。

I'm trying to send an email with an attachment using CakePHP 2.0.

该文件由用户通过表单提交。

The file is submitted by the user via a form.

到目前为止我有:

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();
$email->attachments = array($this->data['Opportunity']['resume_file']['tmp_name']);
$email->viewVars(array('name' => $this->data['Opportunity']['name']));
$email->template('application')
    ->emailFormat('html')
    ->to(TEST_CONTACT)
    ->from(EMAIL_CONTACT)
    ->subject('New application received')
    ->send();

电子邮件发送,看起来不错,但没有附件。

The email sends and looks fine, but there is no attachment.

我做错了什么?

感谢任何帮助。

推荐答案

由于某种原因,CakePHP不会做附件,除非你先声明
filePaths。

For some reason CakePHP won't do attachments unless you state the filePaths first.

我有同样的问题,我没有设法找到许多回答
这个问题。我花了一段时间来解决问题,澄清,
我得到它工作

I have the same problem and I did not manage to find many answer to this question. It took me a while to solve the problem, to clarify, I got it working by

$this->Email->filePaths  = array('/home/username/');
       $this->Email->attachments =array('article_button.png');
$this->Email->to      = 'em...@email.co.uk';
    $this->Email->subject = 'Something';
    $this->Email->replyTo = $client['Client']['email'];
    $this->Email->from    = $client['Client']['email'];
    $this->Email->sendAs  = 'html';

    if($this->Email->send('Testing', null, null)){
      die('Email Sent!');
    }else{
      die('Failed to send email');
    } 

http://groups.google.com/group/cake-php/browse_thread/thread/93a9c9467733fe38?pli=1

这篇关于如何在CakePHP 2.0中发送带有附件的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆