Magento使用带有附件的Zendu邮件轻松发送电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Magento使用带有附件的Zendu邮件轻松发送电子邮件相关的知识,希望对你有一定的参考价值。

send mail with attached file
examples: http://framework.zend.com/svn/framework/standard/trunk/tests/Zend/Mail/MailTest.php
  1. in magento there is no available methods for attach file. once we do it in magento by adding a following code
  2. in mage/core/model/email/template.php at the end of file.
  3.  
  4. public function addAttachment(Zend_Pdf $pdf){
  5. $file = $pdf->render();
  6. $attachment = $this->getMail()->createAttachment($file);
  7. $attachment->type = 'application/pdf';
  8. $attachment->filename = 'yourfile.pdf';
  9. }
  10.  
  11. but i prefer to use Zend_Mail to send mail with attached file.
  12. for this u need to do following.
  13.  
  14. try{
  15. $mail = new Zend_Mail();
  16. $mail->setFrom("fromemail","fromname");
  17. $mail->addTo("toemail","toname");
  18. $mail->setSubject("subject");
  19. $mail->setBodyhtml(" body text"); // here u also use setBodyText options.
  20.  
  21. // this is for to set the file format
  22. $at = new Zend_Mime_Part($content);
  23.  
  24. $at->type = 'application/csv'; // if u have PDF then it would like -> 'application/pdf'
  25. $at->disposition = Zend_Mime::DISPOSITION_INLINE;
  26. $at->encoding = Zend_Mime::ENCODING_8BIT;
  27. $at->filename = $filename;
  28. $mail->addAttachment($at);
  29. $mail->send();
  30.  
  31. }catch(Exception $e)
  32. {
  33. echo $e->getMassage();
  34.  
  35. }

以上是关于Magento使用带有附件的Zendu邮件轻松发送电子邮件的主要内容,如果未能解决你的问题,请参考以下文章

使用 javamail API 发送带有附件的电子邮件

Magento交易邮件常见问题

PHP发送带有文件附件的电子邮件 - 电子邮件根本不发送

使用python发送带有(docx)附件的邮件

如何使用 SmtpClient.SendAsync 发送带有附件的电子邮件?

使用 smtp 发送带有多个附件的电子邮件