禅道发送邮件功能非常方便。但是目前不支持邮件发送附件的功能。
有人求求助此功能时
春哥回答“现在没有这个功能。暂时也没有计划增加,应该还是到系统中查看详细的内容。”
http://www.zentao.net/thread/82828.html
查看了一下php发邮件。
发现实现发附件很简单。只需加一句话。
禅道调用mail->send()函数发送邮件。
我们把mail->send()拷贝一份重新写个函数吧。其实只加了一句话。
/** * Send Email With Mail Attachment * * @param array $toList * @param string $subject * @param string $body * @param array $ccList * @param bool $includeMe * @param string $attachmentPath * @param string $attachmentName * @access public * @return void */ public function sendMailWithAttachment($toList, $subject, $body = '', $ccList = '', $includeMe = false, $attachmentPath = '', $attachmentName = '') { if(!$this->config->mail->turnon) return; if(!empty($this->config->mail->async)) return $this->addQueue($toList, $subject, $body, $ccList, $includeMe); ob_start(); $toList = $toList ? explode(',', str_replace(' ', '', $toList)) : array(); $ccList = $ccList ? explode(',', str_replace(' ', '', $ccList)) : array(); /* Process toList and ccList, remove current user from them. If toList is empty, use the first cc as to. */ if($includeMe == false) { $account = isset($this->app->user->account) ? $this->app->user->account : ''; foreach($toList as $key => $to) if(trim($to) == $account or !trim($to)) unset($toList[$key]); foreach($ccList as $key => $cc) if(trim($cc) == $account or !trim($cc)) unset($ccList[$key]); } /* Remove deleted users. */ $users = $this->loadModel('user')->getPairs('nodeleted'); foreach($toList as $key => $to) if(!isset($users[trim($to)])) unset($toList[$key]); foreach($ccList as $key => $cc) if(!isset($users[trim($cc)])) unset($ccList[$key]); if(!$toList and !$ccList) return; if(!$toList and $ccList) $toList = array(array_shift($ccList)); $toList = join(',', $toList); $ccList = join(',', $ccList); /* Get realname and email of users. */ $this->loadModel('user'); $emails = $this->user->getRealNameAndEmails(str_replace(' ', '', $toList . ',' . $ccList)); $this->clear(); /* Replace full webPath image for mail. */ if(strpos($body, 'src="data/upload')) $body = preg_replace('/<img (.*)src="data/upload/', '<img $1 src="http://' . $this->server->http_host . $this->config->webRoot . 'data/upload', $body); try { $this->mta->setFrom($this->config->mail->fromAddress, $this->convertCharset($this->config->mail->fromName)); $this->setSubject($this->convertCharset($subject)); $this->setTO($toList, $emails); $this->setCC($ccList, $emails); $this->setBody($this->convertCharset($body)); if(!empty($attachmentPath) && !empty($attachmentName)) $this->mta->AddAttachment($attachmentPath,$attachmentName); $this->setErrorLang(); $this->mta->send(); } catch (phpmailerException $e) { $this->errors[] = nl2br(trim(strip_tags($e->errorMessage()))) . '<br />' . ob_get_contents(); } catch (Exception $e) { $this->errors[] = trim(strip_tags($e->getMessage())); } if($this->config->mail->mta == 'smtp') $this->mta->smtpClose(); /* save errors. */ if($this->isError()) $this->app->saveError('E_MAIL', join(' ', $this->errors), __FILE__, __LINE__, true); $message = ob_get_contents(); ob_clean(); return $message; }
比原来的函数就多了两个参数,一句话
attachmentPath 附件的完整路径(包括文件路径文件名)
attachmentName 添加到邮件后邮件内显示附件的名字(也就是相当于重命名了文件,无路径)
if(!empty($attachmentPath) && !empty($attachmentName)) $this->mta->AddAttachment($attachmentPath,$attachmentName);