dongnue4923 2016-02-20 04:54
浏览 58

PHP脚本无法访问Azure网站的“Vendor”文件夹

Background:

I am using Azure App Services to host a php website. I’m new to Azure and PHP (programming in general for that matter). As a starting point I have been following a set of PHP tutorials. The tutorial that I am currently on requires that I use the PHP mail function, however this fails, and from what I’ve read it is because I need to use the SendGrid mail service when working with an Azure hosted website.

Steps Taken:

First I installed SendGrid from the Azure market place. I then installed Composer to my project directory (‘wwwroot’) followed by installing the dependencies. I tried using both ‘sendgrid/smtpapi’ and ‘sendgrid/sendgrid-php’ as dependencies in the ‘composer.json’ file. The installations appeared successful and the “Vendor” folder (in “wwwroot”) updated with files for “Composer” and “SendGrid”.

I tried a number of code examples for SendGrid but decided to stick with the one below (it seems simpler)

// using SendGrid's PHP Library
// https://github.com/sendgrid/sendgrid-php

require 'vendor/autoload.php';

$sendgrid = new SendGrid("SENDGRID_APIKEY");

$email    = new SendGrid\Email();

$email->addTo("test@sendgrid.com")
      ->setFrom("you@youremail.com")
      ->setSubject("Sending with SendGrid is Fun")
      ->setHtml("and easy to do anywhere, even with PHP");

$sendgrid->send($email);

**Problem:**Error’. When I look at the detailed error logs I get a further error ‘HTTP Error 404.0 - Not Found’.

I know that the file ‘vendor/autload.php’ required by the mail script does exist

When I run the website the mail script breaks with a ‘500.0 - Internal Server as I can see it from the FTP portal.

However, if I try to browse to the ‘Vendor’ folder via the ‘Kudu’ site, a “Session Expired” error occurs (strangely it only happens for this specific folder). Internet Explorer developer tools show a further error of “403 Forbidden - Access Denied’

Conclusion:

It is my conclusion that the mail script breaks because it cannot access the files required from the ‘Vendor’ folder. I however do not know why or how to work around this. Any recommendations will be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douhao6271 2016-02-22 03:05
    关注

    As I created a new test project on Azure Web Apps to send emails via SendGird SDK. I didn't reproduce your issue, here are my steps to build the SendGird project, FYI:

    • Install Visual Studio Online extension and Composer extension of the Azure Web Apps for easy developing and management. You can refer the answer of How to install composer on app service? for the steps to install the extensions
    • Create the composer.json file in the root directory of the application. The content of the file:

    { "require": { "sendgrid/sendgrid": "~4.0" } }

    • Open Console the run the command composer install to install the dependency.

    My test code is the same with you, and it works fine on my side. you can try these steps.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用