Web lists-archives.com

[PHP] Re: PHP cannot use a provided class




On 21.03.2018 at 05:58, James Moe wrote:

> On 03/20/2018 03:14 PM, Christoph M. Becker wrote:
> 
>>>     //Import the PHPMailer class into the global namespace
>>>     // use PHPMailer\PHPMailer\PHPMailer;
>> Either properly import the class:
>>
>>   use PHPMailer\PHPMailer;
>>
>   Using the above causes the script to silently abort. No messages, nothing.
> 
>>>
>>>     $mail = new PHPMailer();
>> Or use the fully qualified class name:
>>
>>   $mail = new \PHPMailer\PHPMailer;
>>
>   This yields the message:
> 
> Fatal error: Class 'PHPMailer\PHPMailer' not found in
> /home/sohne/web/php/common/php-test-email.php on line 44

Sorry, forget that.  Actually, the class PHPMailer is contained in the
PHPMailer\PHPMailer namespace, so you need the triple

  $mail = new \PHPMailer\PHPMailer\PHPMailer;

>> See also the chapter about namespaces in the PHP manual:
>> <http://www.php.net/manual/en/language.namespaces.php>
>>
>   Apparently php.net is having issues. The page persistently times out.

Hmm, works for me.  The issue might be intermittent, or maybe there is
something wrong with the geolocation and/or a certain mirror.  Try:

  <http://us2.php.net/manual/en/language.namespaces.php>
  <https://secure.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