Add Attachments To Send Mails


I am using YiiMail extension for sending mails.

How can I add attachments to send mails?

refer its docs or use YiiMailer it uses phpmailer and they provide good api using it

I recommend looking into SwiftMailer.

I have the following code and it doesnt seem to work–

I dont know what does that "tempName" would mean here.


        $message = new YiiMailMessage;


        $message->subject = $_POST['ContactForm']['subject'];


        $uploadedFile = CUploadedFile::getInstanceByName('filename'); // get the CUploadedFile

        $uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'

        $swiftAttachment = Swift_Attachment::fromPath($uploadedFile); // create a Swift Attachment

        $this->email->attach($swiftAttachment); // now attach the correct type



        $message->from = "";//Yii::app()->params['adminEmail'];

        if(Yii::app()->mail->send($message) )


            echo 'mail sent';



            echo 'error while sending email';