symfony - How to get an email from a imbricated form into swiftmailer? -
i want insert email imbricated form swiftmailer. email "sendto" section of swifmailer.
as tried doesn't work. form sent no email recieved.
how can have it? have idea?
so controller, action send form , email :
/** * creates new reservations entity. * */ public function createaction(request $request) { $entity = new reservations(); $emailpool = new pool(); $form = $this->createcreateform($entity); $form->handlerequest($request); if ($form->isvalid()) { $em = $this->getdoctrine()->getmanager(); $em->persist($entity); $em->flush(); // sender's email adress $sender = $entity->getemail(); // recipients' emails adresses (pool address) $emailpool = $this->$pool->getemailpool(); // mal codé >> trouver la bonne méthode // send email $message = \swift_message::newinstance() ->setsubject('demande de véhicule') ->setfrom($sender) ->setto($emailpool) // email à entrer vehicule.esplanade@eurelien.fr // indicate "high" priority ->setpriority(2) ->setbody( $this->renderview( // view in app/resources/views/emails/demandereservation.html.twig 'emails/demandereservation.html.twig', array( 'reservations' => $entity)), 'text/html' ); $this->get('mailer')->send($message); $this->get('session')->getflashbag()->add('notice', 'votre réservation bien été envoyée'); return $this->redirect($this->generateurl('reservations_show', array('id' => $entity->getid()))); } return $this->render('cdcarsbundle:reservations:new.html.twig', array( 'entity' => $entity, 'form' => $form->createview(), )); }
the form (with imbricated form (pool)) :
<?php namespace cd\carsbundle\form\type; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface; use cd\carsbundle\entity\reservations; use cd\carsbundle\entity\vehicules; use application\sonata\userbundle\entity\user; class reservationstype extends abstracttype { // form entity "reservations" used build car's booking form /** * @param formbuilderinterface $builder * @param array $options */ public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('nomagent', null, array( 'label' => 'nom de l\'agent', //'attr' => array( //'readonly' => true, //'disabled' => true //) )) ->add('prenomagent', null, array( 'label' => 'prénom de l\'agent', //'attr' => array( //'readonly' => true, //'disabled' => true //) )) ->add('dga', null, array( 'label' => 'd.g.a', //'attr' => array( //'readonly' => true, //'disabled' => true //) )) ->add('direction', null, array( 'label' => 'direction', //'attr' => array( //'readonly' => true, //'disabled' => true //) )) ->add('email', null, array( 'label' => 'email', //'attr' => array( //'readonly' => true, //'disabled' => true //) )) ->add('telephone', null, array( 'label' => 'téléphone', //'attr' => array( //'readonly' => true, //'disabled' => true //) )) // ajouter le pool ->add('pool', new pooltype()) ->add('heuredebut', null, array( 'label' => 'date et heure de début', 'format' => 'dd-mm-yyyy h:i', 'years' => range(\date("y") - 0, \date("y") + 2), ) ) ->add('heurefin', null, array( 'label' => 'date et heure de fin', 'format' => 'dd-mm-yyyy h:i', 'years' => range(\date("y") - 0, \date("y") + 2), ) ) // ajouter type véhicule ->add('besoin', 'choice', array( 'label' => 'type', 'choices' => array( 'v.l' => 'v.l', 'v.l.e' => 'v.l.e', 'v.u' => 'v.u', 'velo' => 'vélo') ) ) // ajouter nombre personnes ->add('nombrepersonne', 'choice', array( 'label' => 'nombre de personne', 'choices' => array( '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5 +') ) ) // ajouter demande de remisage -> si coché dévoiler champs pour le remisage (dématérialisation) => à faire dans la vue ->add('remisage', null, array('required' => false)) ->add('adresseremisage', null, array('label' => 'adresse')) ->add('datedebutremisage', null, array( 'label' => 'du', 'format' => 'dd-mm-yyyy h:i', 'years' => range(\date("y") - 0, \date("y") + 2), ) ) ->add('datefinremisage', null, array( 'label' => 'au', 'format' => 'dd-mm-yyyy h:i', 'years' => range(\date("y") - 0, \date("y") + 2), ) ) ->add('emaildirecteur', null, array( 'label' => 'email du directeur', 'attr' => array( 'placeholder' => 'email@email.fr', )) ) ->add('destination', null, array('label' => 'destination')) ->add('motifrdv', null, array('required' => false)) ->add('motifformation', null, array('required' => false)) ->add('motifreunion', null, array('required' => false)) ->add('motifcollecte', null, array('required' => false)) ->add('motifinstallation', null, array('required' => false)) ->add('motifprogrammation', null, array('required' => false)) ->add('motifdepannage', null, array('required' => false)) ->add('motifvad', null, array('required' => false)) ->add('motifautre', null, array('label' => 'autre motif')) ->add('conducteur', null, array('required' => false)) // ajouter mandataire -> si coché dévoiler champs pour le mandataire (email...) => à faire dans la vue ->add('mandataire', null, array('required' => false)) ->add('nommandataire', null, array('label' => 'votre nom')) ->add('prenommandataire', null, array('label' => 'votre prénom')) ->add('emailmandataire', null, array('label' => 'votre émail')) ->add('honneur', null, array('required' => true)) ; }
the pool form :
<?php namespace cd\carsbundle\form\type; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface; use cd\carsbundle\entity\pool; use cd\carsbundle\entity\vehicules; class pooltype extends abstracttype { // form entity "pool" /** * @param formbuilderinterface $builder * @param array $options */ public function buildform(formbuilderinterface $builder, array $options) { $builder /*->add('nom', null, array( 'label' => 'nom', ))*/ ->add('emailpool', null, array( 'label' => 'email du pool duquel vous dépendez', )) ; } /** * @param optionsresolverinterface $resolver */ public function setdefaultoptions(optionsresolverinterface $resolver) { $resolver->setdefaults(array( 'data_class' => 'cd\carsbundle\entity\pool' )); } /** * @return string */ public function getname() { return 'cd_carsbundle_pool'; } }
the pool entity :
<?php namespace cd\carsbundle\entity; use doctrine\orm\mapping orm; /** * pool */ class pool { // code entity "pool" public function __tostring() { return (string) $this->getemailpool(); } //yml generated code /** * @var integer */ private $id; /** * @var string */ private $nom; /** * @var string */ private $emailpool; /** * @var \doctrine\common\collections\collection */ private $vehicules; /** * @var \doctrine\common\collections\collection */ private $user; /** * @var \doctrine\common\collections\collection */ private $reservations; /** * constructor */ public function __construct() { $this->vehicules = new \doctrine\common\collections\arraycollection(); $this->user = new \doctrine\common\collections\arraycollection(); $this->reservations = new \doctrine\common\collections\arraycollection(); } /** * id * * @return integer */ public function getid() { return $this->id; } /** * set nom * * @param string $nom * @return pool */ public function setnom($nom) { $this->nom = $nom; return $this; } /** * nom * * @return string */ public function getnom() { return $this->nom; } /** * set emailpool * * @param string $emailpool * @return pool */ public function setemailpool($emailpool) { $this->emailpool = $emailpool; return $this; } /** * emailpool * * @return string */ public function getemailpool() { return $this->emailpool; } /** * add vehicules * * @param \cd\carsbundle\entity\vehicules $vehicules * @return pool */ public function addvehicule(\cd\carsbundle\entity\vehicules $vehicules) { $this->vehicules[] = $vehicules; return $this; } /** * remove vehicules * * @param \cd\carsbundle\entity\vehicules $vehicules */ public function removevehicule(\cd\carsbundle\entity\vehicules $vehicules) { $this->vehicules->removeelement($vehicules); } /** * vehicules * * @return \doctrine\common\collections\collection */ public function getvehicules() { return $this->vehicules; } /** * add user * * @param \application\sonata\userbundle\entity\user $user * @return pool */ public function adduser(\application\sonata\userbundle\entity\user $user) { $this->user[] = $user; return $this; } /** * remove user * * @param \application\sonata\userbundle\entity\user $user */ public function removeuser(\application\sonata\userbundle\entity\user $user) { $this->user->removeelement($user); } /** * user * * @return \doctrine\common\collections\collection */ public function getuser() { return $this->user; } /** * add reservations * * @param \cd\carsbundle\entity\reservations $reservations * @return pool */ public function addreservation(\cd\carsbundle\entity\reservations $reservations) { $this->reservations[] = $reservations; return $this; } /** * remove reservations * * @param \cd\carsbundle\entity\reservations $reservations */ public function removereservation(\cd\carsbundle\entity\reservations $reservations) { $this->reservations->removeelement($reservations); } /** * reservations * * @return \doctrine\common\collections\collection */ public function getreservations() { return $this->reservations; } }
the reservations entity :
<?php namespace cd\carsbundle\entity; use doctrine\orm\mapping orm; use symfony\component\validator\mapping\classmetadata; use symfony\component\validator\constraints\notblank; use symfony\component\validator\constraints\email; use symfony\component\validator\constraints asserts; /** * reservations */ class reservations { // code entity "reservations" public function __tostring() { return (string) $this->getid(); return (string) $this->getheuredebut(); } // yml generated code /** * @var integer */ private $id; /** * @var \datetime */ private $heuredebut; /** * @var \datetime */ private $heurefin; /** * @var string */ private $nomagent; /** * @var string */ private $prenomagent; /** * @var string */ private $dga; /** * @var string */ private $direction; /** * @var string */ private $email; /** * @var string */ private $telephone; /** * @var string */ private $destination; /** * @var boolean */ private $reserve; /** * @var boolean */ private $annulation; /** * @var boolean */ private $remisage; /** * @var string */ private $adresseremisage; /** * @var \datetime */ private $datedebutremisage; /** * @var \datetime */ private $datefinremisage; /** * @var string */ private $emaildirecteur; /** * @var boolean */ private $conducteur; /** * @var boolean */ private $mandataire; /** * @var boolean */ private $motifrdv; /** * @var boolean */ private $motifformation; /** * @var boolean */ private $motifreunion; /** * @var boolean */ private $motifcollecte; /** * @var boolean */ private $motifinstallation; /** * @var boolean */ private $motifprogrammation; /** * @var boolean */ private $motifdepannage; /** * @var boolean */ private $motifvad; /** * @var string */ private $motifautre; /** * @var string */ private $commentaires; /** * @var integer */ private $nombrepersonne; /** * @var string */ private $besoin; /** * @var string */ private $nommandataire; /** * @var string */ private $prenommandataire; /** * @var string */ private $emailmandataire; /** * @var boolean */ private $honneur; /** * @var boolean */ private $traite; /** * @var \cd\carsbundle\entity\vehicules */ private $vehicules; /** * @var \application\sonata\userbundle\entity\user */ private $user; /** * @var \cd\carsbundle\entity\pool */ private $pool; /** * id * * @return integer */ public function getid() { return $this->id; } /** * set heuredebut * * @param \datetime $heuredebut * @return reservations */ public function setheuredebut($heuredebut) { $this->heuredebut = $heuredebut; return $this; } /** * heuredebut * * @return \datetime */ public function getheuredebut() { return $this->heuredebut; } /** * set heurefin * * @param \datetime $heurefin * @return reservations */ public function setheurefin($heurefin) { $this->heurefin = $heurefin; return $this; } /** * heurefin * * @return \datetime */ public function getheurefin() { return $this->heurefin; } /** * set nomagent * * @param string $nomagent * @return reservations */ public function setnomagent($nomagent) { $this->nomagent = $nomagent; return $this; } /** * nomagent * * @return string */ public function getnomagent() { return $this->nomagent; } /** * set prenomagent * * @param string $prenomagent * @return reservations */ public function setprenomagent($prenomagent) { $this->prenomagent = $prenomagent; return $this; } /** * prenomagent * * @return string */ public function getprenomagent() { return $this->prenomagent; } /** * set dga * * @param string $dga * @return reservations */ public function setdga($dga) { $this->dga = $dga; return $this; } /** * dga * * @return string */ public function getdga() { return $this->dga; } /** * set direction * * @param string $direction * @return reservations */ public function setdirection($direction) { $this->direction = $direction; return $this; } /** * direction * * @return string */ public function getdirection() { return $this->direction; } /** * set email * * @param string $email * @return reservations */ public function setemail($email) { $this->email = $email; return $this; } /** * email * * @return string */ public function getemail() { return $this->email; } /** * set telephone * * @param string $telephone * @return reservations */ public function settelephone($telephone) { $this->telephone = $telephone; return $this; } /** * telephone * * @return string */ public function gettelephone() { return $this->telephone; } /** * set destination * * @param string $destination * @return reservations */ public function setdestination($destination) { $this->destination = $destination; return $this; } /** * destination * * @return string */ public function getdestination() { return $this->destination; } /** * set reserve * * @param boolean $reserve * @return reservations */ public function setreserve($reserve) { $this->reserve = $reserve; return $this; } /** * reserve * * @return boolean */ public function getreserve() { return $this->reserve; } /** * set annulation * * @param boolean $annulation * @return reservations */ public function setannulation($annulation) { $this->annulation = $annulation; return $this; } /** * annulation * * @return boolean */ public function getannulation() { return $this->annulation; } /** * set remisage * * @param boolean $remisage * @return reservations */ public function setremisage($remisage) { $this->remisage = $remisage; return $this; } /** * remisage * * @return boolean */ public function getremisage() { return $this->remisage; } /** * set adresseremisage * * @param string $adresseremisage * @return reservations */ public function setadresseremisage($adresseremisage) { $this->adresseremisage = $adresseremisage; return $this; } /** * adresseremisage * * @return string */ public function getadresseremisage() { return $this->adresseremisage; } /** * set datedebutremisage * * @param \datetime $datedebutremisage * @return reservations */ public function setdatedebutremisage($datedebutremisage) { $this->datedebutremisage = $datedebutremisage; return $this; } /** * datedebutremisage * * @return \datetime */ public function getdatedebutremisage() { return $this->datedebutremisage; } /** * set datefinremisage * * @param \datetime $datefinremisage * @return reservations */ public function setdatefinremisage($datefinremisage) { $this->datefinremisage = $datefinremisage; return $this; } /** * datefinremisage * * @return \datetime */ public function getdatefinremisage() { return $this->datefinremisage; } /** * set emaildirecteur * * @param string $emaildirecteur * @return reservations */ public function setemaildirecteur($emaildirecteur) { $this->emaildirecteur = $emaildirecteur; return $this; } /** * emaildirecteur * * @return string */ public function getemaildirecteur() { return $this->emaildirecteur; } /** * set vehicules * * @param \cd\carsbundle\entity\vehicules $vehicules * @return reservations */ public function setvehicules(\cd\carsbundle\entity\vehicules $vehicules = null) { $this->vehicules = $vehicules; return $this; } /** * vehicules * * @return \cd\carsbundle\entity\vehicules */ public function getvehicules() { return $this->vehicules; } /** * set user * * @param \application\sonata\userbundle\entity\user $user * @return reservations */ public function setuser(\application\sonata\userbundle\entity\user $user = null) { $this->user = $user; return $this; } /** * user * * @return \application\sonata\userbundle\entity\user */ public function getuser() { return $this->user; } /** * set pool * * @param \cd\carsbundle\entity\pool $pool * @return reservations */ public function setpool(\cd\carsbundle\entity\pool $pool = null) { $this->pool = $pool; return $this; } /** * pool * * @return \cd\carsbundle\entity\pool */ public function getpool() { return $this->pool; } }
thank you. have nice day.
i have figured out. in controller, @ swiftmailer section, line recipient's email :
// recipients' emails adresses (pool address) $recipients = $entity->getpool()->getemailpool();
like works.
thank people read post , if have other answer, feel free post it.
have nice day!
Comments
Post a Comment