Adding an PDF attachment when using Zend_Mail

后端 未结 1 1125
一向
一向 2020-12-30 15:47

What is the right way to add an attachment when using Zend_Mail? I keep getting the following error when I try to open the attached pdf in the sent mail: \"Cannot extract th

相关标签:
1条回答
  • 2020-12-30 16:09

    Here is the right way to do it,

    $mail = new Zend_Mail();
    $mail->setBodyHtml("description");
    $mail->setFrom('id', 'name');
    $mail->addTo(email, name);
    $mail->setSubject(subject);
    
    $content = file_get_contents("path to pdf file"); // e.g. ("attachment/abc.pdf")
    $attachment = new Zend_Mime_Part($content);
    $attachment->type = 'application/pdf';
    $attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
    $attachment->encoding = Zend_Mime::ENCODING_BASE64;
    $attachment->filename = 'filename.pdf'; // name of file
    
    $mail->addAttachment($attachment);                  
    
    $mail->send(); 
    
    0 讨论(0)
提交回复
热议问题