0

我正在尝试通过控制台/cron 发送带有 CakePHP 1.3 电子邮件组件的电子邮件。电子邮件被发送和接收,但没有附件。

通过表单完成后,电子邮件将与附件一起成功发送。我尝试添加
$this->Email->filePaths
(来自如何在 CakePHP 2.0 中发送带有附件的电子邮件?
但附件仍未发送。

我的代码如下:

$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']);
}

所以,基本上我的问题是,当我通过控制台/cron 运行 shell 脚本时,如何获取带有附件的电子邮件。

先感谢您。

4

1 回答 1

0

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

$attachedFilePath = WWW_ROOT . 'files' . DS .  'email_attachments';
于 2012-06-11T14:07:54.250 回答