ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to use $this->EE in a php file

January 20, 2014 5:52am

Subscribe [2]
  • #1 / Jan 20, 2014 5:52am

    W3 | 84ideas

    22 posts

    Hi All,
     
      I have a requirement to send a mail to admin about something based on a table value,for which I wrote a code in php file and placed this in one of the template,please check sample code

    $this->EE->load->library('email');
        $this->EE->email->initialize(array(
         'mailtype' => 'html',
         'validate' => TRUE,
        ));

    When I run the template (http://example.com/sendmail) in a browser everything works ok,but when I added this template in the cron job list I am getting an error from my host that its unable to find the file or directory,please check

    /bin/sh: <a href="http://example.com/sendmail">http://example.com/sendmail</a>: No such file or directory


      Then I tried creating a folder at my root and placed that php code in a file,now when I checked that file in the browser,I am getting an error like

    Fatal error: Using $this when not in object context in /home/s23betawbr/public_html/site/cron/communication/sendmails.php on line 32

      I think I am not able to use $this->EE in a php file,can anyone please help me out how about how to use EE super object outside templates like in any php file.

    OR how to add the cron job when the code is in a template

     

    Thanks in advance

    Cheers!!

     

  • #2 / Jan 21, 2014 5:23am

    Giraffentoast

    152 posts

    Hello W3,

    I’m no cron job expert, but you’ll most probably need to replace that URL with a path.

    Like:

    /home/s23betawbr/public_html/site/cron/communication/sendmails.php

    And yes, you won’t be able to use EE class methods outside EE scope (in php files for example).

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases