skip to Main Content

This code works in every browser except Firefox and I can’t seem to find out why. I have tried to require all the way back to the root dir, but it still throws me the error:

“Fatal error: require(): Failed opening required
‘PHPMailer/src/PHPMailer.php’
(include_path=’.:/opt/cpanel/ea-php70/root/usr/share/pear’)”

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

2

Answers


  1. Your browser has no influence over how paths work on your server.

    Most simply, you do not have the correct path in your require statement.

    However, I would recommend using composer and its autoload script to bring PHPMailer into your project.

    Login or Signup to reply.
  2. Firefox should NOT be able to influence any of this.

    Checking whether none of your browsers cache old/new version

    Try:

    • clearing history and cache and reloading (hard reload Ctrl+Shift+R or Shift+F5)
    • opening it in a Private window (Ctrl+Shift+P) (names and shortcuts vary across browsers)
    • checking the URL (you may have loaded an old URL from history) and making sure you have the right one
    • checking the protocol (http vs https) and making sure you have the right one

    If any of these steps help, it definitely isn’t Firefox’ issue.

    Is it a simple page you open, or do you rely on GET or POST variables? Is there any chance other browsers have cached an older, working version, and only Firefox shows the current broken results? Try renaming the file to something you haven’t had there before and re-opening it, or the steps I listed on other browsers.

    Checking whether you are editing the right file

    When I get weird behavior like this, I usually try editing the file to show something different (like echo "current file <br>"; at the beginning of the PHP file) first to see for sure I am opening the right file from everywhere and the changes to code take effect. I’ve had lots of such problems and it usually were switching underscore and dash, opening from production server instead of development one, etc. It’s a nightmare when your debugging can’t seem to work whatever you do and in the end you find out you didn’t do anything at all (to the file you were opening).

    Including absolute path

    This won’t help with the “Why only Firefox” question, but you might want to use absolute path to be safe when including, or relative to your current folder.

    Instead of

    require 'PHPMailer/src/PHPMailer.php';
    

    try

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

    or

    require __DIR__ . '/PHPMailer/src/PHPMailer.php';
    // __DIR__ is a Magic constant showing directory of currently running script (if included, then path of included one)
    // see http://php.net/manual/en/language.constants.predefined.php
    

    or

    require $_SERVER['DOCUMENT_ROOT'] . '/includes/PHPMailer/src/PHPMailer.php';
    // DOCUMENT_ROOT is the root directory of your web, like /var/www/html/site.com
    

    so the parser doesn’t look for the file in your include path (unless that is where your PHPMailer is located).

    Also, I’d use require_once rather than require when loading libraries.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search