Skip to content

Instantly share code, notes, and snippets.

@good-orbit
Created October 17, 2011 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save good-orbit/70401ed7314fac8b46fa to your computer and use it in GitHub Desktop.
Save good-orbit/70401ed7314fac8b46fa to your computer and use it in GitHub Desktop.
//CONTROLLER
<?php
class Email extends CI_Controller {
public function __construct()
{
parent::__construct();
// Your own constructor code
}
function index() {
$this->load->view('newsletter');
}
function send() {
$this->load->library('form_validation');
// 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) {
$this->load->view('newsletter');
}
else
{
// validation has passed. Now send the email
$name = $this->input->post('name');
$email = $this->input->post('email');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('RalphLeMouf@gmail.com', 'Michael Sanger');
$this->email->to('RalphLeMouf@gmail.com');
$this->email->subject('Test this fucking sign-up shit');
$this->email->message('YO');
$path = $this->config->item('server_root');
$file = $path . '/CodeIgniter/attachments/email_test_attachment.txt';
if($this->email->send()) {
'email sent';
}
else {
show_error($this->email->print_debugger());
}
}
}
}
VEW:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>newsletter</title>
<style type="text/css">
label { display:block;}
</style>
</head>
<body>
<div id="newsletter_form">
<?php echo form_open('email/send'); ?>
<?php
$name_data = array(
'name' => 'name',
'id' => 'name',
'action' =>'email
'value' => set_value('name')
);
?>
<p>
<label for="name">Name: </label><?php echo form_input($name_data);?>
</p>
<p>
<label for="name">Email Address:</label><input type="text" name="email" id="email" value="<?php echo set_value('email');?>">
</p>
<p>
<?php echo form_submit('submit', 'Submit'); ?>
</p>
<?php echo form_close(); ?>
<?php echo validation_errors('<p class="error">'); ?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment