Need to install SendGrid in PHP App Service??

MAC 1 Reputation point
2021-10-06T22:20:45.407+00:00

I have a PHP App Service within which I'm trying to send a simple email using SendGrid (as instructed). SendGrid says to use their API. Do I need to install that within my App Service, or does it come pre-loaded?

I'm guessing the former, so how do I install the API as instructed here:
https://docs.sendgrid.com/for-developers/sending-email/v2-php-code-example
Using the console?

Obviously I'm very new to all of this so any basic guidance is very much appreciated!

Azure App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.

0 comments No comments

2 answers

Sort by: Oldest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. MAC 1 Reputation point
    2021-10-11T18:29:43.267+00:00

    I got it to work! After quite a bit of fiddling though...

    FYI, couldn't get your sample code to work, but I was able to use the sample code on the Integration page of SendMail's Dashboard:

    $email = new \SendGrid\Mail\Mail(); 
    $email->setFrom("[email protected]", "Example User");
    $email->setSubject("Sending with SendGrid is Fun");
    $email->addTo("[email protected]", "Example User");
    $email->addContent("text/plain", "and easy to do anywhere, even with PHP");
    $email->addContent(
        "text/html", "<strong>and easy to do anywhere, even with PHP</strong>"
    );
    $sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
    try {
        $response = $sendgrid->send($email);
        print $response->statusCode() . "\n";
        print_r($response->headers());
        print $response->body() . "\n";
    } catch (Exception $e) {
        echo 'Caught exception: '. $e->getMessage() ."\n";
    }
    

    Thanks much!

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.