在cakephp文件的真实路径中发送带附件的电子邮件

时间:2016-04-06 03:08:15

标签: php email cakephp

我正在尝试使用cake php发送电子邮件,这里是代码

 <table class="section-table">
          <tbody>
            <tr><td class="section-topic">Testing</td></tr>
            <tr data-ng-repeat="subtopic in main.subtopics">
              <td data-ng-click="subtopic.isCollapsed = !subtopic.isCollapsed" class="section-subtopic">{{subtopic.label}}
                <div uib-collapse="subtopic.isCollapsed" expanded="main.showContent(subtopic.id)">
              <div data-ng-repeat="content in main.contents"  class="topic-content">
              <div data-ng-bind="content.content"></div>
            </div>
          </div>
              </td>
            </tr>
          </tbody>
        </table>

但它似乎只是添加了一个附件。我能以任何方式附加多个文件吗?

2 个答案:

答案 0 :(得分:0)

attachments()方法允许您添加图像路径数组。像这样更改你的源代码

    $data =  "RSIMT7210;RSIMT7220";
    $email = new CakeEmail();
    $var = ROOT;
    $var = str_replace("api", "", $var);

    $attachments = array();

    $myArray = explode(';', $data);
    foreach($myArray as $sku)
    {                    
        $result = $this->Ring->find('first', array('conditions'=>array('sku'=>$sku)));
        $ring = $result['Ring'];

        $ringItems = explode(' ', $ring['name']);            
        $styleNumber = $ringItems[0];

        $mAttach = $var . "rings/" . "$styleNumber/image/white.jpg"; 
        $attachments[] =  $mAttach;                          
    }
    $email->attachments($attachments); 

答案 1 :(得分:0)

好的主要问题是所有附件都有相同的名称。我必须使用不同的名称才能使其工作。现在我正在使用这个

$attachments[$styleNumber . ".jpg"] = array(
                                            'file' => $mAttach,
                                            'mimetype' => 'image/png',
                                            'contentId' => $styleNumber
                                        );