我的要求声明调用phpmailer有什么问题?

时间:2018-09-23 09:12:20

标签: php composer-php phpmailer

我的作曲家和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

我想使用phpmailer从vps发送电子邮件,将以下代码另存为sendmail.php(部分,部分调试),在此处根据网页编写代码。
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);
?>

在我的浏览器中输入http://vps_ip/sendmail.php,遇到问题:

  

警告:require(/home/bwg/vendor/autoload.php):无法打开流:在第6行的/var/www/html/sendmail.php中权限被拒绝

     

严重错误:require():无法在/ var /中打开所需的'/home/bwg/vendor/autoload.php'(include_path ='。:/ usr / share / pear:/ usr / share / php')第6行的www / html / sendmail.php

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

我的require语句怎么了?

1 个答案:

答案 0 :(得分:-1)

$ mail =新的PHPMailer \ PHPMailer \ PHPMailer();

要在我的vps中创建与op类似的环境。

添加用户bwg及其密码。

useradd -d /home/bwg -m bwg -s /bin/bash
passwd bwg

bwg添加sudo权限。

visudo -f /etc/sudoers
bwg ALL=(ALL) NOPASSWD:ALL

安装作曲家和phpmailer

su bwg
cd  /home/bwg
sudo yum install composer
sudo composer require phpmailer/phpmailer

要检查new PHPMailer();

 php -a
Interactive shell

php > use PHPMailer\PHPMailer\PHPMailer;
php > use PHPMailer\PHPMailer\Exception;
php > require '/home/bwg/vendor/autoload.php';
php > require '/home/bwg/vendor/phpmailer/phpmailer/src/Exception.php';
php > require '/home/bwg/vendor/phpmailer/phpmailer/src/SMTP.php';
php > require '/home/bwg/vendor/phpmailer/phpmailer/src/PHPMailer.php';
php > $mail = new PHPMailer();
PHP Warning:  Uncaught Error: Class 'PHPMailer' not found in php shell code:1
Stack trace:
#0 {main}
  thrown in php shell code on line 1

要检查PHPMailer\PHPMailer\PHPMailer()

php -a
Interactive shell

php > use PHPMailer\PHPMailer\PHPMailer;
php > use PHPMailer\PHPMailer\Exception;
php > require '/home/bwg/vendor/autoload.php';
php > require '/home/bwg/vendor/phpmailer/phpmailer/src/Exception.php';
php > require '/home/bwg/vendor/phpmailer/phpmailer/src/SMTP.php';
php > require '/home/bwg/vendor/phpmailer/phpmailer/src/PHPMailer.php';
php > $mail = new PHPMailer\PHPMailer\PHPMailer();
php >