This project is being archived and replaced with the Build PHP apps with Microsoft Graph. As part of the archival process, we're closing all open issues and pull requests.
You can continue to use this sample "as-is", but it won't be maintained moving forward. We apologize for any inconvenience.
This sample shows how to connect a PHP web app to a Microsoft work or school (Azure Active Directory) or personal (Microsoft) account using the Microsoft Graph API to send an email. It uses the Microsoft Graph PHP Client Library to work with data returned by Microsoft Graph. In addition, the sample uses the Office Fabric UI for styling and formatting the user experience.
This sample requires the following:
- Either a Microsoft account or Office 365 for Business account. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building Office 365 apps.
- PHP 5.6^ or 7
- Composer, a dependency manager for PHP
-
Sign in to the App Registration Portal using either your personal, work, or school account.
-
Choose Add an app
-
Enter a name for the app and choose Create application.
The registration page displays, listing the properties of your app.
-
Copy the Application ID. This is the unique identifier for your app.
-
Under Application Secrets, choose Generate New Password. Copy the password from the New password generated dialog.
You'll use the application ID and password to configure the sample app in the next section.
-
Upder Platforms, choose Add platform.
-
Choose Web.
-
Make sure the Allow Implicit Flow check box is selected, and enter http://localhost:8000/oauth.php as the Redirect URI.
The allow Implicit Flow option enables the hybrid flow. During authentication, this enables the app to receive both sign-in info (the id_token) and artifacts (in this case, an authorization code) that the app can use to obtain an access token.
-
Choose Save.
-
Download or clone the Microsoft Graph Connect Sample for PHP
-
Open the sample solution in your favorite IDE.
-
In the graph.php file in the config directory, replace the ENTER_YOUR_CLIENT_ID and ENTER_YOUR_SECRET placeholder values with the application ID and password you copied during registration.
-
Install the project's dependencies:
composer install
-
Rename .env.example to .env and run
php artisan key:generate
-
Run
php artisan serve
to run the sample. -
Navigate to
http://localhost:8000
in your web browser. -
Sign in with your account and grant the requested permissions.
-
Choose the Get email address button. When the operation completes, the email address of the signed-in user is displayed on the page.
-
Optionally edit the recipient list and email subject, and then choose the Send email button. When the mail is sent, a success message is displayed below the button.
You receive the following error after providing your credentials to the sign in page.
SSL certificate problem: unable to get local issuer certificate
cURL can't verify the validity of the Microsoft certificate when trying to issue a request call to get tokens. You must configure cURL to use a certificate when issuing https requests by following these steps:
-
Download the cacert.pem file from cURL website.
-
Open your php.ini file and add the following line
curl.cainfo = "path_to_cacert/cacert.pem"
This sample helps get you registered and making calls to Microsoft Graph. You can now try different calls using the Microsoft Graph library for PHP. Explore the Microsoft Graph documentation to see what you can do with your favorite Microsoft products. You can try:
- Copying a OneDrive file to another folder
- Performing cell functions with Excel
- Navigating your organization's directory
- Paging through a list of emails
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
We'd love to get your feedback about the PHP Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.
Questions about Microsoft Graph development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [MicrosoftGraph] and [API].
- Microsoft Graph
- Office 365 APIs platform overview
- Getting started with Office 365 APIs
- Office UI Fabric
Copyright (c) 2016 Microsoft. All rights reserved.