Friday 15 February 2013

php - Postmark - Not able to attach PDF and Image from saved location path in Symfony2 -



php - Postmark - Not able to attach PDF and Image from saved location path in Symfony2 -

i saving image , pdf file uploaded user in 1 of local path. , want attach pdf , image file when mailing[mailing - using postmark api]. not getting attached.

the next code using -

//location file gets uploaded $targetpath = $this->container->getparameter('upload_dir').'/exibition/'.$filename; $imagepath = $this->container->getparameter('upload_dir').'/sk_booth_b17.jpg'; $message = $this->get('postmark.message'); $message->addto($custemail); $message->addcc($useremail); $message->setsubject('my subject goes here'); $message->sethtmlmessage($message_body); $message->addattachment($targetpath); $message->addattachment($imagepath); $result = $message->send(); if($result){ // }else{ // }

i have done configurations correctly. able send plain text mail service without attachments.

when tried attach pdf or image getting next error -

catchable fatal error: argument 1 passed mz\postmarkbundle\postmark\message::addattachment() must instance of symfony\component\httpfoundation\file\file, string given, called in c:\wamp\www\skerp4\src\skerp\salesbundle\controller\exhibitioncustomercontroller.php on line 558 , defined in c:\wamp\www\skerp4\vendor\mlpz\postmark-bundle\mz\postmarkbundle\postmark\message.php line 254

how attach locally saved pdf or images.where going wrong. how implement attachments. help appriciated.

assuming attachments under 10 mb limit, , assuming this library referring to, not using addattachment method correctly accepts symfony file object.

the readme under repo states example:

$message = $this->get('postmark.message'); $message->addto('test@gmail.com', 'test test'); $message->setsubject('subject'); $message->sethtmlmessage('<b>email body</b>'); $message->addattachment(new symfony\component\httpfoundation\file\file(__file__)); $response = $message->send(); $message->addto('test2@gmail.com', 'test2 test'); $message->setsubject('subject2'); $message->sethtmlmessage('<b>email body</b>'); $message->addattachment(new symfony\component\httpfoundation\file\file(__file__), 'usethisfilename.php', 'text/plain'); $response = $message->send();

the build of symfony\component\httpfoundation\file\file accepts scheme path file, , generates right object accordingly, under inference, need write code in next manner:

//location file gets uploaded $targetpath = $this->container->getparameter('upload_dir').'/exibition/'.$filename; $imagepath = $this->container->getparameter('upload_dir').'/sk_booth_b17.jpg'; $message = $this->get('postmark.message'); $message->addto($custemail); $message->addcc($useremail); $message->setsubject('my subject goes here'); $message->sethtmlmessage($message_body); $message->addattachment(new symfony\component\httpfoundation\file\file($targetpath), $filename, 'application/pdf'); $message->addattachment(new symfony\component\httpfoundation\file\file($imagepath), 'sk_booth_b17.jpg', 'image/jpeg'); $result = $message->send();

php email symfony2 email-attachments postmark

No comments:

Post a Comment