php - How could I achieve sending emails in Symfony2/SwiftMailer service with the following criteria? -
i'm trying achieve task killing me! can ugly message without success! below 2 simple classes....which pretend through form in app send emails selecting persons in db according 2 criterias inserted through metioned form(products , city).
what should possible reasons of error:
exception occurred while executing 'select u0_.email email0 userinfo u0_ u0_.city = ? , u0_.products = ? limit 1' params [{}, {}]: catchable fatal error: object of class quotera\emailbundle\entity\email not converted string public function emailaction(request $request){ $email = new email(); $form = $this->createform(new emailtype()); if ($request->ismethod('post')) { $form->submit($request); if ($form->isvalid()) { $city = $email->setcity($form->get('city')->getdata()); $product =$email->setproduct($form->get('product')->getdata()); $user = $this->getuser(); $email->setowner($user); $email->setname($user); $email->setcity($form->get('city')->getdata()); $email->setproduct($form->get('product')->getdata()); $email->setmessage($form->get('message')->getdata()); $email->setemail("exellent@sometoon.com"); $email->setemailto($this->sendemailstoproviders($city, $product)); $email->settime($form->get('time')->getdata()); $em = $this->getdoctrine()->getmanager(); $em->persist($email); $em->flush(); $message = \swift_message::newinstance() ->setsubject($form->get('product')->getdata()) ->setfrom('exellent@sometoon.com') ->setto($this->sendemailstoproviders($city,$product)) ->setcharset('utf-8') ->setcontenttype('text/html') ->setbody('thank you', 'text/html'); $this->get('mailer')->send($message); $request->getsession()->getflashbag()->add('success', 'your quotation has been sent' ); } } return array( 'form' => $form->createview() ); } public function sendemailstoproviders($city, $product) { $em = $this->getdoctrine ()->getmanager(); $qb = $em->createquerybuilder(); $emails = $qb->select('u')->from('userbundle:userinfo', 'u') ->select('u.email') ->andwhere('u.city = :city') ->setparameter('city', $city) ->andwhere('u.product = :product') ->setparameter('product', $product ) ->setmaxresults(5) ->getquery() ->execute(); if(!$emails){ throw new notfoundhttpexception('sorry, no providers criteria!'); } return $emails; } if var_dump($this->sendemailstoproviders('berlin','butter' )) ; result array (size=5) 0 => array (size=1) 'email' => string 'iancasillasbuffon@gmail.com' (length=27) 1 => array (size=1) 'email' => string 'iancasillasbuffon@gmail.com' (length=27) 2 => array (size=1) 'email' => string 'eddynvg@hotmail.com' (length=19) 3 => array (size=1) 'email' => string 'dolphin23@dolphin.net' (length=21) 4 => array (size=1) 'email' => string 'dolphin@dolphin.org' (length=19) <?php namespace quotera\emailbundle\entity; use doctrine\orm\mapping orm; //use gedmo\mapping\annotation gedmo; use symfony\component\validator\constraints assert; use symfony\component\httpfoundation\file\uploadedfile; use quotera\userbundle\entity\user; /** * email * * @orm\table(name="quottum_email") * @orm\entity(repositoryclass="quotera\emailbundle\repository\emailrepository") * @orm\haslifecyclecallbacks * */ class email { /** * @var integer * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; /** * @orm\manytoone(targetentity="quotera\userbundle\entity\user") * @orm\joincolumn(ondelete="cascade") */ private $owner; /** * @orm\column(type="string", length=255) * @assert\notblank */ private $name; /** * @var integer * * @orm\column(name="tracking", type="integer") */ private $tracking; /** * @orm\column(type="string") */ private $ip; /** * @var string * * @orm\column(name="quotation_sender", type="string", length=255) */ private $quotationsender; /** * @var string * * @orm\column(name="product", type="string", length=255) */ private $product; /** * @var string * * @orm\column(name="city", type="string", length=255) */ private $city; /** * @var string * * @orm\column(name="category", type="string", length=255) */ private $category; /** * @var string * * @orm\column(name="message", type="string", length=255) */ private $message; /** * @var integer * * @orm\column(name="message_id", type="integer") */ private $messageid; /** * @var integer * * @orm\column(name="quantity", type="integer") */ private $quantity; /** * @var string * * @orm\column(name="qty_type", type="string", length=255) */ private $qtytype; /** * @var string * * @orm\column(name="username", type="string", length=255) */ private $username; private $temp; /** * @var string * * @orm\column(name="image", type="string", length=255, nullable=true) */ private $image; /** * @var string * * @orm\column(name="email", type="string", length=255) */ private $email; /** * @var string * * @orm\column(name="email_to", type="string", length=255) */ private $emailto; /** * * @var string * @orm\column(name="captcha", type="string", nullable=false) */ private $captcha; /** * @assert\file(maxsize="6000000") */ private $file; /** * @var \datetime * * @orm\column(name="time", type="date", nullable=true) */ private $time; /** * id * * @return integer */ public function getid() { return $this->id; } /** * @param user $owner */ public function setowner(user $owner) { $this->owner = $owner; } /** * @return user */ public function getowner() { return $this->owner; } /** * @param mixed $name */ public function setname($name) { $this->name = $name; } /** * @return mixed */ public function getname() { return $this->name; } /** * set tracking * * @param integer $tracking * @return email */ public function settracking($tracking) { $this->tracking = $tracking; return $this; } /** * tracking * * @return integer */ public function gettracking() { return $this->tracking; } /** * set quotationsender * * @param string $quotationsender * @return email */ public function setquotationsender($quotationsender) { $this->quotationsender = $quotationsender; return $this; } /** * quotationsender * * @return string */ public function getquotationsender() { return $this->quotationsender; } /** * set product * * @param string $product * @return email */ public function setproduct($product) { $this->product = $product; return $this; } /** * product * * @return string */ public function getproduct() { return $this->product; } /** * set city * * @param string $city * @return email */ public function setcity($city) { $this->city = $city; return $this; } /** * city * * @return string */ public function getcity() { return $this->city; } /** * set category * * @param string $category * @return email */ public function setcategory($category) { $this->category = $category; return $this; } /** * category * * @return string */ public function getcategory() { return $this->category; } /** * set message * * @param string $message * @return email */ public function setmessage($message) { $this->message = $message; return $this; } /** * message * * @return string */ public function getmessage() { return $this->message; } /** * set messageid * * @param integer $messageid * @return email */ public function setmessageid($messageid) { $this->messageid = $messageid; return $this; } /** * messageid * * @return integer */ public function getmessageid() { return $this->messageid; } /** * set quantity * * @param integer $quantity * @return email */ public function setquantity($quantity) { $this->quantity = $quantity; return $this; } /** * quantity * * @return integer */ public function getquantity() { return $this->quantity; } /** * set qtytype * * @param string $qtytype * @return email */ public function setqtytype($qtytype) { $this->qtytype = $qtytype; return $this; } /** * qtytype * * @return string */ public function getqtytype() { return $this->qtytype; } /** * set username * * @param string $username * @return email */ public function setusername($username) { $this->username = $username; return $this; } /** * username * * @return string */ public function getusername() { return $this->username; } /** * set image * * @param string $image * @return email */ public function setimage($image) { $this->image = $image; return $this; } /** * image * * @return string */ public function getimage() { return $this->image; } /** * set email * * @param string $email * @return email */ public function setemail($email) { $this->email = $email; return $this; } /** * email * * @return string */ public function getemail() { return $this->email; } /** * set emailto * * @param string $emailto * @return email */ public function setemailto($emailto) { $this->emailto = $emailto; return $this; } /** * emailto * * @return string */ public function getemailto() { return $this->emailto; } /** * @param mixed $ip */ public function setip($ip) { $this->ip = $ip; } /** * @return mixed */ public function getip() { return $this->ip; } /** * @param mixed $captcha */ public function setcaptcha($captcha) { $this->captcha = $captcha; } /** * @return mixed */ public function getcaptcha() { return $this->captcha; } /** * @orm\column(type="string", length=255, nullable=true) */ private $path; public function getwebpath() { return null === $this->path ? null : $this->getuploaddir().'/'.$this->path; } protected function getuploadrootdir() { // absolute directory path uploaded // documents should saved return __dir__.'/../../../../web/'.$this->getuploaddir(); } protected function getuploaddir() { // rid of __dir__ doesn't screw // when displaying uploaded doc/image in view. return 'images/products'; } /** * sets file. * * @param uploadedfile $file public function setfile(uploadedfile $file = null) { $this->file = $file; // check if have old image path if (isset($this->path)) { // store old name delete after update $this->temp = $this->path; $this->path = null; } else { $this->path = 'initial'; } } */ /** * sets file. * * @param uploadedfile $file */ public function setfile(uploadedfile $file = null) { $this->file = $file; // check if have old image path if (isset($this->path)) { // store old name delete after update $this->temp = $this->path; $this->path = null; } else { $this->path = 'initial'; } } /** * @orm\prepersist() * @orm\preupdate() */ public function preupload() { if (null !== $this->getfile()) { $this->path = $this->getfile()->guessextension(); } } /** * file. * * @return uploadedfile */ public function getfile() { return $this->file; } /** * @orm\postpersist() * @orm\postupdate() */ /** * @orm\postpersist() * @orm\postupdate() */ public function upload() { if (null === $this->getfile()) { return; } // check if have old image if (isset($this->temp)) { // delete old image unlink($this->temp); // clear temp image path $this->temp = null; } // must throw exception here if file cannot moved // entity not persisted database // uploadedfile move() method $this->getfile()->move( $this->getuploadrootdir(), $this->id.'.'.$this->getfile()->guessextension() ); $this->setfile(null); } /** * @orm\preremove() */ public function storefilenameforremove() { $this->temp = $this->getabsolutepath(); } /** * @orm\postremove() */ public function removeupload() { if (isset($this->temp)) { unlink($this->temp); } } public function getabsolutepath() { return null === $this->path ? null : $this->getuploadrootdir().'/'.$this->id.'.'.$this->path; } /** * @param \datetime $time */ public function settime($time) { $this->time = $time; } /** * @return \datetime */ public function gettime() { return $this->time; } /** * set path * * @param string $path * * @return email */ public function setpath($path) { $this->path = $path; return $this; } /** * path * * @return string */ public function getpath() { return $this->path; } }
hope 1 of genious outhere bring light path! , bless in advance!
check dump() if $city , $product strings not class or array.
$city = $email->setcity($form->get('city')->getdata()); $product =$email->setproduct($form->get('product')->getdata());
maybe need this
$city = $form->get('city')->getdata(); $product =$form->get('product')->getdata(); $email->setcity($city); $email->setproduct($product);
Comments
Post a Comment