0

The directory for my composer and phpmailer.

tree -L 3  /home/bwg
/home/bwg
├── composer.json
├── composer.lock
└── vendor
    ├── autoload.php
    ├── composer
    │   ├── autoload_classmap.php
    │   ├── autoload_namespaces.php
    │   ├── autoload_psr4.php
    │   ├── autoload_real.php
    │   ├── autoload_static.php
    │   ├── ClassLoader.php
    │   ├── installed.json
    │   └── LICENSE
    └── phpmailer
        └── phpmailer
            ├── get_oauth_token.php
            ├── LICENSE
            ├── README.md
            ├── SECURITY.md
            ├── src
            │   ├── Exception.php
            │   ├── OAuth.php
            │   ├── PHPMailer.php
            │   ├── POP3.php
            │   └── SMTP.php
            └── VERSION

I want to send email from vps with phpmailer,save the following code as sendmail.php(part of it,debug part by part),write the code according to webpage here.
HOW TO SEND YOUR FIRST EMAIL WITH PHPMAILER

<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '/home/bwg/vendor/autoload.php';
require '/home/bwg/vendor/phpmailer/phpmailer/src/Exception.php';
require '/home/bwg/vendor/phpmailer/phpmailer/src/SMTP.php';
require '/home/bwg/vendor/phpmailer/phpmailer/src/PHPMailer.php';
$mail = new PHPMailer(TRUE);
?>

Type http://vps_ip/sendmail.php in my browser, come across the problem:

Warning: require(/home/bwg/vendor/autoload.php): failed to open stream: Permission denied in /var/www/html/sendmail.php on line 6

Fatal error: require(): Failed opening required '/home/bwg/vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/sendmail.php on line 6

ls  -al  /home/bwg/vendor
total 20
drwxr-xr-x 4 apache apache 4096 Sep 23 07:55 .
drwx------ 5 bwg    bwg    4096 Sep 23 11:10 ..
-rw-r--r-- 1 apache apache  178 Sep 23 07:55 autoload.php
drwxr-xr-x 2 apache apache 4096 Sep 23 07:55 composer
drwxr-xr-x 3 apache apache 4096 Sep 23 07:55 phpmailer

What is the matter with my require statement?

2
  • 1
    The statement is OK (although is extremely unportable - you should use __DIR__ to build your paths), the problem is in your webserver permissions - it does not have access to this file.
    – rob006
    Sep 23, 2018 at 11:52
  • What rob006 said. You only need to require autoload.php; if you've set up your project with composer correctly, it will load whatever classes it needs dynamically, you don't need to load them explicitly.
    – Synchro
    Sep 23, 2018 at 12:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.