Skip to content
Create a gist now

Instantly share code, notes, and snippets.

class Email extends CI_Controller {
public function __construct()
// Your own constructor code
function index() {
function send() {
// three rules - field name, error message, validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email');
if($this->form_validation->run() == FALSE) {
// validation has passed. Now send the email
$name = $this->input->$_POST('name');
$email = $this->input->$_POST('email');
$this->email->from('', 'Michael Sanger');
$this->email->subject('Hey ');
$path = $this->config->item('server_root');
$file = $path . '/CodeIgniter/attachments/email_test_attachment.txt';
if($this->email->send()) {
'email sent';
else {
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
label { display:block;}
<div id="newsletter_form">
<?php echo form_open('email/send'); ?>
$name_data = array(
'name' => 'name',
'id' => 'name',
'value' => set_value('name')
<label for="name">Name: </label><?php echo form_input($name_data);?>
<label for="name">Email Address:</label><input type="text" name="email" id="email" value="<?php echo set_value('email');?>">
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
<?php echo validation_errors('<p class="error">'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.