deepu sankar
deepu sankar

Reputation: 4465

zend mail attachment is not working

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('[email protected]', '[email protected]');
$mail->addTo('[email protected]','[email protected]');

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

if anything wrong in this.please help me

Thanks in advance.

Upvotes: 0

Views: 1453

Answers (2)

Ronak K
Ronak K

Reputation: 1567

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

Upvotes: 1

bitWorking
bitWorking

Reputation: 12675

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';

Upvotes: 0

Related Questions