CodeIgniter From Scratch: Day 4
videos

CodeIgniter From Scratch: Day 4 – Newsletter Signup

This entry is part 4 of 17 in the CodeIgniter From Scratch Session
« PreviousNext »

Continuing on from Day 3, we’ll expand our little application into a simple newsletter signup form. This will allow us to taker a closer look at both the email and the form_validation classes. Learn it all in this 30 minute screencast.

Catch Up

Day 4

If you’re having trouble viewing the video, watch it here instead.


Add Comment

Discussion 146 Comments

Comment Page 2 of 2 1 2
  1. Howard says:

    Is there a “best practice” for multiple page forms?

    For example, the user goes to page and enters some registration information. Based on the choices made in the form, the user is sent to a second page to fill out more information.

    Do you hold the user data in session variables? Or to you update the database after every page?

    Thanks!

    • Alex Stomp says:

      I’d like to know this too.. I will go with session variables for now, but yea.. I’m not sure what to do for this.

      • mbuurman says:

        A bit late reaction, but for simple forms I simply pass the entered data to the next form with a hidden field.

        Like form1:
        input type text name=name

        Then in form2:
        input type hidden name=name value= $_POST['name']

  2. Rich Webster says:

    First, thank you for the series… quite good. I did have one problem with it, and maybe it was my fault. But for other newbies:

    this->email->set_newline(‘\r\n’); gave me problems.

    it put a newline in the middle of the header, after sending. I think this is because the sending server (qmail, masquerading as sendmail) prepended some header info, then the newline appeared, then the rest of the header info supplied by the Email class appeared… The newline caused part of the header to appear in the body, including the multipart stuff, causing the html to not render, the mime info and some of the header info to look wonky, and me to tear out what little hair I have left. Removing the newline code restored my sanity.

    So is my mail server weird? Did you ever figure out why the line needs to be there (since it seemed to solve MY problems to take it out)? Has anyone else had a similar experience?

    The one thing I’ve done a bit different than this tutorial is: I was loading a pre-designed HTML page as the message, using read_file(), with the intent of creating a system that sends a series of emails to anyone who signs up, starting with the first and continuing monthly for a year… rather than your system that sends a just-saved message on demand. But that shouldn’t have affected the headers.

  3. Gregory says:

    Hi Jeff,

    I noticed when you referenced the stylesheet it was for that single view, is it possible to reference a css file for all your views?

    Thanks!

  4. Maxx90 says:

    And third, and probably most importantly, simplifying the benefit formula as part of a larger Social Security reform. ,

  5. anzahen says:

    http://nettuts.blip.tv/file/2466799?filename=NETTUTS-CodeIgniterFromScratchDay4184.flv
    where the video?
    problem loading page
    The server at nettuts.blip.tv is taking too long to respond.

  6. t0m3k says:

    Hi.
    I’m getting strange issue:
    Fatal error: Call to undefined function form_open() in C:\Program Files\WebServ\httpd\codeigniter\application\views\newsletter.php on line 15

    Somebody knows what’s the problem?
    I downloaded files from this page and I’m getting the same error.

  7. ChoiZ says:

    Hi, i try to send an email with Code Igniter.

    With plain/text it’s works (with smtp protocol like your screecast).

    But when i set: $config['mailtype'] = ‘html’; in my config/email.php file it’s doesn’t works… Any ideas ?

    Thank you for this great tutorials ;)

  8. ChoiZ says:

    Ok i’ve got my answer in my config/email.php you have to specify :

    $config['charset'] = ‘iso-8859-1′;

    if you want to send an html mail with code igniter ;)

    Regards,

  9. red says:

    Jeffrey, this series is truly great. So great, I’m going to subscribe to the Plus program.

  10. Alexanxer says:

    I love this series! thank you very much. Keep up the good work Jeffrey!

  11. adelle says:

    That Such an explained Screencast .. so great . GO ON

  12. Kit says:

    I watched the first video in this series way before I understood MVC at all. It was a little advanced for me then, but now it’s perfect! Understanding frameworks has to be one of the most useful things I have ever learned. I spent all of yesterday trying to send HTML emails by hand when this thing does all the work for me!

  13. Kris says:

    Great tut as usual! Unfortunately, the ‘get the source code’ link is broken. If it matters, I am a premium member and am currently signed in.

  14. Kris says:

    I was finally able to download the source files. It didn’t work when I first logged into the member’s area and then navigated to this page.

    It did work when I navigated to this page and then logged on via the input boxes on this page and then hit the ‘back’ button on my browser.

    In what is probably an unrelated issue, half the time I reload this page, I get no css.

  15. Yvan says:

    Hey ! Great series, very clear and useful.

    But when I try to send the e-mail, I get the following error :

    A PHP Error was encountered

    Severity: Warning

    Message: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()

    Filename: libraries/Email.php

    Line Number: 1519

    I tried to use the mail protocol (instead of ssl) and also tried to modify the smtp info in the php.ini file, but it doesn’t change anything. I just don’t understand. Has anyone any idea ? Could it be because I am at the office and can’t do everything I want on my computer ? I guess not, because I have full rights on my wamp folder and I can of course send e-mail, but there may be something I miss…

    Thanks

    • Edward says:

      Just email configurations error to call mail functions:

      Refer to Day 3: Sending Emails. to solve this error

      Cheers!

      • Yvan says:

        Thanks for your answer, but I just don’t get what you mean… :(

        I’ve gone through Day 3. I don’t think there is any mistake in my php/codeigniter code. But I can’t recall having done any configuration for the sending of e-mail. Maybe I’m missing something. Maybe the port is blocked (because of the proxy of my work place) or the mailserver address should be different…

        I really don’t understand. If you could explain a bit more, that would be great. Thanks !

      • Edward says:

        I see.. Can you show me the codes of your email controller.

    • Nicholas Riley says:

      I understand it has been a year since this comment was posted, but just in case anyone else runs into it – open up your php.ini and search for “ssl” and uncomment “extension=php_openssl.dll” – don’t mess with your smtp settings unless you know what you are doing. Also, be sure to restart your *AMP Server ;) – Cheers

  16. koftunka says:

    Ok, so here is the same error that I was getting with a lesson 3. I successfully submit form and get a confirmation email with attachment, but still when I use autoloading of email.php from config folder I get:

    A PHP Error was encountered
    Severity: Notice

    Message: Undefined variable: config

    Filename: controllers/email.php

    Line Number: 27

    Anyone have an idea why? Thanks.

    • Youssef says:

      Try this (with quotes):
      $this->form_validation->set_rules(‘name’, ‘Name’,'trim|required’);
      $this->form_validation->set_rules(‘email’, ‘Email’,'trim|required|valid_email’);

  17. nXqd says:

    “jQuery ” at $_SERVER :D . You do a lot of tutorial mate .
    THanks for great video
    – nXqd

  18. Hitesh says:

    Hello sir …..

    i tried this code bt i got this fetal error

    Fatal error: Maximum execution time of 59 seconds exceeded in C:\wamp\www\tempproj\system\libraries\Email.php on line 1812

    so how can i solve this error.

    Great tutorial ………..

  19. Wilson says:

    This series is absolutely great, thank you so much for taking the time to make this. Very, very helpful.

  20. Eoghan says:

    Thanks again Jeff.

  21. Zach says:

    I followed along with the tut, and everything is working, except for when I look at the email in my inbox, the message doesn’t show up? Does anybody know anything about this?

  22. Korky says:

    Was wondering about how you got your HTML shell at the very first of the tutorial around the 2:50 mark or so. Looks like you typed “beginthm” then backspaced but the shell magically appeared. I’m sure this is a feature in TextMate, but I’m test driving that product and was wondering if this was a snippet or what?

    Excellent Tutorial…I’ve been wanting to get into a Framework for a while (PHP coding now for 10 years) and this is making it a lot more friendly. Hopefully we’ll see soon how to insert, update and delete records (i reckon those are just methods!)

    Thnx.

  23. Korky says:

    I am still having one last issue. I have looked at the downloaded files, compared them against mine and they seem to be identical except for the actual parameters for the email.

    However, when you run your exercise, the form is centered properly. Mine is shifted left at the left side of the page. The CSS clearly seems to support that placement. I can’t find out how you got the form to be centered in your video.

    Can you lend some insight here?

  24. gayathri says:

    can u please take a tutorial about using the messenger in my website???

  25. gayathri says:

    i am badly in need of adding messenger plugin in my website.. help me out soon
    ..

  26. foobar says:

    are there next parts of this tutorial?

  27. Bert says:

    Hi Jeffrey,

    thanks for the excellent tutorials! I’m just starting out with CodeIgniter and your tuts are a great help. Carry on the noble work ;)

  28. Steve says:

    Yesterday I followed the Day 3 video, and was able to send an email from a live server, even though it wouldn’t work on my local machine running XAMPP. Today, I continued with the day 4 tutorial and now it WILL send an email from my local machine, but when i try running it on the live server i get errors. Its weird because im getting the same errors from the live server that i was getting yesterday from my local XAMPP, somehow the tables turned… and i am at a complete loss. Heres the errors:

    A PHP Error was encountered
    Severity: Warning
    Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)
    Filename: libraries/Email.php
    Line Number: 1652

    A PHP Error was encountered
    Severity: Warning
    Message: fwrite(): supplied argument is not a valid stream resource
    Filename: libraries/Email.php
    Line Number: 1795

    A PHP Error was encountered
    Severity: Warning
    Message: fgets(): supplied argument is not a valid stream resource
    Filename: libraries/Email.php
    Line Number: 1818

    A PHP Error was encountered
    Severity: Warning
    Message: Cannot modify header information – headers already sent by (output started at /home/gcstarc1/public_html/stevemason/scoopd/system/libraries/Exceptions.php:166)
    Filename: codeigniter/Common.php
    Line Number: 356

    Anyone with a clue what might get this working on the live server again?

  29. Marcus says:

    I’m learning CodeIgniter the Jeffrey Way!

  30. CakeWalk says:

    Single quotes do not allow escape sequences (such as \n )
    double quotes do.

    e.g. “testing\n’wow’OMG” produces
    testing
    ‘wow’OMG

    Whereas ‘testing\n”wow”OMG’ produces
    testing\n”wow”OMG

  31. r-benTahir says:

    my form doesn’t show up.. i am using the echo form_open();… guide me please.. i am very new to ci.. and i am lovin it. it doesn’t show me the fields . any thoughts y???

  32. aditya menon says:

    thanks, enjoyed it very much. it’s really extremely simple!

  33. Great post. I enjoyed it very much! Thanks. Goo luck Felice Herrero

  34. Craig says:

    Hey, I’m a little confused. I keep getting an 404 error saying that “email/send” doesn’t exist?

  35. Craig says:

    Okay, I’ve fixed that issue it was my based_url. But what is plaguing me now is the “validation” isn’t working.

    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’);

    if($this->form_validation->run() == FALSE)
    {
    $this->load->view(‘newsletter’);
    }

    It doesn’t show up as asking for an email or password.

  36. webmaster says:

    You can’t send email with gmail. Not anymore… You need a webserver with a dedicated email server and then create the config array with those settings. Actually the only fields that need to be changed are ‘smtp_host’ and ‘smtp_user’ and pass. It should work with the default settings of the latest MAMP Version. (I’m using MAMP).

  37. Fra Ore says:

    Hi, very interesting tutorial’s serie!

    I’m italian, i don’t speak english very well and i’m learning codeigniter.

    Mine is a stupid question: Why never we use a model?!

    In this video we use a view and a controller… But what can we to put in a model?

    This is because i don’t understand very well the MVC paradigm!

    Thank to who will answer!

    Fra!

    • Khalid says:

      As we know . Models is just made for dealing with database .
      if you made an application that deals with database . you will make model to deal with database . controller to get info from model and assign it to view . view to display html etc …
      if we don’t use models . then we will not deal with database . just controllers and views .

      I hope my answer was useful !

      • Ian says:

        Just to add to this, You would use a model if after the email is successfully sent the users email is stored in a database so it can be used later to send them the newsletter they just subscribed for.

        still this might be part of another model since it’s one little piece of info. Not sure if you would create a model for this or if this will be part of a subscribers database with more data in it.

        I’m guessing that will come later in the series.

  38. Tate says:

    Hello,

    I am getting this error:

    A PHP Error was encountered
    Severity: Notice
    Message: Undefined property: Email::$form_vaildation
    Filename: controllers/email.php
    Line Number: 20

    function send(){
    $this->load->library(‘form_validation’);

    //field name, error message, validation rules
    $this->form_vaildation->set_rules(‘name’, ‘Name’, ‘trim|required’); // line 20
    $this->form_vaildation->set_rules(‘email’, ‘Email Address’, ‘trim|required|valid_email’);

    Any help would be very appreciated.

  39. Shun says:

    Hi! for some reason, the style.css does not work, the form box is like this : http://imageshack.us/photo/my-images/843/screenshotkj.png/ . Does anyone have this problem?
    P.S: great tutorials

  40. Brandon says:

    $_SERVER['DOCUMENT_ROOT'] is my favorite jQuery function too! LOL.
    Thanks for the tutorials man, keep it up!

  41. Ian says:

    Testament to the awesomeness of these tuts. It’s 2011 and people are still learning from these!

    Now back to the css noob to ninja series to fix the issue with the “Signup for the Newsletter” heading. lol

  42. Niccu says:

    I keep on getting this error: A PHP Error was encountered

    Severity: 8192

    Message: Function get_magic_quotes_gpc() is deprecated

    Filename: core/Input.php

    Line Number: 516
    T.T please help

  43. Alvaro Uribe says:

    Nice Tutorial :D this also works for codeIgniter 2.1….

    The inclusion of css does not work for me because i think my routes.php file has something wrong…

    Maybe somebody can help me here it is:

    my header.php file is in CodIgniter/App/views/templates/header.php
    and i put the there:

    <link rel="stylesheet" type="text/css" media="screen" href="css/base.css” />

    and the result is:

    i put here CodIgniter/App the folder CSS AND
    i put here CodIgniter/ the folder CSS AND nothing happens so i believe that the routes.php is corrupt

    routes.php

    $route['news/create'] = ‘news/create’;
    $route['news/(:any)'] = ‘news/view/$1′;
    $route['news'] = ‘news’;
    $route['pages/(:any)'] = ‘pages/view/$1′;
    $route['default_controller'] = ‘pages/view’;
    $route['404_override'] = ”;

  44. Jason says:

    I used the form helper as shown as the tutorial, but strangely I got 2 index.php nested in my send url,
    and it shows error 404 page not found message.

    Does anyone have the same issue? I am using MAMP by the way.

    here’s the form action url generated:

    http://localhost:8888/CI/index.php/index.php/email/send

    here’s my code:

    ‘name’,
    ‘id’ => ‘name’,
    ‘value’ => set_value(‘name’)
    );

    ?>

    Name:

    Email Address:
    <input type=text id=email value=>

    • Jason says:

      sorry I forgot the code is in php:

      here’s my code:

      ‘name’,
      ‘id’ => ‘name’,
      ‘value’ => set_value(‘name’)
      );

      ?>

      Name:

      Email Address:
      <input type=text id=email value=>

      and this is the source code of my form page:

      Name:

      Email Address:

  45. baljit says:

    hi
    thanks for provide useful code

Comment Page 2 of 2 1 2

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.