【问题标题】:zend mail attachment is not workingZend 邮件附件不起作用
【发布时间】:2014-02-28 04:00:09
【问题描述】:

我在我的网站中使用 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);

如果这里有什么问题,请帮助我

提前致谢。

【问题讨论】:

  • 您的文件是 .gif 图片,但 mime 类型是 jpeg,请尝试使用 $at->type = "image/gif"
  • 那是我的错误。当我从另一个部分复制时,类型发生了变化。但这对我没有帮助。感谢回复

标签: php zend-framework zend-mail


【解决方案1】:

试试下面的代码,

$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

【讨论】:

【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    相关资源
    最近更新 更多