0

I have a problem with setting up PHPMailer. It was working before, but now all of a sudden it stopped and this is the error I'm getting: PHP Fatal error: require(): Failed opening required '../src/PHPMailer.php' (include_path='.:/opt/cpanel/ea-php53/root/usr/share/pear:/opt/cpanel/ea-php53/root/usr/share/php') in /home/pandatra/site.com/contacts_form/contact_form.php on line 9

Here is the code in contact_form.php:

<?php

    include 'config.php';

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    use PHPMailer\PHPMailer\SMTP;

    require ''.$d['include_path'].'PHPMailer/src/Exception.php';
    require ''.$d['include_path'].'PHPMailer/src/PHPMailer.php';
    require ''.$d['include_path'].'PHPMailer/src/SMTP.php';
    
    $mail = new PHPMailer(true);

  if (isset($_POST['Send'])) {

How to fix this? Any ideas? I downloaded version 6.1.7 of PHPMailer.

tsvetko.krastev
  • 69
  • 1
  • 12

2 Answers2

1

The error you mentioned is that, the path in your require is getting Wrong. To avoid this type of problem , you should always use absolute path

e.g.

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

   # use "use" after include or require

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    use PHPMailer\PHPMailer\SMTP;

__DIR__ is the absolute path of running file's directory.

0

Here's the problem:

I just replaced the old version with the new one

If you upgraded from 5.x to 6.x, you needed to read either the readme, the upgrade guide, or this question and answer that was specifically created to deal with this issue.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • Hey thanks for the answer. I downloaded PHPMailer 5.2 - Stable and using the examples in GutHub I get this: – tsvetko.krastev Aug 17 '20 at 08:55
  • Don't use 5.2 for any new development. All the examples are for the current version (6.x) and will not work with old (5.x) versions. – Synchro Aug 17 '20 at 08:56
  • Here is the error I'm getting `Warning: require(/contacts_form/PHPMailer/PHPMailerAutoload.php): failed to open stream: No such file or directory in /home/pandatra/nordinterior.com/contacts_form/contact_form.php on line 5 Fatal error: require(): Failed opening required '/contacts_form/PHPMailer/PHPMailerAutoload.php' (include_path='.:/opt/cpanel/ea-php53/root/usr/share/pear:/opt/cpanel/ea-php53/root/usr/share/php') in /home/pandatra/nordinterior.com/contacts_form/contact_form.php on line 5` – tsvetko.krastev Aug 17 '20 at 08:57
  • Please read the docs I pointed you at. The files you are trying to load no longer exist. – Synchro Aug 17 '20 at 08:57
  • Here is my code: `include 'config.php'; require ''.$d['include_path'].'PHPMailer/PHPMailerAutoload.php'; $mail = new PHPMailer(true);` I downloaded PHPMailer 5.2 Stable from github and this my results. – tsvetko.krastev Aug 17 '20 at 08:58
  • 1
    Just stop. I'm not going to help you use an obsolete version. – Synchro Aug 17 '20 at 08:58