tsvetko.krastev
tsvetko.krastev

Reputation: 77

Problem with PHPMailer: require(): Failed opening required

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.

Upvotes: 0

Views: 10412

Answers (2)

Rahul juneja - DevOps
Rahul juneja - DevOps

Reputation: 790

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.

Upvotes: 1

Synchro
Synchro

Reputation: 37730

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.

Upvotes: 0

Related Questions