用zend发送简易邮件带附件(M1&M2通用)

2.98K 浏览开发笔记

用zend发送简易邮件带附件(M1&M2通用)

<code>$to = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__">[email&#160;protected]</a>'; $subject = 'test'; $message = 'test'; $mail = new Zend_Mail(); $mail->setFrom('<a href="/cdn-cgi/l/email-protection" class="__cf_email__">[email&#160;protected]</a>', 'Me') ->addTo($to) ->setSubject($subject) ->setBodyText($message); $file = BP.'/var/invoice2017-02-28_03-08-53.pdf'; $at = new Zend_Mime_Part(file_get_contents($file)); $at->filename = basename($file); $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $at->encoding = Zend_Mime::ENCODING_8BIT; $mail->addAttachment($at); $file = BP.'/LICENSE.txt'; $at = new Zend_Mime_Part(file_get_contents($file)); $at->filename = basename($file); $at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $at->encoding = Zend_Mime::ENCODING_8BIT; $mail->addAttachment($at); $mail->send();</code>
0