无法在邮件中发送附件 - Yii

时间:2014-03-29 05:30:07

标签: php yii

这是我在邮件中附加文档的代码。我正在使用YiiMail扩展。

控制器 -

public function actionContact()
{
    $model=new ContactForm;
    if(isset($_POST['ContactForm']))
    {
        $model->attributes=$_POST['ContactForm'];
        $message = new YiiMailMessage;
        $message->Body=$_POST['ContactForm']['body'];
        $message->subject = $_POST['ContactForm']['subject'];
        $message->addTo($_POST['ContactForm']['email']);
        $message->from = "from@gmail.com";

        //Adding attachment
        //$uploadedFile = CUploadedFile::getInstanceByName('file'); // get the CUploadedFile
       // $uploadedFileName = $uploadedFile->tempName;

        $model->file=CUploadedFile::getInstance($model,'file');
        $uploadedFileName =$model->file->tempName; // will be something like 'myfile.jpg'
        $swiftAttachment = Swift_Attachment::fromPath($uploadedFileName); // create a Swift Attachment from the temporary file
        $message->attach($swiftAttachment); // now attach the correct type

         Yii::app()->mail->send($message);
    }

    $this->render('contact',array('model'=>$model));
}

我可以发送带附件的邮件,但邮件中找不到附件。它说“没有预览可用”。我在哪里错了?

0 个答案:

没有答案