Welcome Guest, Not a member yet? Register   Sign In
Codeigniter sending blank emails when more then one email is sent in a single request
#6

I was thinking something like this:
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

class 
Emailer extends CI_Model {

    private 
$emailConfig;

    public function 
__construct() {

        
parent::__construct();

        
$this->load->library('email');

        
$this->emailConfig = array(
            
'mailtype'  => 'html',
            
'useragent' => $this->config->item('app_email_useragent'),
            
'protocol'  => $this->config->item('app_email_protocol'),
            
'smtp_host' => $this->config->item('app_email_smtp_host'),
            
'smtp_port' => $this->config->item('app_email_smtp_port'),
            
'smtp_user' => $this->config->item('app_email_smtp_user'),
            
'smtp_pass' => $this->config->item('app_email_smtp_pass'),
            
'smtp_crypto'=>'tls'
        
);
    }

    public function 
send_email($email$to$data = array()) {
        
$func '_email_'.$email;
        if (
method_exists($this$func)) {
            
$email $this->$func($data);
            if (
$email) {
                
$this->email->initialize($this->emailConfig);
                
$this->email->set_newline("\r\n");
                
$this->email->to($to); 
                
$this->email->from($this->config->item('app_email_from'), $this->config->item('app_email_from_name'));
                
$this->email->subject($email['subject']);
                
$this->email->message($this->load->view('emails/_wrapper', array('body' => $email['body']), true));
                
$result $this->email->send();
            }
        }
    }

    private function 
_email_contact_form($data = array()) {
        
$result = array();
        
$result['subject'] = 'Enquiry from '.$this->config->item('app_name').' website';
        
$result['body'] = $this->load->view('emails/contact_form'$datatrue);

        return 
$result;
    } 


However, I have a feeling there's something else wrong, and I'm just not seeing it for some reason.
Reply


Messages In This Thread
RE: Codeigniter sending blank emails when more then one email is sent in a single request - by mwhitney - 09-17-2015, 01:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB