Re: [symfony-users] Re: Sending mail from a Form class.
I disagree that this is a good use case for the event dispatcher. The event dispatcher is good for providing hooks for additional, _optional_ functionality (like logging, profiling etc.) Sending a mail upon form submission is not optional. This has to happen. You want to be able to test that it happens. The best solution IMHO is to inject the mailer into the form's constructor and use it in doSave() (unless you plan to embed that form somewhere else). And btw: NEVER use sfContext::getInstance(). Well, almost never. http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/ // /lib/form/doctrine/PostForm.class.php class PostForm extends BasePostForm { protected $mailer; public function __construct($object, sfMailer $mailer, array $options = array()) { $this-mailer = $mailer; parent::__construct($object, $options); } protected function doSave($con = null) { parent::doSave($con); $post = $this-getObject(); $mail = $this-mailer-compose(); $mail-setFrom(i...@teapartyitalia.it, 'Tea Party Italia'); $mail-setTo($array( 'myaddr...@yahoo.com', 'myaddr...@gmail.com', )); $mail-setSubject(prova); $mail-setBody(Mail inviata da form); $this-mailer-send($mail); } } Bernhard -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
[symfony-users] Re: Sending mail from a Form class.
I don't embed the form.. where should i put this function if I want that an email is sent when a new article is posted (in the backend)? And why it doesn't work into the form class using sfContext::getInstance(), and it works in an action using $this ? @Richtermeister: I've never used eventdispatcher On 2 Lug, 15:25, Johannes johannes.schmitt...@googlemail.com wrote: doSave() is probably not the right place since it never gets called if you embed the PostForm somewhere. Johannes On Jul 2, 3:12 pm, cosmy c.zec...@gmail.com wrote: On 2 Lug, 05:58, pghoratiu pghora...@gmail.com wrote: From the first one the actual send is missing: // send the email $this-getMailer()-send($mail); gabriel It still doesn't work.. -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
[symfony-users] Re: Sending mail from a Form class.
On 2 Lug, 05:58, pghoratiu pghora...@gmail.com wrote: From the first one the actual send is missing: // send the email $this-getMailer()-send($mail); gabriel It still doesn't work.. -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
[symfony-users] Re: Sending mail from a Form class.
doSave() is probably not the right place since it never gets called if you embed the PostForm somewhere. Johannes On Jul 2, 3:12 pm, cosmy c.zec...@gmail.com wrote: On 2 Lug, 05:58, pghoratiu pghora...@gmail.com wrote: From the first one the actual send is missing: // send the email $this-getMailer()-send($mail); gabriel It still doesn't work.. -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
[symfony-users] Re: Sending mail from a Form class.
From the first one the actual send is missing: // send the email $this-getMailer()-send($mail); gabriel On Jul 2, 5:25 am, Cosimo Zecchi c.zec...@gmail.com wrote: Hi all.. I think it's a strange behavior: if I send email inside an action it will be sent. If I try to send it inside the save function in a form class, the email doesn't arrive (I've seen in the sendmail queue and it is empty). To explain what i'm trying to do: i want to send an email everytime a post is created or edited, so the better thing to do it is to send through the save function of the Post Form class. This is the not working code (but it gives no errors, everything seem fine): !-- /lib/form/doctrine/PostForm.class.php -- public function doSave($con = null) { parent::doSave($con); $post=$this-getObject(); $mail = sfContext::getInstance()-getMailer()-compose(); $mail-setFrom(i...@teapartyitalia.it, 'Tea Party Italia'); $to = array( 'myaddr...@yahoo.com', 'myaddr...@gmail.com', ); $mail-setTo($to); $mail-setSubject(prova); $mail-setBody(Mail inviata da form); // send the email sfContext::getInstance(); } This my working function (it sends the email) in the actions.class.php: public function executeTestMail(sfWebRequest $request){ $mail = $this-getMailer()-compose(); // definition of the required parameters $mail-setFrom(i...@teapartyitalia.it, 'Tea Party Italia'); $to = array( 'myaddr...@yahoo.com', 'myaddr...@gmail.com', ); $mail-setTo($to); $mail-setSubject(prova); $mail-setBody(Mail inviata da testMail); // send the email $this-getMailer()-send($mail); $this-redirect('/'); } They are quite the same.. why the hell the first doesn't work? I'm going mad, thank you in advance, Cosimo -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
[symfony-users] Re: Sending mail from a Form class.
Hey there, overall this is a perfect case for using the eventdispatcher. That way you can keep the form focused on what it's good at (validation), and handle notifications outside. The form already has access to the eventdispatcher, so all it takes is firing an event that carries the post object to wherever the listener sits. For example, register some action as the listener, and you have access to the mailer there. No need involve sfContext, which makes this form hard to test. Just 2 cents, Daniel On Jul 1, 7:25 pm, Cosimo Zecchi c.zec...@gmail.com wrote: Hi all.. I think it's a strange behavior: if I send email inside an action it will be sent. If I try to send it inside the save function in a form class, the email doesn't arrive (I've seen in the sendmail queue and it is empty). To explain what i'm trying to do: i want to send an email everytime a post is created or edited, so the better thing to do it is to send through the save function of the Post Form class. This is the not working code (but it gives no errors, everything seem fine): !-- /lib/form/doctrine/PostForm.class.php -- public function doSave($con = null) { parent::doSave($con); $post=$this-getObject(); $mail = sfContext::getInstance()-getMailer()-compose(); $mail-setFrom(i...@teapartyitalia.it, 'Tea Party Italia'); $to = array( 'myaddr...@yahoo.com', 'myaddr...@gmail.com', ); $mail-setTo($to); $mail-setSubject(prova); $mail-setBody(Mail inviata da form); // send the email sfContext::getInstance(); } This my working function (it sends the email) in the actions.class.php: public function executeTestMail(sfWebRequest $request){ $mail = $this-getMailer()-compose(); // definition of the required parameters $mail-setFrom(i...@teapartyitalia.it, 'Tea Party Italia'); $to = array( 'myaddr...@yahoo.com', 'myaddr...@gmail.com', ); $mail-setTo($to); $mail-setSubject(prova); $mail-setBody(Mail inviata da testMail); // send the email $this-getMailer()-send($mail); $this-redirect('/'); } They are quite the same.. why the hell the first doesn't work? I'm going mad, thank you in advance, Cosimo -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups symfony users group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en