Welcome Guest, Not a member yet? Register   Sign In
Message: Call to a member function email->from() on string
#1

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 protected]', '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...
Reply
#2

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

(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 protected]' and 'Email' in the call.

PHP Code:
$this->email->from('[email protected]''Email'); 
Reply
#4

@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.
Reply
#5

(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 protected]', '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
Reply
#6

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

(This post was last modified: 04-05-2018, 01:41 PM by php_rocs.)

@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.
Reply
#8

(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..
Reply
#9

Did you try?

PHP Code:
$this->email->initialize($config); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB