-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting Up PHPMailer with Microsoft Azure - Encountering Errors #3018
Comments
It seems not to be a PHPMailer error/problem but an OAuth grant problem when utilizing the Azure provider. |
The flow appears to be failing at the point where the refresh token is exchanged for an access token. Worth a quick check to confirm that you are actually giving the provider a refresh token (from running get_oauth_token.php) and not an access token or even an auth code. |
Hello Decomplexity, Just wanted to drop you a quick note to say thank you for your help with the OAuth2 flow issue. Your suggestion to double-check the token type was super helpful, and it got me back on track. I really appreciate your support! Thanks again! Best regards, |
Hello,
I am trying to set up PHPMailer with my Microsoft Azure account, but I am encountering the following errors. Can someone help me resolve the issue?
Here's what I've done so far:
Step 1: Executed the following command to install the required dependencies using Composer:
composer require phpmailer/phpmailer=6.9.1 greew/oauth2-azure-provider=1.0.2
Step 2: Configured the get_oauth_token.php file with the following parameters:
Provider
ClientId
ClientSecret
TenantId
Step 3: Created an index.php file to access the refresh token. After that, I utilized the script available at GitHub, and encountered the following error:
2024-02-13 23:17:31 SERVER -> CLIENT: 220 FR5P281CA0023.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 13 Feb 2024 23:17:31 +0000
2024-02-13 23:17:31 CLIENT -> SERVER: EHLO localhost
2024-02-13 23:17:31 SERVER -> CLIENT: 250-FR5P281CA0023.outlook.office365.com Hello [2a0c:d242:9013:e600:4138:bc71:9423:3ccf]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2024-02-13 23:17:31 CLIENT -> SERVER: STARTTLS
2024-02-13 23:17:31 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2024-02-13 23:17:31 CLIENT -> SERVER: EHLO localhost
2024-02-13 23:17:31 SERVER -> CLIENT: 250-FR5P281CA0023.outlook.office365.com Hello [2a0c:d242:9013:e600:4138:bc71:9423:3ccf]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
Fatal error: Uncaught League\OAuth2\Client\Provider\Exception\IdentityProviderException: AADSTS9002313: Invalid request. Request is malformed or invalid. Trace ID: c1ff9033-06e8-4e51-bb90-c6f5b87e0200 Correlation ID: 03d51264-6938-4a96-af7f-17b8600f759e Timestamp: 2024-02-13 23:17:32Z in C:\MAMP\htdocs\zmaillatest\vendor\greew\oauth2-azure-provider\src\Provider\Azure.php:89 Stack trace: #0 C:\MAMP\htdocs\zmaillatest\vendor\league\oauth2-client\src\Provider\AbstractProvider.php(726): Greew\OAuth2\Client\Provider\Azure->checkResponse(Object(GuzzleHttp\Psr7\Response), Array) #1 C:\MAMP\htdocs\zmaillatest\vendor\league\oauth2-client\src\Provider\AbstractProvider.php(635): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse(Object(GuzzleHttp\Psr7\Request)) #2 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\OAuth.php(115): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\RefreshToken), Array) #3 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\OAuth.php(128): PHPMailer\PHPMailer\OAuth->getToken() #4 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\SMTP.php(618): PHPMailer\PHPMailer\OAuth->getOauth64() #5 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\PHPMailer.php(2262): PHPMailer\PHPMailer\SMTP->authenticate('', '', 'XOAUTH2', Object(PHPMailer\PHPMailer\OAuth)) #6 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\PHPMailer.php(2062): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array) #7 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\PHPMailer.php(1689): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Wed, 14 F...', '--b1=_npek9gfjj...') #8 C:\MAMP\htdocs\zmaillatest\vendor\phpmailer\phpmailer\src\PHPMailer.php(1523): PHPMailer\PHPMailer\PHPMailer->postSend() #9 C:\MAMP\htdocs\zmaillatest\index.php(154): PHPMailer\PHPMailer\PHPMailer->send() #10 {main} thrown in C:\MAMP\htdocs\zmaillatest\vendor\greew\oauth2-azure-provider\src\Provider\Azure.php on line 89
2024-02-13 23:17:32 CLIENT -> SERVER: QUIT
2024-02-13 23:17:32 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
Any assistance or guidance on resolving these errors would be greatly appreciated. Thank you in advance for your support!
Best regards,
Siva Matta
The text was updated successfully, but these errors were encountered: