【发布时间】:2012-06-11 22:07:54
【问题描述】:
我正在尝试通过控制台/cron 使用 CakePHP 1.3 电子邮件组件发送电子邮件。 电子邮件已发送和接收,但没有附件。
通过表单完成后,电子邮件将与附件一起成功发送。
我已尝试添加
$this->Email->filePaths,
(来自How do I send an email with an attachment in 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 脚本时,如何获取带有附件的电子邮件。
提前谢谢你。
【问题讨论】:
-
如果您正在通过控制台排队和发送电子邮件,您可能会对这个插件感兴趣。它可能会减少你的一些工作。 github.com/jeremyharris/queue_email
-
回到 cron 作业后,我会看看你的插件。完成后应在此处更新结果。感谢您的宝贵时间。
标签: cakephp console email-attachments