来自heroku中应用程序的错误:“需要(供应商\自动加载. php):无法打开流:无此文件或目录”

mi7gmzs6  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(94)

我做了一个php应用程序,使用phpmailer从html表单发送电子邮件。这在localhost上工作得很好(使用MAMP),所以我决定把它们上传到github,然后部署到heroku上(我选择“github”对我的heroku部署方法)。我上传几乎所有的东西,除了包含“autoload.php”文件的供应商文件夹,因为从浏览这个论坛的问题,这是不建议也不推荐的,并且假设heroku在从composer.json文件中检测到phpmailer后会创建这些文件。所以在我将所有这些文件上传到github并在heroku上部署页面后,我的页面工作正常,除了mailer功能不再工作,并显示以下错误:
警告:需要(供应商\autoload.php):无法打开流:/app/email. php中没有这样的文件或目录
致命错误:未捕获的错误:在/app/email.php中打开所需的“vendor\autoload.php”失败(include_path =“.:”)。php:11堆栈跟踪:在/app/email. php中的第11行抛出了#0 {main}
我试着在heroku中检查构建日志,但是没有错误,尽管它确实有一些注意事项(不确定这是否相关,但我将把它放在这里以防万一)。下面是我的日志输出:

-----> Building on the Heroku-22 stack
-----> Using buildpack: heroku/php
-----> PHP app detected
-----> Bootstrapping...
-----> Preparing platform package installation...
       NOTICE: No runtime required in composer.json; requirements
       from dependencies in composer.lock will be used for selection
-----> Installing platform packages...
       - apache (2.4.54)
       - php (8.1.11)
       - composer (2.4.2)
       - nginx (1.22.0)
-----> Installing dependencies...
       Composer version 2.4.2 2022-09-14 16:11:15
       Installing dependencies from lock file
       Verifying lock file contents can be installed on current platform.
       Package operations: 1 install, 0 updates, 0 removals
         - Installing phpmailer/phpmailer (v6.6.5): Extracting archive
       Generating optimized autoload files
       1 package you are using is looking for funding.
       Use the `composer fund` command to find out more!
-----> Preparing runtime environment...
       NOTICE: No Procfile, using 'web: heroku-php-apache2'.
-----> Checking for additional extensions to install...
-----> Discovering process types
       Procfile declares types -> web
-----> Compressing...
       Done: 17.1M
-----> Launching...
       Released v9
       https://ezrawibowo.herokuapp.com/ deployed to Heroku
Starting November 28th, 2022, free Heroku Dynos, free Heroku Postgres, and free Heroku Data for Redis® will no longer be available.
If you have apps using any of these resources, you must upgrade to paid plans by this date to ensure your apps continue to run and to retain your data. For students, we will announce a new program by the end of September. Learn more at https://blog.heroku.com/next-chapter

这是我的 composer Json:

{
    "require": {
        "phpmailer/phpmailer": "^6.6"
    }
}

可能有一些明显的东西我错过了,因为无可否认这是我第一次使用heroku,但我已经试图搜索它的heroku应用程序和谷歌我的问题,似乎没有找到具体的解决方案,这种情况下。任何帮助将不胜感激。
先谢谢你!

tzxcd3kk

tzxcd3kk1#

更新

我找到了解决方案。通过编辑我的电子邮件中的这一行。php:

require 'vendor\autoload.php';

更改为:

require __DIR__ . '/vendor/autoload.php';

它解决了这个问题。我的电子邮件功能现在工作正常。

相关问题