0

i am using zend mail for mailing purpose in my web site. In this mail i add a image attachment function. The mail sent successfully but i can't view image from my inbox. They said that unsupported file format.

This is my code

       $attach_path = image path

   $transport   = new Zend_Mail_Transport_Smtp('sanple', $config);
  $mail         = new Zend_Mail('UTF-8');
  $mail->setBodyHtml($message);
  $fileContents = file_get_contents($attach_path);

    $at = $mail->createAttachment($fileContents);
    $at->type        = 'image/jpeg';
    $at->filename    = 'test.jpg';

$mail->setFrom('customersupport@testing.com', 'customersupport@testing.com');
$mail->addTo('customersupport@testing.com','customersupport@testing.com');

$mail->setSubject($subject);
$mail->send($transport);

if anything wrong in this.please help me

Thanks in advance.

deepu sankar
  • 4,335
  • 3
  • 26
  • 37

2 Answers2

1

Try the following code,

$content = file_get_contents($attach_path);                       
$attachment = new Zend_Mime_Part($content);
$attachment->type = 'image/jpeg';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = 'test.jpeg';
$mail->addAttachment($attachment); 

OFFICIAL DOC

Ronak K
  • 1,567
  • 13
  • 23
  • see my [Earlier Answer](http://stackoverflow.com/questions/19816637/adding-an-pdf-attachment-when-using-zend-mail) in this regard, – Ronak K Feb 04 '14 at 10:00
0

If you look at the docs you see they set the disposition and encoding.

http://framework.zend.com/manual/1.12/en/zend.mail.attachments.html

$at = $mail->createAttachment(file_get_contents($attach_path));
$at->type        = 'image/jpeg';
$at->disposition = Zend_Mime::DISPOSITION_INLINE; // or Zend_Mime::DISPOSITION_ATTACHMENT
$at->encoding    = Zend_Mime::ENCODING_BASE64;
$at->filename    = 'test.jpg';
bitWorking
  • 12,485
  • 1
  • 32
  • 38