加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

zend-framework – Zend Mail 2.0附件

发布时间:2020-05-25 09:15:45 所属栏目:PHP 来源:互联网
导读:任何人都可以提供一些关于如何向ZF2邮件组件添加附件的示例吗? 我喜欢: $message = new Message;$message-setEncoding(utf-8);$message-setTo($email);$message-setReplyTo($replyTo);$message-setFrom($from);$message-setSubject($su

任何人都可以提供一些关于如何向ZF2邮件组件添加附件的示例吗?

我喜欢:

$message = new Message;
$message->setEncoding('utf-8');
$message->setTo($email);
$message->setReplyTo($replyTo);
$message->setFrom($from);
$message->setSubject($subject);
$message->setBody($body);

但在需要添加附件时卡住了.
谢谢.

要添加附件,您只需创建一个新的MIME部分并将其添加到消息中.

例:

// create a new ZendMailMessage object
$message  = new Message;

// create a MimeMessage object that will hold the mail body and any attachments
$bodyPart = new MimeMessage;

// create the attachment
$attachment = new MimePart(fopen($pathToAttachment));
// or
$attachment = new MimePart($attachmentContent);

// set attachment content type
$attachment->type = 'image/png';

// create the mime part for the message body
// you can add one for text and one for html if needed
$bodyMessage = new MimePart($body);
$bodyMessage->type = 'text/html';

// add the message body and attachment(s) to the MimeMessage
$bodyPart->setParts(array($bodyMessage,$attachment));

$message->setEncoding('utf-8')
        ->setTo($email)
        ->setReplyTo($replyTo)
        ->setFrom($from)
        ->setSubject($subject)
        ->setBody($bodyPart);  // set the body of the Mail to the MimeMessage with the mail content and attachment

以下是有关该主题的一些有用文档:ZF2 – ZendMail

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读