dongnue4923 2016-02-19 20: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-21 19: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.

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部