CakePHP:通过控制台发送带有附件的电子邮件

CakePHP:通过控制台发送带有附件的电子邮件,cakephp,console,email-attachments,Cakephp,Console,Email Attachments,我正试图通过console/cron使用CakePHP 1.3电子邮件组件发送电子邮件。 发送和接收电子邮件,但没有附件 通过表单完成后,电子邮件将与附件一起成功发送。 我已尝试添加 $this->Email->filepath, (来自) 但是附件仍然没有被发送 我的代码如下: $email =& new EmailComponent(); $email->reset(); $email->initialize($controller); $email-&g

我正试图通过console/cron使用CakePHP 1.3电子邮件组件发送电子邮件。 发送和接收电子邮件,但没有附件

通过表单完成后,电子邮件将与附件一起成功发送。 我已尝试添加
$this->Email->filepath
(来自)
但是附件仍然没有被发送

我的代码如下:

$email =& new EmailComponent();
$email->reset();
$email->initialize($controller);        
$email->delivery = $emailConfigurations['delivery'];        
$email->from = $emailConfigurations['from'];
$email->replyTo = $emailConfigurations['replyTo'];
$email->return = $emailConfigurations['return'];
$email->template = 'default';
$email->sendAs = $emailConfigurations['sendAs'];

if (strcasecmp($email->delivery, 'smtp') == 0) {
    $email->smtpOptions = array(
        'timeout' => $emailConfigurations['smtpTimeout'],
        'port' => $emailConfigurations['smtpPort'],
        'host' => $emailConfigurations['smtpHost'],
        'username' => $emailConfigurations['smtpUsername'],
        'password' => $emailConfigurations['smtpPassword']
    );
}

$email->to = $newEmail['mail_to'];
$email->subject = $newEmail['message_title'];

if ($newEmail['attachment_name'] && $newEmail['attachment_tmp']) {
    $attachedFilePath = WWW_ROOT . 'files' . DS .  'email_attachments' . DS ;
    $attachedFile = $newEmail['attachment_tmp'];

    $this->Email->filePaths  = array($attachedFilePath); 
    $this->Email->attachments = array($attachedFile);
}

if($email->send($newEmail['message'])){
    $this->out(date('Y-m-d H:i:s')." Email sent : ".$newEmail['id']);
} else {
    $this->out(date('Y-m-d H:i:s')." Email not sent : ".$newEmail['id']);
}
所以,基本上我的问题是,当我通过console/cron运行shell脚本时,如何获得带附件发送的电子邮件


提前谢谢。

从路径列表中删除尾随的
DS
,因为Cake不会修剪它:

$attachedFilePath = WWW_ROOT . 'files' . DS .  'email_attachments';

如果您正在排队并通过控制台发送电子邮件,您可能会对该插件感兴趣。这可能会减少你的一些工作。一旦我回到cron工作,我会看看你的插件。完成后,应在此处更新结果。谢谢您的时间。您是否尝试过使用完整附件路径而不是使用
电子邮件->文件路径
var?像
$this->Email->attachments=array(WWW_ROOT.'files'.DS.'Email\u attachments'.DS.$newEmail['attachment\u tmp'])
。另外,使用
文件\u exists()
验证文件是否存在于该位置。是的,我有&文件确实存在。但电子邮件中仍然没有附件。期待着尝试你的插件&希望这能解决问题(希望能阐明我不工作的真正原因)。嗨,项目已经取消了&我已经离开了。但是如果有人能回答这个问题,我会很感激你的。谢谢