secret
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
// 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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.