CodeIgniter Forums
Message: Call to a member function email->from() on string - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Message: Call to a member function email->from() on string (/thread-70412.html)



Message: Call to a member function email->from() on string - kylmiko - 04-05-2018

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...


RE: Message: Call to a member function email->from() on string - php_rocs - 04-05-2018

@kylmiko,
What values are you expecting for $this->email->from()?


RE: Message: Call to a member function email->from() on string - dave friend - 04-05-2018

(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'); 



RE: Message: Call to a member function email->from() on string - php_rocs - 04-05-2018

@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.


RE: Message: Call to a member function email->from() on string - Paradinight - 04-05-2018

(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-70394-post-352779.html#pid352779


RE: Message: Call to a member function email->from() on string - dave friend - 04-05-2018

(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.


RE: Message: Call to a member function email->from() on string - php_rocs - 04-05-2018

@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.


RE: Message: Call to a member function email->from() on string - kylmiko - 04-09-2018

(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..



RE: Message: Call to a member function email->from() on string - InsiteFX - 04-10-2018

Did you try?

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