Welcome Guest, Not a member yet? Register   Sign In
Sending email from Model
#1

[eluser]bewhite[/eluser]
Hi!

I have problem with email. When I have tried to use it in the Controller then everything is ok. Now I have decided to separate all email related functions to the special class Mailer. Here is code:
Code:
class Mailer extends Model
{
  public

  function __construct()
  {
    parent::Model();
    $this->load->library('email');
  }

  function subscribe($email)
  {
    $subscriber = array('email' => $email);
    
    $this->db->insert('subscribers', $subscriber);
  }
  
  function mail_action($name, $email, $login, $password)
  {
    $initial = array('[FIO]', '[LOGIN]', '[PASSWORD]');
    $final = array($name, $login, $password);
  
    $template = read_file('system/application/views/mails/crew.php');
    
    $this->email->to($email);
    $this->email->from('[email protected]');
    
    $this->email->subject('Welcome to the mysite.com!');
    $this->email->message(str_replace($initial, $final, $template));
    
    $this->email->send();
  }
}
When I'm trying to call mail_action then I recieve Internal Server Error. Maybe it happens because I have used User Guide example of code and there is line with words 'assuming you are using Controller during email sending'. Can anybody show example of email sending from Model? Or just take a look at my code and tell me what should I change to make it workable?

Victor


Messages In This Thread
Sending email from Model - by El Forum - 01-11-2008, 07:27 AM
Sending email from Model - by El Forum - 01-11-2008, 08:13 AM
Sending email from Model - by El Forum - 01-11-2008, 08:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB