views:

122

answers:

2

Why am I receiving same attachment twice with this code!?

 $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();
A: 

It looks like it is because you are using createAttachment and addAttachment. Please make sure you are following the documentation for Zend_Mail on how to do this.

For example:

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

Well problem actuality is in this line $mailer->addAttachment($attachment); Without it, it will work. I didn't know that because it seams to bi logical to call addAttachment method to me :P

Splendid