带附件的ZF Mail问题

时间:2009-06-05 21:21:33

标签: zend-framework email

为什么我使用此代码两次收到相同的附件?

 $mailer = new Zend_Mail('UTF-8');
 $mailer->setFrom($group_email,$group_name);
 $mailer->setSubject($title);
 $mailer->setBodyHtml($full);

 $fileContents = file_get_contents('test.jpg');
 $attachment = $mailer->createAttachment($fileContents);
 $attachment->filename = "test.jpg";
 $mailer->addAttachment($attachment);

        //get all subscribers
        $i=0;
        foreach ($subscribers->getGroupUsers($group_id) as $sub){
            if ($i==0){
                $mailer->addTo($sub->email);
            }
            else {
                $mailer->addBcc($sub->email);
            }
            $i++;
        }

 $mailer->send(); 

3 个答案:

答案 0 :(得分:1)

看起来是因为您使用的是createAttachmentaddAttachment。请确保您关注documentation for Zend_Mail如何执行此操作。

例如:

$mail = new Zend_Mail();
// build message...
$mail->createAttachment($someBinaryString);
$mail->createAttachment($myImage,
                        'image/gif',
                        Zend_Mime::DISPOSITION_INLINE,
                        Zend_Mime::ENCODING_8BIT);

答案 1 :(得分:1)

问题的实际情况就在这一行

$mailer->addAttachment($attachment);
没有它,它会起作用。我不知道,因为向我调用addAttachment方法似乎合乎逻辑:P

答案 2 :(得分:0)

这个正在为我努力发送简历作为附件在zend

                $mail = new Zend_Mail ();
                $mail->setBodyHTML ( stripslashes ($message) );

                // add attachment
                $fileContents = file_get_contents($attachemnet);
                $resume = $mail->createAttachment($fileContents);
                $resume->filename = $EmployeeDeatils['resume'];

                //$mail->createAttachment($attachemnet);
                $mail->setFrom ( $mail_template ['from_email'], $mail_template ['from_caption'] );
                $mail->addTo ( $clientemail, $employee_name );
                $mail->setSubject ($subject );
                try {
                    $mail->send ();
                } catch ( Exception $e ) {
                    $this->_helper->errorlog ( " Send mail to member with activation link : " . $e->getMessage () );
                }