Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework ZF邮件附件问题_Zend Framework_Email - Fatal编程技术网

Zend framework ZF邮件附件问题

Zend framework ZF邮件附件问题,zend-framework,email,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->createA

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

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

看起来这是因为您正在使用
createAttachment
addAttachment
。请确保您遵守了有关如何执行此操作的说明

例如:

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

问题就在这方面

$mailer->addAttachment($attachment);

没有它,它就会工作。我不知道这一点,因为对我来说调用addAttachment方法似乎是合乎逻辑的:P

这是一个适合我的方法,试图发送一份简历,在zend中有attachmnet

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

你的回答对我帮助很大