Welcome Guest, Not a member yet? Register   Sign In
Error with email class in CI 3.1.8
#1
Bug 
(This post was last modified: 04-04-2018, 01:11 AM by ardavan.)

Hey everybody.

I'm trying to use email class as usual.

I have loaded the email library in the autoload.php and made an email.php file in my config folder and in my controller trying to send() the email.

But I get Error "NOT" on the browser, rather in the log file. I don't have this problem with CI 3.1.5 by the way!
Does anyone have any idea?

config > email.php
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');
$config['protocol']    = 'smtp';
$config['smtp_host']    = 'mail.mydomain.com';
$config['smtp_port']    = '26';
$config['smtp_timeout'] = '7';
$config['smtp_user']    = 'myusername';
$config['smtp_pass']    = 'mypassword';
$config['charset']    = 'utf-8';
$config['newline']    = "\r\n";
$config['mailtype'] = 'html';
$config['validation'] = TRUE

controller
PHP Code:
$message $this->load->view('edm/verification'''TRUE);
$this->email->from($this->config->item('from'), $this->config->item('appName'));
$this->email->to($email);
$this->email->subject('Welcome to '.$this->config->item('appName'));
$this->email->message($message);

if( ! 
$this->email->send()):
 
$this->session->set_flasdata('error'$this->lang->line('unableSendingEmail'));
endif; 

log file
Code:
ERROR - 2018-04-04 01:49:43 --> Severity: Error --> Call to a member function from() on string /home1/xxx/public_html/myProject/application/controllers/User.php 129
Reply
#2

(This post was last modified: 04-04-2018, 08:08 AM by php_rocs.)

@ardavan,
What is the value for $this->config->item('from') and $this->config->item('appName')?
What I mean to say is where (in your code) is the value for $this->config->item('from') and $this->config->item('appName') assigned?
Reply
#3

(This post was last modified: 04-04-2018, 12:15 PM by Paradinight.)

(04-04-2018, 12:57 AM)ardavan Wrote: Hey everybody.

I'm trying to use email class as usual.

I have loaded the email library in the autoload.php and made an email.php file in my config folder and in my controller trying to send() the email.

But I get Error "NOT" on the browser, rather in the log file. I don't have this problem with CI 3.1.5 by the way!
Does anyone have any idea?

config > email.php
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');
$config['protocol'   'smtp';
$config['smtp_host'   'mail.mydomain.com';
$config['smtp_port'   '26';
$config['smtp_timeout'] = '7';
$config['smtp_user'   'myusername';
$config['smtp_pass'   'mypassword';
$config['charset'   'utf-8';
$config['newline'   "\r\n";
$config['mailtype'] = 'html';
$config['validation'] = TRUE

controller
PHP Code:
$message $this->load->view('edm/verification'''TRUE);
$this->email->from($this->config->item('from'), $this->config->item('appName'));
$this->email->to($email);
$this->email->subject('Welcome to '.$this->config->item('appName'));
$this->email->message($message);

if( ! 
$this->email->send()):
 
$this->session->set_flasdata('error'$this->lang->line('unableSendingEmail'));
endif; 

log file
Code:
ERROR - 2018-04-04 01:49:43 --> Severity: Error --> Call to a member function from() on string /home1/xxx/public_html/myProject/application/controllers/User.php 129

$this->email is a string not an object.

Have you something like $this->email = "string" in the controller? or an attribute $email = "string" ?
Reply
#4

(04-04-2018, 04:49 AM)php_rocs Wrote: @ardavan,
What is the value for $this->config->item('from') and $this->config->item('appName')?
What I mean to say is where (in your code) is the value for $this->config->item('from') and $this->config->item('appName') assigned?

the value of them is a string.
Reply
#5

(This post was last modified: 04-04-2018, 05:59 PM by ardavan.)

(04-04-2018, 12:14 PM)Paradinight Wrote: $this->email is a string not an object.

Have you something like $this->email = "string" in the controller? or an attribute $email = "string" ?

i am following this https://www.codeigniter.com/user_guide/l...ding-email
as i said this works on my another project which is different version of CI (3.1.5) but in 3.1.8 doesnt work.

this is my project in CI 3.1.5 which the email works perfectly
PHP Code:
$from $this->config->item('email_info');
$to $this->session->flashdata('to');
$subject $this->session->flashdata('subject') . ' | ' $this->AppName;
$message $this->session->flashdata('message');

$this->email->from($form['address'], $from['name']);
$this->email->to($to);
        
if(
$cc$this->email->cc($cc);

$this->email->subject($subject);
$this->email->message($message);
$this->email->send(); 
Reply
#6

(04-04-2018, 05:56 PM)ardavan Wrote:
(04-04-2018, 12:14 PM)Paradinight Wrote: $this->email is a string not an object.

Have you something like $this->email = "string" in the controller? or an attribute $email = "string" ?

i am following this https://www.codeigniter.com/user_guide/l...ding-email
as i said this works on my another project which is different version of CI (3.1.5) but in 3.1.8 doesnt work.

this is my project in CI 3.1.5 which the email works perfectly
PHP Code:
$from $this->config->item('email_info');
$to $this->session->flashdata('to');
$subject $this->session->flashdata('subject') . ' | ' $this->AppName;
$message $this->session->flashdata('message');

$this->email->from($form['address'], $from['name']);
$this->email->to($to);
 
if(
$cc$this->email->cc($cc);

$this->email->subject($subject);
$this->email->message($message);
$this->email->send(); 

Dodgy

You override the attribute $email.

Search in the controller/my_controller

$this->email = "examplestring" and attribute $email = "examplestring"
Reply
#7

i can't understand what's your mean by $this->email = "examplestring" and attribute $email = "examplestring"
can you please give me a sample code?

even im doing the same on another project with CI 3.1.5 and it works. idk why is not working in 3.1.8 !
Reply
#8

(04-05-2018, 12:18 AM)ardavan Wrote: i can't understand what's your mean by $this->email = "examplestring" and attribute $email = "examplestring"
can you please give me a sample code?

even im doing the same on another project with CI 3.1.5 and it works. idk why is not working in 3.1.8 !

Hi @ardavan

Can you please print out $this->config and post your response?
"Vision without execution is hallucination"

- What is REST?
Reply
#9

CodeIgniter version 3.1.8 expects all parameters in the from methods to be strings.

I would assign your variables to string variables and then pass them into the email form.
or cast them to a string to see if that works (string) variable.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(04-05-2018, 01:02 AM)farukga Wrote:
(04-05-2018, 12:18 AM)ardavan Wrote: i can't understand what's your mean by $this->email = "examplestring" and attribute $email = "examplestring"
can you please give me a sample code?

even im doing the same on another project with CI 3.1.5 and it works. idk why is not working in 3.1.8 !

Hi @ardavan

Can you please print out $this->config and post your response?

(04-05-2018, 03:31 AM)InsiteFX Wrote: CodeIgniter version 3.1.8 expects all parameters in the from methods to be strings.

I would assign your variables to string variables and then pass them into the email form.
or cast them to a string to see if that works (string) variable.

This is what i got from it and im sure that my from parameter is a String:
Code:
object(CI_Config)#3 (3) {
  ["config"]=>
  &array(54) {
    ["base_url"]=>
    string(22) "http://xx.xx.com/"
    ["index_page"]=>
    string(0) ""
    ["uri_protocol"]=>
    string(11) "REQUEST_URI"
    ["url_suffix"]=>
    string(0) ""
    ["language"]=>
    string(7) "english"
    ["charset"]=>
    string(5) "UTF-8"
    ["enable_hooks"]=>
    bool(false)
    ["subclass_prefix"]=>
    string(0) ""
    ["composer_autoload"]=>
    bool(false)
    ["permitted_uri_chars"]=>
    string(14) "a-z 0-9~%.:_\-"
    ["enable_query_strings"]=>
    bool(false)
    ["controller_trigger"]=>
    string(1) "c"
    ["function_trigger"]=>
    string(1) "m"
    ["directory_trigger"]=>
    string(1) "d"
    ["allow_get_array"]=>
    bool(true)
    ["log_threshold"]=>
    int(4)
    ["log_path"]=>
    string(0) ""
    ["log_file_extension"]=>
    string(0) ""
    ["log_file_permissions"]=>
    int(420)
    ["log_date_format"]=>
    string(11) "Y-m-d H:i:s"
    ["error_views_path"]=>
    string(0) ""
    ["cache_path"]=>
    string(0) ""
    ["cache_query_string"]=>
    bool(false)
    ["encryption_key"]=>
    string(0) ""
    ["sess_driver"]=>
    string(5) "files"
    ["sess_cookie_name"]=>
    string(10) "ci_session"
    ["sess_expiration"]=>
    int(7200)
    ["sess_save_path"]=>
    NULL
    ["sess_match_ip"]=>
    bool(false)
    ["sess_time_to_update"]=>
    int(300)
    ["sess_regenerate_destroy"]=>
    bool(false)
    ["cookie_prefix"]=>
    string(0) ""
    ["cookie_domain"]=>
    string(0) ""
    ["cookie_path"]=>
    string(1) "/"
    ["cookie_secure"]=>
    bool(false)
    ["cookie_httponly"]=>
    bool(false)
    ["standardize_newlines"]=>
    bool(false)
    ["global_xss_filtering"]=>
    bool(true)
    ["csrf_protection"]=>
    bool(false)
    ["csrf_token_name"]=>
    string(14) "csrf_test_name"
    ["csrf_cookie_name"]=>
    string(16) "csrf_cookie_name"
    ["csrf_expire"]=>
    int(7200)
    ["csrf_regenerate"]=>
    bool(true)
    ["csrf_exclude_uris"]=>
    array(0) {
    }
    ["compress_output"]=>
    bool(false)
    ["time_reference"]=>
    string(5) "local"
    ["rewrite_short_tags"]=>
    bool(false)
    ["proxy_ips"]=>
    string(0) ""
    ["from"]=>
    string(16) "[email protected]" // but this is my actual domain
  }
  ["is_loaded"]=>
  array(1) {
    [0]=>
    string(72) "/home1/xx/public_html/um/application/config/application_config.php"
  }
  ["_config_paths"]=>
  array(1) {
    [0]=>
    string(43) "/home1/xx/public_html/um/application/"
  }
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB