0

I saw the other threads on this topics, but none of the proposed solutions seems to work for me. This is my code for sending mails with attachment:

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';

require_once('class.phpmailer.php');    
$send_mail = new PHPMailer();
$send_mail->From = "classiperlo2@altervista.org";
$send_mail->FromName = "classiperlo2";
$send_mail->Subject = "Backup";
$send_mail->Body = "Backup";
$send_mail->AddAddress("mymail@gmail.com");

$attach_file = $file;
$send_mail->AddAttachment($attach_file);

return $send_mail->Send();

I previously uploaded the folder containing PHPMaster files on the server (as downloaded from Github; the path is correct). But it doesn't work! It doesn't send any mail at all.

I really don't know what to do. Please, if you can, explain me in a simple way!

Thanks so much Giancarlo

Giancarlo
  • 13
  • 4

1 Answers1

0

If you downloaded the latest version and still have this line:

require_once('class.phpmailer.php');  

your script will fail with a fatal error because that file has not existed in PHPMailer for years.

Without any error output it's hard to be any more accurate. Also, instead of basing your code on the examples provided with PHPMailer, you've written your own with no error checking at all, so you'll never know when or why it dies.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • I deleted require_once. The script stops after $send_mail = new PHPMailer(). This instruction is not executed or causes a fatal error. Since this happens before using $send_mail, I don't know how to see the error code. – Giancarlo Aug 24 '21 at 08:32
  • Errors will be in your web servers error log. You are missing `use` statements that import the `PHPMailer` class into the global namespace, so the `PHPMailer` class won't appear to exist when you try to create an instance, which is a fatal error. It would help if you read the docs and based your code on the examples provided as they do all this basic stuff correctly. – Synchro Aug 24 '21 at 09:11
  • Thanks for your kind answer. I read the document and I tried putting the lines use PHPMailer\PHPMailer\PHPMailer and use PHPMailer\PHPMailer\Exception at the beginning of my php file, but with no result. I am giving up. Thank you again in any case! – Giancarlo Aug 24 '21 at 09:23