简体   繁体   中英

send email from model and template

if i want send email with SwiftMailer in symfony then i must in action:

$message = $this->getMailer()->compose(
      array('user@gmail.com' => 'user'),
      $affiliate->getEmail(),
      'Jobeet affiliate token',
      body
    );

    $this->getMailer()->send($message);

but this doesnt working in template and in model (i would like create function for this).

I wouldn't recommend sending mail using a template - put a link in the template and call the action to send the mail ... you can send from a model although again i wouldn't recommend it as using sfContext::getInstance() inside the model is a really bad practice as it makes the model class rely on the context. So, your model class can't be unit tested as it needs a context to work...

You need an instance of the current sfContext to do it ... i would suggest passing it as a parameter when you create the model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM