Skip to content

Instantly share code, notes, and snippets.

@mpmont
Created July 31, 2012 23:49
Show Gist options
  • Save mpmont/3221791 to your computer and use it in GitHub Desktop.
Save mpmont/3221791 to your computer and use it in GitHub Desktop.
// CONTROLLER
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Controllername extends CI_Controller {
public function index()
{
if (!empty($_POST)) {
$this->load->helper('emailsender');
if (contact_email($this->input->post())) {
die('your email was sent');
} else {
die('there was a problem sending your email');
}
}
}
}
// HELPER
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('contact_email')) {
function contact_email( $data = array()) {
//Load the ci instance
$CI =& get_instance();
$CI->load->library('email');
$CI->email->from('[email protected]', 'Name');
$CI->email->to($data['email']);
$CI->email->subject($data['subject']);
$CI->email->message($data['message']);
if ($CI->email->send()) {
return TRUE;
} else {
return FALSE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment