[eluser]rweston[/eluser]
stef, from the other thread, i swapped some stuff around. e.g. the loading of the view after the check for the posted data and added a 'definition' for $feedback.
I'm fairly 'new' to working with CI, but i've stuck with passing data to the view using the 2nd paramater of the view method ( $this -> load -> view ('viewname', $data) ), but i'll have to check out the load -> vars method and get familar with it.
Code:
class Mailer extends Controller {
function index() {
$feedback = array('message' => '');
//check to see if form is being submitted
if($this->input->post('sendCheck'))
{
//load email library
$this->load->library('email');
//text alternative
$textMail = "this is a text replacement";
//grab values
$fromName = $this->input->post('fromName');
$fromEmail = $this->input->post('fromEmail');
$toName = $this->input->post('toName');
$toEmail = $this->input->post('toEmail');
//insert values
$this->email->from($fromEmail, $fromName);
$this->email->to($toEmail, $toName);
$this->email->subject($fromName.' would like to recommend Company X to you');
$this->email->message('<p>All your base are belong to us</p>');
$this->email->set_alt_message($textMail);
echo $this->email->print_debugger();
//send mail + success / fail message
if (!$this->email->send()) {
$feedback = array(
'message' => 'Sorry, message could not be sent'
);
$this->load->vars($feedback);
}
else {
$feedback = array(
'message' => 'Message sent!'
);
$this->load->vars($feedback);
}
}
//load the default view, the main index.php html design
$this->load->view('index');
}
}