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.