【问题标题】:Zend_mail send duplicate attachmentZend_mail 发送重复的附件
【发布时间】:2015-07-09 16:34:28
【问题描述】:

我正在使用带有zend 框架的phpexcel 库。 我想用 excel 文件附件向用户发送邮件,一切正常,但是带有两个附件的邮件发送是重复的,我不知道为什么。

这是我的函数,用于导出 excel 并将其发送给用户

public function exportandmail($name = NULL) {
        if ($name === NULL) {
            $name = 'excel_' . date('Y_m_d');
        }
        $name = $name.'.xlsx';

        $objWriter = PHPExcel_IOFactory::createWriter($this->_excel, 'Excel2007');
        $objWriter->save("public/uploads/Mailexcel/".$name);

          $message="<table width='90%' align='center' >
                 <tr>
                 <th height='15' style='background-color:#037296;padding:10px;color:#FFFFFF' align='left'>excel</th>
                 </tr>
                     <tr>
                     <td style='padding:10px'><strong>Please find the attachment. </strong> 

                    </td>
                    <tr>
                    <td style='padding:10px'>
                        Thanks,
                    </td>
                    </tr>
                    </table>";

                $mail = new Zend_Mail();
                $mail->setBodyHtml($message);
                $mail->setFrom('sender@gmail.com', 'sender');
                $mail->addTo('user@gmail.com');
                $mail->setSubject('find attachment');

                $fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
                $file = $mail->createAttachment($fileContents);
                $file->filename = "excel.xlsx";
                $mail->addAttachment($file);   
                $mail->send();
        exit;
    }

提前致谢。

【问题讨论】:

    标签: phpexcel zend-mail


    【解决方案1】:

    我得到了解决方案, 在我的代码中,我同时使用了 createAttachment 和 addAttachment,这就是为什么我的邮件发送时带有重复的附件。 删除 addAttachment 并正常工作。

    $fileContents = file_get_contents("public/uploads/Mailexcel/".$name);
                    $file = $mail->createAttachment($fileContents);
                    $file->filename = "excel.xlsx";
                    $mail->addAttachment($file);   // Remove this 
                    $mail->send();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-11
      • 2013-07-12
      • 2011-11-20
      • 1970-01-01
      • 2012-10-23
      • 1970-01-01
      • 2011-01-24
      • 2010-11-11
      相关资源
      最近更新 更多