zend-framework – Zend Mail 2.0附件

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了zend-framework – Zend Mail 2.0附件脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都可以提供一些关于如何向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 Zend\Mail\Message 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 – Zend\Mail

脚本宝典总结

以上是脚本宝典为你收集整理的zend-framework – Zend Mail 2.0附件全部内容,希望文章能够帮你解决zend-framework – Zend Mail 2.0附件所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。