0

i had a little contact form from the net and trying to insdtall it but i am getting these 2 errors and i must admit, i am not very good with php esp server side. the errors are:

Error 1: *Warning: 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.* contactform/include/class.phpmailer.php on line 1612 and the same warning for line 1616 of the same file class.phpmailer.php

line 1612 to line 1616 of class.phpmailer.php is

1612- $tz = date('Z');
1613- $tzs = ($tz < 0) ? '-' : '+';
1614- $tz = abs($tz);
1315- $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1316- $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);

Error 2: Warning: Cannot modify header information - headers already sent by (output started at /home/massa/public_html/mydomain.com/folder/contactform/include/class.phpmailer.php:1612) in /home/massa/public_html/mydomain.com/folder/contactform/include/fgcontactform.php on line 143

line 143 of fgcontactform.php is .

143-  header("Location: $url");
144-  exit;

I must specity this are not my codes, its just a free basic contact form i had on internet and try to implement it on my site.. Any help will be appreciated. Just how to insert the right time zone on line 1612 and what to insert in line 143 of the other file.. Thanks in advance. Michelle

  • https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php You can add ob_start(); at the top of your file as a quick and dirty hack. The reason is you aren't allowed to send any output before a header redirect. ob_start will eat that output. As far as timezone. You need to set it. – Matt Jun 08 '17 at 03:49
  • sorry @mkaatman: i have already exploited that article on the link you said and cant seem to figure out. Add ob-start at the top of which file.? please? top of my file is class PHPMailer { var $Priority = 3; and other classes listed down. Sorry i am not really looking to know how it works, just exactly what to put and where, so i can go on wirth my site. thanks, – Michelle Dimwaite Jun 08 '17 at 03:53
  • sorry @mkaatman: i have already exploited that article on the link you said and cant seem to figure out. Add ob-start at the top of which file.? please? top of my file is class PHPMailer { var $Priority = 3; and other classes listed down. Sorry i am not really looking to know how it works, just exactly what to put and where, and as concern time zone, i need to set it, set what where, what timezone format? Sorry for my ignorance thanks, – Michelle Dimwaite Jun 08 '17 at 03:59
  • @Kaivosukeltaja covered the issue. In your fgcontactform add `date.timezone="America/New_York";` at the top of the file. – Matt Jun 08 '17 at 04:04

1 Answers1

1

The problem is in your php.ini settings. Follow the warning's suggestion and either edit the file and add this:

date.timezone="Australia/Sydney"

Or alternatively, add the call to date_default_timezone_set("Australia/Sydney") somewhere in the beginning of your code.

Once the error is resolved, your other problem will be gone as well. PHP echoes all errors it encounters and unless your output is buffered, it will send the HTTP response headers along with the first thing it outputs. After that it will be too late to use header('Location: ...') because the headers are already sent to the client.

Kaivosukeltaja
  • 15,541
  • 4
  • 40
  • 70
  • Are you referring to my line 1612- $tz = date('Z');, how do i insert date.timezone="Australia/Sydney" in that format? and what php.ini file you mean, the download package i have doesnt have this file at all unless you mean on my sever? thanks – Michelle Dimwaite Jun 08 '17 at 04:09
  • do you mean i should rewrite { header("Location: $url"); exit; } to { header("Location: $url"); exit; }. what about the variable $url?@Kaivosukeltaja – Michelle Dimwaite Jun 08 '17 at 04:13
  • Yes, I mean on the server. The correct path depends on your installation but it usually can be found in a path that starts with `/etc/php`. On my Ubuntu it's in `/etc/php/5.6/apache2/php.ini`. – Kaivosukeltaja Jun 08 '17 at 04:14
  • For a quick fix you could just add the `date_default_timezone_set("Australia/Sydney")` before your line 1612 but I'd recommend setting the correct timezone globally in php.ini so you won't bump into the same problem again. – Kaivosukeltaja Jun 08 '17 at 04:16
  • did that nothing happened,, Are you looking at my line 1612 etc etc,? if those where your codes, how will you rewrite? it assuming you are in Sydney Australia? – Michelle Dimwaite Jun 08 '17 at 04:32
  • If it were my code I'd change the `php.ini` file. Note that adding `date.timezone="blahblah"` inside your PHP script will do nothing except possibly generate an error. To make the change inside PHP you'll need to call `date_default_timezone_set("Australia/Sydney")` before the first time you use any date/time functions. – Kaivosukeltaja Jun 08 '17 at 04:44
  • yeah thanks i tried but my company will not let me edit the php file, they prefered i configure it on the contact form. Assuming that you are doing it. how will your line 1612 to 1616 be as per my example above, and one thing, I do receive the messages processed in the form but the problem is just seeing those warnings after i submit, just to get rid of that,. more of your help needed??? And thanks for your continual replies – Michelle Dimwaite Jun 08 '17 at 05:03
  • Lines 1612 and 1616 don't need to be changed. Just add `date_default_timezone_set("Australia/Sydney")` somewhere before them. If you have a file you `include`/`require` for all of your pages that would be a great place. Otherwise I'd probably place it right at the top of the file. – Kaivosukeltaja Jun 08 '17 at 06:40