I'm developing an application in CodeIgniter, and I'm getting an error in sending mail while registering.
PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; emailcomm has a deprecated constructor in /var/www/html/portal/application/libraries/emailcomm.php on line 3
My Library file is below emailcomm.php
class emailcomm
{
var $to;
var $subject;
var $message;
var $from='From:';
function emailcomm()
{
$this->CI=&get_instance();
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_port'] = '465';
$config['_smtp_auth']=TRUE;
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'Web8*98*2015';
$config['smtp_timeout'] = '60';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = "html";
$this->CI->load->library('email',$config);
$this->CI->email->initialize($config);
}
}
Recently upgraded the server to php7, and now my code doesn't work anymore. I'm going through the error logs showing the above error. How can I fix my code?
Solution : Rename your function name emailcomm() to __construct()
Explanation: In previous versions of PHP
, if PHP
cannot find a __construct()
function for a given class, it will search for the old-style constructor function, by the name of the class,
but now old style constructors are DEPRECATED in PHP 7.0
, and will be removed in a future version. You should always use __construct()
in new code.
Read php manual
function __construct() {
// copy your old constructor function code here
}
You can rename your emailcomm()
function with __construct()
:
function __construct()
instead of
function emailcomm()
or you can use the following error_reporting
in your config file:
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With