Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
// CONTROLLER
<title>HEY</title>
<?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('Hey ');
$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());
}
}
}
}
// VIEW
<!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',
'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
Something went wrong with that request. Please try again.