CodeIgniter Forums

Full Version: Message: Call to a member function email->from() on string
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please help...

I have 2 controllers

first controller is home

and my sendemail method is working and no problem at all but when I copy the same method to user controller it keeps  me getting an error "Message: Call to a member function email->from() on string"  heres my method...

public function sendEmail($email,$link){ 
          $message = "Hi"

           $subject = "hello message";

       $this->load->library('email');
       $this->load->helper(array('email'));

        $this->email->from('email@gmail.com', 'Email');
        $this->email->to($email);
        $this->email->subject($subject);
        $this->email->message($message);
        $this->email->set_mailtype("html");
        if($this->email->send())
        return true;
        else
        return false;
        }

I am looking forward to your positive response thank you so much...
@kylmiko,
What values are you expecting for $this->email->from()?
(04-05-2018, 09:56 AM)php_rocs Wrote: [ -> ]@kylmiko,
What values are you expecting for $this->email->from()?

Looks to me like he is using the string literals 'email@gmail.com' and 'Email' in the call.

PHP Code:
$this->email->from('email@gmail.com''Email'); 
@dave friend,

I am trying to ask what are the specific values that the from method is expecting. It could be a case of wrong values that are causing the error.
(04-05-2018, 08:00 AM)kylmiko Wrote: [ -> ]Please help...

I have 2 controllers

first controller is home

and my sendemail method is working and no problem at all but when I copy the same method to user controller it keeps  me getting an error "Message: Call to a member function email->from() on string"  heres my method...

public function sendEmail($email,$link){ 
          $message = "Hi"

           $subject = "hello message";

       $this->load->library('email');
       $this->load->helper(array('email'));

        $this->email->from('email@gmail.com', 'Email');
        $this->email->to($email);
        $this->email->subject($subject);
        $this->email->message($message);
        $this->email->set_mailtype("html");
        if($this->email->send())
        return true;
        else
        return false;
        }

I am looking forward to your positive response thank you so much...

https://forum.codeigniter.com/thread-703...#pid352779
(04-05-2018, 10:24 AM)php_rocs Wrote: [ -> ]@dave friend,

I am trying to ask what are the specific values that the from method is expecting.  It could be a case of wrong values that are causing the error.

The method CI_Email::from() accepts three arguments, all three are strings, the second and third arguments are optional. Read the docs. Nothing happens in the method that would produce the error described.

That error message would seem to indicate that the variable $this->email is a string and not an instance of the CI_Email class. How that occurs is not determinable in the code the OP provides.
@kylmiko,
I'm wondering if you even need this helper when you have already loaded the library [ $this->load->helper(array('email')); ]. This may be causing a conflict.

@dave friend,
I did a quick browse and didn't know if he was using a custom library.
(04-05-2018, 12:05 PM)dave friend Wrote: [ -> ]
(04-05-2018, 10:24 AM)php_rocs Wrote: [ -> ]@dave friend,

I am trying to ask what are the specific values that the from method is expecting.  It could be a case of wrong values that are causing the error.

The method CI_Email::from() accepts three arguments, all three are strings, the second and third arguments are optional. Read the docs. Nothing happens in the method that would produce the error described.

That error message would seem to indicate that the variable $this->email is a string and not an instance of the CI_Email class. How that occurs is not determinable in the code the OP provides.

I just found the error by myself and you are totally correct.. I accidentally assign $this->email as a string somewhere in my code and I ddn't notice that... 

Thank you for your reply.... highly appreciated.. I can say your reply is the answer to my problem... thank you very much..
Did you try?

PHP Code:
$this->email->initialize($config);