CodeIgniter Forums
Good Email Form Tutorial or Code - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Good Email Form Tutorial or Code (/thread-18885.html)

Good Email Form Tutorial or Code - El Forum - 05-21-2009


I'm working my way through a form which will simply take details and email them to me.

I've done a search for Codeigniter forms but Godbit was the main one which is based on an older version of codeigniter.

Not like me to ask straight off the bat, but anyone have a link to a good modern tutorial or code that does validation etc. It's an emergency!

Many thanks.


Good Email Form Tutorial or Code - El Forum - 05-21-2009

I havn't seen any tutorials for that sort of thing. The form validation has lots of examples on the library page here -->

After you've validated it just need to email it off which is really easy, you can find the info here -->

You can put the posted variables in your email by using something like this:

$this->email->message('Some Field:'.$this->input->post('form_field_name'));

Good Email Form Tutorial or Code - El Forum - 05-22-2009

[eluser]got 2 doodle[/eluser]

As far as putting your mail message together I've found this technique useful
$message = $this->load->view('contents_email_cart',$data,true);

$data['user_data']= $this->userdata->get_user_data($this->user_id);
$order_email = $this->sitedata->get_site_key('order_email');
$this->email->subject('Website order');

The first line sends the data to a view with the 'true' parameter set, in my case it's a confirmation of an online order.

Here's a chunk of the view code.
Website generated order.
$today = getdate();
$year = $today['year'];
$month = $today['month'];
$daynum = $today['mday'];
$dayname = $today['weekday'];
echo "This order was placed on $dayname, $month $daynum, $year\n";
$the_code = random_string('numeric',8)."\n";
echo "ID Number:$the_code\n\n";

This allows an easy way to build a text message for emailing.

I know it doesn't directly answer your question and it could be considered a hack but it wasn't immediately obvious to me that you could do this in CI, now that I know you can it makes formatting the email real easy. I haven't tried it with html emails, but it should be no problem.

I thought this might save you some time.