php - using namespace -


i want use minimal features of phpmailer. folder structure:

webroot/   - php/      - mail.php      - phpmailer/          - phpmailer.php 

in mail.php, want use namespace:

<?php use phpmailer\phpmailer; $mail = new phpmailer(true); ... 

but got error:

fatal error: class 'phpmailer\phpmailer' not found in /home/example/public_html/php/mail.php on line 2

how can resolve this?

  1. create include.php file.

      $librarypath = "/webroot/php";   set_include_path(get_include_path() . path_separator . $librarypath); ?> 

*where $libarypath path of php folder contains phpmailer folder

  1. in phpmailer.php include

        namespace phpmailer;      class phpmailer(){     .....     }     ?> 
  2. in mail.php include require can instantiate phpmailer\phpmailer

    require ('include.php');  use phpmailer\phpmailer; 

you can add more class inside php folder , can define namespaces following #2.

you can call them in new pages including 'include.php' , instantiating class.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -