vikaspa Posted October 13, 2024 Share Posted October 13, 2024 (edited) Dear Respected i had installed phpmailer using composer logged in to cpanel used Terminal to install phpmailer command (@terminal) composer require phpmailer/phpmailer (help found in https://packagist.org/packages/phpmailer/phpmailer ) After installation, I had used following php code to send email require('vendor/autoload.php'); require "vendor/phpmailer/phpmailer/src/PHPMailer.php"; require "vendor/phpmailer/phpmailer/src/OAuth.php"; require "vendor/phpmailer/phpmailer/src/SMTP.php"; require "vendor/phpmailer/phpmailer/src/POP3.php"; require "vendor/phpmailer/phpmailer/src/Exception.php"; // use vendor/phpmailer/phpmailer/src //require "vendor/phpmailer/phpmailer/src/PHPMailer"; $mail = new PHPMailer ; $mail->IsSMTP(); // telling the class to use SMTP $mail->SMTPAuth = true; Error Uncaught Error: Class "PHPMailer" not found <in path here> pls help me to solve this issue Edited October 13, 2024 by vikaspa Quote Link to comment https://forums.phpfreaks.com/topic/324786-phpmailer-for-php-8-not-working/ Share on other sites More sharing options...
requinix Posted October 13, 2024 Share Posted October 13, 2024 The only require you need is for vendor/autoload.php. Remove the others. "PHPMailer" is the name of the class, yes, but it also exists in a namespace. Do you have at least this particular use statement use PHPMailer\PHPMailer\PHPMailer; at the top of your file? I'm grabbing that directly from the packagist.org page you linked to. Quote Link to comment https://forums.phpfreaks.com/topic/324786-phpmailer-for-php-8-not-working/#findComment-1637476 Share on other sites More sharing options...
vikaspa Posted October 13, 2024 Author Share Posted October 13, 2024 Thanks for reply i tried but resulted in syntax error, unexpected token "use" use PHPMailer\PHPMailer\PHPMailer; require 'vendor/autoload.php'; //Create a new PHPMailer instance $mail = new PHPMailer(); /* require "vendor/phpmailer/phpmailer/src/PHPMailer.php"; require "vendor/phpmailer/phpmailer/src/OAuth.php"; require "vendor/phpmailer/phpmailer/src/SMTP.php"; require "vendor/phpmailer/phpmailer/src/POP3.php"; require "vendor/phpmailer/phpmailer/src/Exception.php"; */ // use vendor/phpmailer/phpmailer/src // require "vendor/phpmailer/phpmailer/src/PHPMailer"; //$mail = new PHPMailer ; Quote Link to comment https://forums.phpfreaks.com/topic/324786-phpmailer-for-php-8-not-working/#findComment-1637508 Share on other sites More sharing options...
Barand Posted October 13, 2024 Share Posted October 13, 2024 When something is "unexpected" the cause is usually whatever came before it. But you haven't shown us that. Quote Link to comment https://forums.phpfreaks.com/topic/324786-phpmailer-for-php-8-not-working/#findComment-1637510 Share on other sites More sharing options...
gizmola Posted March 28 Share Posted March 28 On 10/13/2024 at 4:11 AM, Barand said: When something is "unexpected" the cause is usually whatever came before it. But you haven't shown us that. To add to Barand's comment, your use statements need to be at the top of the file. This is literally the instructions from the project github page at https://github.com/PHPMailer/PHPMailer <?php //Import PHPMailer classes into the global namespace //These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; //Load Composer's autoloader require 'vendor/autoload.php'; We do not know if this will actually work because we don't have any idea what your project layout is. For example, if your project webroot is /public, then these instructions won't work, because your path to the vendor/autoload.php would need to be: require '../vendor/autoload.php'; Using require will generate an error if the required file can not be located. Quote Link to comment https://forums.phpfreaks.com/topic/324786-phpmailer-for-php-8-not-working/#findComment-1652308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.