邮件附件无效

时间:2014-02-04 09:13:08

标签: php zend-framework zend-mail

我在我的网站上使用zend邮件进行邮寄。在这封邮件中,我添加了一个图像附件功能。邮件已成功发送但我无法从收件箱中查看图像。他们说不支持的文件格式。

这是我的代码

       $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);

如果有任何错误,请帮助我

提前致谢。

2 个答案:

答案 0 :(得分:0)

如果您查看文档,则会看到他们设置了处置和编码。

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

答案 1 :(得分:0)

请尝试以下代码

$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