Welcome Guest, Not a member yet? Register   Sign In
Date Error when Emailing with Code Igniter
#1

[eluser]eldrinofsoalim[/eluser]
Hi guys, I'm really new to Code Igniter. Hopefully I can get help from you guys.

I'm getting this error when I try to submit an e-mail. I followed Day 3 of Jeffrey Way's tutorial, but it seems I get this error and he doesn't.
Quote:A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Manila' for 'PHT/8.0/no DST' instead

Filename: libraries/Email.php

Line Number: 662

And...

Quote:A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Manila' for 'PHT/8.0/no DST' instead

Filename: libraries/Email.php

Line Number: 667

I've seen forums where people say the answer is to fix the php.ini file, but I'm really unfamiliar with a few terms so far. Considering that I'm somewhat new, can you guys help point me step-by-step how to fix this?

Thanks!

eldrinofsoalim
#2

[eluser]portgaz[/eluser]
You can use the codeigniter date helper
or set the
Code:
date_default_timezone_set("Asia/Manila");
#3

[eluser]chonlatee[/eluser]
sorry my English.

what your server localhost or real host ?

if you can't find other solution you can use this


date_default_timezone_set('your time zone'); in you function or Constructors function.
#4

[eluser]lennierb5[/eluser]
You can view the supported time zones here:

http://php.net/manual/en/timezones.php

Use the values found there in date_default_timezone_set or if you have access to edit your php.ini file your entry would be something like:

date.timezone = "US/Central"
#5

[eluser]eldrinofsoalim[/eluser]
Thanks for the quick replies!

I added the
Code:
date_default_timezone_set("Asia/Manila");
to the index function but it didn't work.

Then I placed it in the __construct function and it worked, errors don't show anymore.

I'm still a bit confused with the difference between index and __constructor. Aren't they both instantiated when the controller is called?
#6

[eluser]portgaz[/eluser]
When the controller is called/load the __constructor will be first instantiated.
I guess the
Quote:date()
function that you are using isn't on the index function. That's why it throws an error when you included the
Code:
date_default_timezone_set("Asia/Manila");
in the index function.
Am I wrong?

Hopes that helps! Smile
#7

[eluser]eldrinofsoalim[/eluser]
Here is the code:
Code:
<?php
    /**
    * SENDS E-MAIL WITH GMAIL
    */
    class Email extends Controller {
        
        function __construct() {
            parent::Controller();
            date_default_timezone_set("Asia/Manila");
        }
        
        function index(){

                
            $this->load->library('email', $config);
            $this->email->set_newline("\r\n");
            
            $this->email->from('[email protected]', 'John Doe');
            $this->email->to('[email protected]');
            $this->email->subject('This is a test e-mail');
            $this->email->message('It is working. Great!');
    
            $path = $this->config->item('server_root');
            
            $file = $path . '/PoweredByMacOSX.gif';

            $this->email->attach($file);
            
            if($this->email->send()) {
                echo 'Yup! Your e-mail was sent.';
            }
            else {
                show_error($this->email->print_debugger());
            }
        }
    }
    
?>

As you can see, the...
Code:
date_default_timezone_set("Asia/Manila");
is in the __construct function where it worked. If I put the same code in the index, the error still occurs.

What's the difference between index() function and the __construct() function if both are just instantiated when called?

Thanks for the help!




Theme © iAndrew 2016 - Forum software by © MyBB