CodeIgniter email class
<?php
if (! defined('BASEPATH')) {exit('No direct access');}
class Email extends CI_Controller {
function construct($argument) {
parent::Controller();
}
function index(){
// email config - better move it to config/email.php
// and call it like so: $this->config->item('email');
$config = array(
'protocol' => '', // mail, sendmail, or smtp
// if smtp - define smtp_host, smtp_port, smtp_user and smtp_pass as well
);
$this->load->library('email', $config); // load email library (can be autoloaded)
$this->email->set_newline("\r\n"); // necessary for the Mail eXchange (MX) protocol to be able to recognise that the email is complete and ready to send the email on to the next MX server, without it, the MX server will just sit there waiting
$this->email->from($address, $name); // params: email string, name
$this->email->to($to); // param: email string
$this->email->subject($subject); // param: string
$this->email-message($body); // param: string
$this->email->attach($path.$fileName); // param: server path + filename
if ($this->email->send()) {
// success
} else {
show_error($this->email->print_debugger()); // CI method
}
}
}