[eluser]jshultz[/eluser]
I'm using the email library to send emails from a simple "contact us" type form. Everything is working and emails are being sent but there's no message. The subject and all the other data works and even the form validation. It's just the message is dropped off and all that is sent is blank email.
Here's my email function:
Code:
class Email extends Controller
{
function __construct()
{
parent::Controller();
}
function index()
{
$this->load->library('email');
$data['page_title'] = 'Arrow Express';
$data['banner'] = 'banner-contact';
$data['page'] = 'contact'; // pass the actual view to use as a parameter
$this->load->view('container',$data);
}
function send()
{
$this->load->library('form_validation');
// 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');
$this->form_validation->set_rules('message', 'Comments', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$data['page_title'] = 'Arrow Express';
$data['banner'] = 'banner-contact';
$data['page'] = 'contact'; // pass the actual view to use as a parameter
$this->load->view('container',$data);
}
else
{
// validation has passed. Now send the email
$name = $this->input->post('name');
$email = $this->input->post('email');
$comments = $this->input->post('message');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from($email, $name);
$this->email->to($email);
$this->email->subject('Arrow Express Contact Form');
$this->email->message($comments);
$path = $this->config->item('server_root');
$file = $path . '/ci_day4/attachments/newsletter1.txt';
$this->email->attach($file);
if($this->email->send())
{
//echo 'Your email was sent, fool.';
redirect('/site/contact_confirmation/');
}
else
{
show_error($this->email->print_debugger());
}
}
}
}
And here's my contact form:
Code:
<?php echo form_open('email/send'); ?>
<fieldset>
<div id="" class="span-8">
<legend>
Use This Simple Form
</legend>
<br/>
<?php
$name_data = array('name'=>'name', 'id'=>'name', 'value'=>set_value('name'));
$message_data = array('name'=>'message', 'id'=>'message', 'value'=>set_value('message'), 'rows'=>'5', 'class'=>'span-7');
?>
<p>
<label for="name">
Name:
</label><br/>
<?php echo form_input($name_data); ?>
</p>
<p>
<label for="name">
Email Address:
</label><br/>
<input type="text" name="email" id="email" value="<?php echo set_value('email');?>">
</p>
</div>
<div id="" class="span-7 last">
<label>
Comments
</label>
<?php echo form_textarea($message_data); ?>
<br/>
<p>
<?php echo form_submit('submit', 'Submit'); ?>
</p>
<?php echo form_close(); ?>
</div>
</fieldset>
<?php echo validation_errors('<p class="error">'); ?>
</div>