Web lists-archives.com

[PHP] Re: PHP cannot use a provided class




On 20.03.2018 at 21:37, James Moe wrote:

>   php v5.6.34
> 
>   I am working on a very simple PHPMailer; all it has to do is send an
> email. I am using the latest version from the Github repository, v6.0.3.
>   Running the program produces this:
> 
> Fatal error: Class 'PHPMailer' not found in
> /home/sohne/web/php/common/php-test-email.php on line 44
> 
>     //Import the PHPMailer class into the global namespace
>     // use PHPMailer\PHPMailer\PHPMailer;

Either properly import the class:

  use PHPMailer\PHPMailer;

>     $from = 'sma.info@xxxxxxxxxxxxxx';
> 
>     $to = $sendto;
>     $replyto = 'moe.james@xxxxxxxxxxxxxx';
>     $cc = '';
>     $bcc = '';
> 
>     // use PHPMailer;
> 
>     $mail = new PHPMailer();

Or use the fully qualified class name:

  $mail = new \PHPMailer\PHPMailer;

See also the chapter about namespaces in the PHP manual:
<http://www.php.net/manual/en/language.namespaces.php>

-- 
Christoph M. Becker

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php