Splendid
Splendid

Reputation: 1357

ZF Mail problem with attachments

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(); 

Upvotes: 0

Views: 1572

Answers (3)

Splendid
Splendid

Reputation: 1357

Well problem actuality is in this line

$mailer->addAttachment($attachment);

Without it, it will work. I didn't know that because it seems logical to call addAttachment method to me :P

Upvotes: 1

Rinzler
Rinzler

Reputation: 2116

this one is working for me trying to send a resume has attachmnet in 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 () );
                }

Upvotes: 0

Kekoa
Kekoa

Reputation: 28250

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);

Upvotes: 1

Related Questions