[SOLVED]attachment swiftmailer from database

hello all,

im pretty new in using yii, can anyone please tell me how to make attachment from (blob field) in my database so when i send an email using swiftmailer that file from my database can be an attachment of the email. i already succeed in sending email using swiftmailer without attachment. but now i want attach file from database too, i already read how to attach file from specified folder from server but doesnt meet with my case that i want take a file from database…


$message = new YiiMailMessage();


$message->setFrom(array('crazysasshy@gmail.com'=>'staff support Bee'));




$message->attach(Swift_Attachment::fromPath( /*What to write here?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />*/);

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


save the file to a temporary location, then after sent delete the temporary file

thanks Gustavo,

i already tried that and i can make the attachments, huraaayyy,

but… somehow i cant delete the temporary file…

here is my code:


		$filename = $attachment->attfilename; //temporary file name

		$Content = $attachment->attdata;

		$handle = fopen($filename, 'x+');

		fwrite($handle, $Content);


                $message->attach(Swift_Attachment::fromPath($filename)); //this is succeed

	        $delete ="C:/xampp/htdocs/yii/Support Suite/".$filename."";   //seems to be fail



i try "$delete = $filename;"

doesnt work either, maybe u know why? Thanks :D

the file is in use, you must delete after you send the email

$filename = $attachment->attfilename; //temporary file name


$message->attach(Swift_Attachment::fromPath($filename)); //this is succeed

//after send


thanks for ur reply :)

yeah u re right,

but i got another problem, permission denied, i search google and try everything such chmod etc, but still not working, im using windows 7, do u know why?

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



							$a ="C:/xampp/htdocs/yii/Support Suite/".$filename."";



thanks a lot :)

I wouldn’t know

apache must have permission to write to the file

try first change its owner to the apache user

also, looks like you are not deleting the right file

you use $filename for attachment, to file_put_contents, to chmod

and then you delete "C:/xampp/htdocs/yii/Support Suite/".$filename.""

be sure you are deleting the correct file

thanks again for ur reply :)

im sure im deleting the correct file,

i guess after sending a message the file is not closed,

here if i comment the "sending code", deleting the file is successfull without any permission denied

	$numsent = Yii::app()->mail->send($message);//the sending code i comment



	        	$a =$filename;



yeah im still working on it :)

i end up to delete the file not after i send an email, but after some period of time using try catch, well maybe a cron job is a gud option, but because i still working in localhost, i will try it later

problem solved…:D

Hi, I have to decide what extension to use for sending emails with PDF attachments, what do you recommend?