Save the follow as send.php,it can be executed with php -f send.php
or 127.0.0.1/send.php
, no error info as output.
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once('/home/debian9/vendor/autoload.php');
$mail = new PHPMailer();
?>
The use statements import the namespaced PHPMailer class into the global scope, so do not need to use a FQCN( Fully-Qualified Class Name) such as $mail = new PHPMailer\PHPMailer\PHPMailer();
here,just $mail = new PHPMailer();
is enough.
Open a php shell with php -a.
php > use PHPMailer\PHPMailer\PHPMailer;
php > use PHPMailer\PHPMailer\Exception;
php > require '/home/debian9/vendor/autoload.php';
php > $mail = new PHPMailer(true);
PHP Warning: Uncaught Error: Class 'PHPMailer' not found in php shell code:1
Stack trace:
#0 {main}
thrown in php shell code on line 1
Why $mail = new PHPMailer(true);
can't import the namespaced PHPMailer class into the global scope in php shell?
You must write $mail = new PHPMailer\PHPMailer\PHPMailer();
in php shell.