Para agregar un archivo adjunto, solo tiene que crear una nueva parte MIME y agregarla al mensaje.
Ejemplo:
// 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
Aquí es algún tipo de documentación útil sobre el tema: ZF2 - Zend\Mail
todavía no he verificado, pero que parece ser una solución de trabajo porque yo también considero que debe haber algún acuerdo con Mime Gracias. –
No tengo idea de por qué se tomó la decisión de eliminar el método 'addAttachment' de la clase Mail, que en ZF1 simplemente crearía una nueva parte mime para usted y la agregaría al mensaje, ahora es un poco más explícita. – drew010
Creo que vale la pena mencionar aquí que el nuevo MimePart y MimeMessage en ZF 2 están ahora en el Zend \ Mime \ Part y Zend \ Mime \ Message, por lo que tendrá que usar sus espacios de nombres en consecuencia. –