Jump to content

Recommended Posts

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 by vikaspa
Link to comment
https://forums.phpfreaks.com/topic/324786-phpmailer-for-php-8-not-working/
Share on other sites

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.

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  ;

 

  • 5 months later...
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.