Skip to content
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

PHPMailer gmail_xoauth.phps example from github #677

Closed
renardrouge opened this issue Apr 6, 2016 · 67 comments
Closed

PHPMailer gmail_xoauth.phps example from github #677

renardrouge opened this issue Apr 6, 2016 · 67 comments

Comments

@renardrouge
Copy link

I have been trying to get the gmail_xoauth.phps example running from the github site for a number of days now following these instructions.

https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2

I have repeated the instructions faithfully and googled the error and followed the suggestions on this forum to no avail.

I always end with "SMTP ERROR: AUTH command failed: 334".

(The format presented at the google developers site is now slightly different from that shown in the instructions.)

The only difference from the instructions up to the point of failure is the absence of
250-CHUNKING in the SERVER -> CLIENT response.

Here is my current state. Can anyone offer suggestions as to how I can get closer to a solution ?
(confidential information replaced by xxxxx)

The following change was made to php.ini to get to this point.
[cURL] curl.cainfo = C:\xampp\php\cacert.pem

This code was also added to gmail_xoauth.php

// LAD, 2016-04-05 // unsecure fix for "Warning: stream_socket_enable_crypto(): SSL operation failed with code 1"
// see #368

$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);

php version = 5.6.15
PHPMailer version = 5.2.14
Apache version = Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.15


redo steps at https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2

https://console.developers.google.com/project

Create project
project name: phpmailer3
project id: phpmailer3-1273
app engine location: us-central

Google APIs
click Gmail API
click Enable Gmail API
This API is enabled, but you can't use it in your project until you create credentials.
Click "Go to Credentials" to do this now (strongly recommended).

Now select Credentials from the left-hend menu, then click the Create new Client ID button:

click Create Credentials button
Which API ? Gmail API
Calling API from ? Web Server
What data ? User data

click 'What credentials do I need ?'
Calling Gmail API from a web server

2 Create an OAuth 2.0 client ID
name: phpmailer3
authorized redirect uri: https://localhost/phpmailer2/get_oauth_token.php

click 'Create client ID'
Created OAuth client 'phpmailer3'
Email address '[email protected]'
Product name shown to users 'PHPMailer3'

click 'Continue'
Download credentials
Client ID
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com

    Download this credential information in JSON format. 

click 'Download'
    client_id.json is downloaded

paste the new values into get_oauth_token.php
$redirectUri = 'http:https://localhost/phpmailer2/get_oauth_token.php';
$clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com';
$clientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxx';

Fetch the token with get_oauth_token.php
Refresh Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

paste the new values into gmail_xoauth.php and try again


SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 31sm483745ioj.17 - gsmtp
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [xx.xxx.xxx.xx]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [xx.xxx.xxx.xx]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
CLIENT -> SERVER: AUTH XOAUTH2 dXNlcj1sb3JuZWR1ZGxleUBnbWFpbC5jb20BYXV0aD1CZWFyZXIgeWEyOS4udkFKeDE1U1plODFQOHlQLWMwN29qMDFjM0VtT3ZFTTlUMFVHZzV6bFF0dkRUQ0poaWdIVXUydl9fQk1uOGstVDRRAQE=
SERVER -> CLIENT: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 31sm483745ioj.17 - gsmtp
SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 31sm483745ioj.17 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@renardrouge
Copy link
Author


OK, a little progress, but can anyone advise where to go from here ??? I executed get_auth_token.php again, received a new Refresh Token, which I immediately entered into https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

the return is
{
"error": "invalid_token",
"error_description": "Invalid Value"
}

So ... where am I going wrong. I'm a novice in this area and any suggestions are appreciated.

@Synchro
Copy link
Member

Synchro commented Apr 6, 2016

I'm not sure what's wrong there, it looks like you're doing it all right. You may or may not be glad to know that this is all changing... If you look in the xoauth branch there is a major refactor underway that should make using xoauth2 a bit more transparent, though it's not quite there yet. I quite agree that OAuth is horribly confusing to work with!

BTW if you find differences in the wiki, it's publicly editable, so please do update it so that others can benefit.

@renardrouge
Copy link
Author

Hello Synchro ! Another minor step forward. I have managed to get a valid access_token.

I tried substituting "$mail->oauthAccessToken =" instead of "$mail->oauthRefreshToken =" but end up with Fatal error: Uncaught exception 'League\OAuth2\Client\Provider\Exception\IdentityProviderException'

I'm a novice at OAuth. Can you tell me why the code is using a refresh token instead of the access token ?

Also, when I try "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=xxx" I get a valid response back. If I use the refresh token instead, the response is "error": "invalid_token". Since the access token for GMail expires in 1 hour I wonder why the code does not include logic to refresh the access token after some period of time ? Again, I am wondering why a refresh token is used in the code instead of the access token ???

I keep looping back in my mind to "SMTP ERROR: AUTH command failed: 334" and why this might be happening.

@sherryl4george
Copy link
Contributor

@renardrouge I see that you are obtaining a Client Id for Web Server app. Can you please try getting the credentials for a Client Side using Javascript option for Calling from where option. Even though we run PHPMailer from a Web Server the working of a google Webserver App is completely different from our scenario. We make PHPMailer work as a client side app in order to get the refresh token. We store this refresh token and use it for subsequent calls and send mails.

@sherryl4george
Copy link
Contributor

@renardrouge I think the above way should work if everything else is fine at your ebd. Or if you still have issues you can simply try using the code in Xoauth branch to double check things

@renardrouge
Copy link
Author

Hello sherryl4george ! Can you provide more detail please. I am new at this OAuth stuff.

I am using PHP not Javascript, so I do not understand why or how I should be requesting a Javascript option.

Can you be more specific in how to "use the code in Xoauth branch to double check things" ?

@sherryl4george
Copy link
Contributor

Below is the screenshot of the option I wanted you to select when you create the app
screenshot_2016-04-07-01-00-15_1

I meant to say that in order to confirm that the Refresh token you have created works fine you can actually use the xoauth branch. Just because the code in Xoauth branch is 100% sure to works if we have the correct parameters. Hope this helps.

@renardrouge
Copy link
Author

Thanks ! Can you explain why a refresh token is used in the gmail_xoauth.php example rather than an access token ? I will try your credential setup suggestion to see if that makes any difference.

@sherryl4george
Copy link
Contributor

Typically Access tokens are short lived unlike Refresh tokens which are
long lived. In OAuth2 setup we trade the refresh tokens to obtain a Access
token and this access token is used for authentication and thereby send
mails. So internally when a mail is sent this is the process that happens.

If we use a Access token directly without a Refresh token we don't have a
way to get a new Access Token once the it is expired, without a user
intervention. Remember the fact that access tokens have a very short life.
We want to avoid this user intervention since PHPMailer is going to be on
the server side and for this setup the user is actually the sender of the
email and not the end user.

On Thursday, April 7, 2016, renardrouge [email protected] wrote:

Thanks ! Can you explain why a refresh token is used in the
gmail_xoauth.php example rather than an access token ? I will try your
credential setup suggestion to see if that makes any difference.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#677 (comment)

Regards,
Sherryl George
+91 7036858184

@renardrouge
Copy link
Author

OK, I think I understand. So this means that an access token is really aquired behind the scenes ??? Is there a way I can find the current access code in use by the gmail_xoauth.php example ???

@sherryl4george
Copy link
Contributor

Yes. You are absolutely correct. To see what the current access token, and if you are using the Master branch go to the file class.phpmaileroauthgoogle.php and you can echo the $token variable after line 74. If in Xoauth branch the same can be found in src\OAuth.php around line 100. The function getToken just above this does all the work to get access token from refresh token.

@renardrouge
Copy link
Author

Hi ! I tried to follow your instructions on the Google Developer site, but I do not know how to get to the screen shot you displayed. This is the setup I see. Do you have the URI for your screen ?

phpmailer2_credentials

@renardrouge
Copy link
Author

Oooops ! I see I made an error in that setup. I missed localhost. I will redo.

@sherryl4george
Copy link
Contributor

Yes this is fine. You can go ahead and create the credentials. The
screenshot I gave is reached when you create a new project and add apis.
The way you follow is also fine. Go ahead.

On Thursday, April 7, 2016, renardrouge [email protected] wrote:

Hi ! I tried to follow your instructions on the Google Developer site, but
I do not know how to get to the screen shot you displayed. This is the
setup I see. Do you have the URI for your screen ?

[image: phpmailer2_credentials]
https://cloud.githubusercontent.com/assets/10366395/14331647/35a9908e-fc14-11e5-8144-fca6a2875757.JPG


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#677 (comment)

Regards,
Sherryl George
+91 7036858184

@renardrouge
Copy link
Author

Hello Synchro ! Looking at the new gmail_xoauth.php code. Isn't it missing "require '../PHPMailerAutoload.php';" ???

@renardrouge
Copy link
Author

Hello sherryl4george ! Here is a screen shot of my latest effort.
xoauth_credentials

@Synchro
Copy link
Member

Synchro commented Apr 6, 2016

@renardrouge no - in the new version composer takes care of loading both PHPMailer and dependencies. Much neater!

@renardrouge
Copy link
Author

OK, thanks. I am just about to try new version. Cross my fingers !!!

@renardrouge
Copy link
Author

with the new code I get
"Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 18"

When I do the require on ../PHPMailerAutoload.php I get "Fatal error: Namespace declaration statement has to be the very first statement in the script in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 7" Help !!!

@renardrouge
Copy link
Author

Hello Syncro ! I am stuck. I uninstalled and reinstalled the latest composer. Composer version 1.0-dev (40c14709f79f9d7ea35ac969cfbd7f41beb525bb) 2016-04-05 I then executed a "composer update".

I tried the new gmail_xoauth.php code again, with the single require for autoload.php and I get "Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 18"

Suggestions ??? I am running on a Windows laptop.

@sherryl4george
Copy link
Contributor

Can you please run me through how you go about from the first step. Just to
be sure did you change the required dependencies in composer.json. Have did
you run the composer?

On Thursday, April 7, 2016, renardrouge [email protected] wrote:

Hello Syncro ! I am stuck. I uninstalled and reinstalled the latest
composer. Composer version 1.0-dev
(40c14709f79f9d7ea35ac969cfbd7f41beb525bb) 2016-04-05

I tried the new gmail_xoauth.php code again, with the single require for
autoload.php and I get "Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer'
not found in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 18"

Suggestions ??? I am running on a Windows laptop.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#677 (comment)

Regards,
Sherryl George
+91 7036858184

@renardrouge
Copy link
Author

Hi sherryl4george ! Well, I found I had to dig into composer syntax again. The ReadME says to add "phpmailer/phpmailer": "~5.4" to the .json file, but that did not work. I finally got version 5.4 to install with a "composer update" and the following .json

{
"require-dev": {
"phpmailer/phpmailer": "5.4.x-dev",
"league/oauth2-client": "^1.3",
"league/oauth2-google": "^1.0"
}
}

I then ran gmail_xoauth again and I am stuck at

Fatal error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::setOAuth() in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 56

line 56 starts with
$mail->setOAuth(
new OAuth([
'provider' => $provider,
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'refreshToken' => $refreshToken,
'userName' => $email
])
);

Suggestions ???

Looking at this further, perhaps I do not have the correct levels of the "league/" components ?
I will check further.

@sherryl4george
Copy link
Contributor

I feel you have a lot of stuff going into the composer.json file. My version would just have and addition of "league/oauth2-google":"*.*" under the require block. And run a composer update --no-dev

@renardrouge
Copy link
Author

OK, here is my composer.json now
{
"require-dev": {
"phpmailer/phpmailer": "5.4.x-dev"
},
"require": {
"league/oauth2-client": "^1.3",
"league/oauth2-google" : " * . * "
}
}

composer update -- no-dev says "Package "no-dev" listed for update is not installed. Ignoring.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files

I still get the same error "Fatal error: Call to undefined method PHPMailer\PHPMailer\PHPMailer::setOAuth() in C:\xampp\htdocs\phpmailer2\gmail_xoauth_v2.php on line 56"

@renardrouge
Copy link
Author

I have been searching the /vendor libraries for setOauth() and have not been successful. Where should it be located ???

@renardrouge
Copy link
Author

So ... I deleted my /vendor library and ran "composer update" with this .json
{
"require-dev": {
"phpmailer/phpmailer": "5.4.x-dev"
},
"require": {
"league/oauth2-client": " * . * ",
"league/oauth2-google": " * . * "
}
}

The result is
Updating dependencies (including require-dev)

  • Installing phpmailer/phpmailer (5.4.x-dev a9054a5)
    Cloning a9054a5
    • Installing ircmaxell/security-lib (1.0.0)
      Loading from cache
    • Installing ircmaxell/random-lib (v1.1.0)
      Loading from cache
    • Installing guzzlehttp/promises (1.1.0)
      Loading from cache
    • Installing psr/http-message (1.0)
      Loading from cache
    • Installing guzzlehttp/psr7 (1.2.3)
      Loading from cache
    • Installing guzzlehttp/guzzle (6.2.0)
      Loading from cache
    • Installing league/oauth2-client (1.3.0)
      Loading from cache
    • Installing league/oauth2-google (1.0.1)
      Loading from cache
      Generating autoload files

Same failure on gmail_xoauth.php. So ... the problem seems to be the absence of setOauth(). Would you mind checking the library list above with your install ? Have you been able to run the new gmail_xoauth successfully ?

@renardrouge
Copy link
Author

Hi Sherryl4george !

6 hours ago, you stated "If in Xoauth branch the same can be found in src\OAuth.php around line 100. The function getToken just above this does all the work to get access token from refresh token."

I can not find a src\OAuth.php file anywhere under the \vendor directory so I am obviously not using the same source libraries as you are.

The closest I can find is PHPMailerOAuth.php

So it seems I am stuck until someone can tell me how to properly build the correct library structure.

@renardrouge
Copy link
Author

OK, I am a little slow at figuring out what is going on. I finally found the "missing" files at https://github.com/PHPMailer/PHPMailer/tree/xoauth . My question is "How do I properly build the library ?" Can I do this with composer ? How ? If not, do I build it manually ?

@sherryl4george
Copy link
Contributor

Hope you did a Clone of xoauth branch and you have the correct files. Now go to composer.json and add "league/oauth2-google":"*.*" under require. There's really no need to add anything else as you have said above in the composer file. Now run a composer update. And things should work fine.

@renardrouge
Copy link
Author

Hi ! See my comments 1 hour ago. I have already run the composer update with
"league/oauth2-google" : " * . * "

@renardrouge
Copy link
Author

Good day members !
Latest results after reinstalling under localhost root directory. I cloned the recent updates and exercised get_oauth_token as before with success. However I seem to be at the same place as before with the previous structure.

I don't know where to go from here. Any suggestions that might aid in narrowing down why Google refuses to authenticate ???

I wonder if one of you could try the latest gmail_xoauth.php code yourself and report on successful execution ???

SERVER -> CLIENT: 220 smtp.gmail.com ESMTP cl4sm4182496igb.4 - gsmtp
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [67.193.150.17]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [67.193.150.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
CLIENT -> SERVER: AUTH XOAUTH2 dXNlcj1zb21lb25lQGdtYWlsLmNvbQFhdXRoPUJlYXJlciB5YTI5Li52UUtYeHRoM3lMc0lxWldqWnI1WlVNZTZuLWc0M25OR2FrSXBjaTAybU5nNEt0bmpQYjNOZF9BcDJJSzFpNFdfTlEBAQ==
SERVER -> CLIENT: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP ERROR: AUTH command failed: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 cl4sm4182496igb.4 - gsmtp
SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 cl4sm4182496igb.4 - gsmtp
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@sherryl4george
Copy link
Contributor

Can you please send me the file you are running to me. I will check and let
you know

On Friday, April 8, 2016, renardrouge [email protected] wrote:

Good day members !

Latest results after reinstalling under localhost root directory. I cloned
the recent updates and exercised get_oauth_token as before with success.
However I seem to be at the same place as before with the previous
structure.

I don't know where to go from here. Any suggestions that might aid in
narrowing down why Google refuses to authenticate ???

SERVER -> CLIENT: 220 smtp.gmail.com ESMTP cl4sm4182496igb.4 - gsmtp
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service,
[67.193.150.17]250-SIZE
35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250
SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-smtp.gmail.com at your service,
[67.193.150.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2
PLAIN-CLIENTTOKEN OAUTHBEARER
XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
CLIENT -> SERVER: AUTH XOAUTH2
dXNlcj1zb21lb25lQGdtYWlsLmNvbQFhdXRoPUJlYXJlciB5YTI5Li52UUtYeHRoM3lMc0lxWldqWnI1WlVNZTZuLWc0M25OR2FrSXBjaTAybU5nNEt0bmpQYjNOZF9BcDJJSzFpNFdfTlEBAQ==
SERVER -> CLIENT: 334
eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP ERROR: AUTH command failed: 334
eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
SMTP Error: Could not authenticate.
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more
at535 5.7.8 https://support.google.com/mail/answer/14257
cl4sm4182496igb.4 - gsmtp
SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not
accepted. Learn more at535 5.7.8
https://support.google.com/mail/answer/14257 cl4sm4182496igb.4 - gsmtp
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#677 (comment)

Regards,
Sherryl George
+91 7036858184

@renardrouge
Copy link
Author

Hi Sherryl !

It works !!! It works !!!

As I was cleaning up the client secret and id for dispatch I noticed that I had neglected to change the
$email = '[email protected]'; After changing to my correct email @ gmail, everything executed as expected.

Thank you for getting me to this point.

Can you explain the technical details as to why it only works at the root level ? I do not understand why the Javascript declaration of https://localhost was necessary or how it comes into play in the interaction.

@renardrouge
Copy link
Author

Here is a puzzle in the new get_oauth_token.php code.

I had to use $redirectUri = 'https://localhost/get_oauth_token.php';

Examining the code yields these results.

redirectUri = https://
HTTPS = on
HTTP_HOST = localhost
PHP_SELF = /$server.php (that's the name used for the test code below)

<?php
$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
echo 'redirectUri = '.$redirectUri. '<br/>';
echo 'HTTPS     = '.$_SERVER['HTTPS']. '<br/>';
echo 'HTTP_HOST = '.$_SERVER['HTTP_HOST']. '<br/>';
echo 'PHP_SELF  = '.$_SERVER['PHP_SELF']. '<br/>';
//$redirectUri = 'https://localhost/get_oauth_token.php';

@renardrouge
Copy link
Author

My solution:

$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http:https://';
$redirectUri = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

@renardrouge
Copy link
Author

A better solution:

$redirectUri = (isset($_SERVER['HTTPS']) ? 'https://' : 'http:https://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

@Synchro
Copy link
Member

Synchro commented Apr 7, 2016

That's just what I was thinking - it will be down to the operator precedence of . vs ?. I often find ? troublesome in that regard! I've just pushed that fix.

@renardrouge
Copy link
Author

Hi Synchro !
Can you explain technically why the Javascript credential declaration at Google of https//:localhost is required, forcing all of my code to the document root ? I'm not aware of any Javascript code. Is it hidden in /vendor somewhere ? If so, what is its function ???

@Synchro
Copy link
Member

Synchro commented Apr 7, 2016

It's not required to be anywhere - it can be any URL. That line in the token script attempts to generate a URL that points back at itself, wherever you put it. For the token issuing mechanism to work it needs a URL to send the result back to, so rather than making you set one, we attempt to generate one that should work in many cases. If it doesn't work, you can just set it manually to whatever you need. Generally you will only need to do this once - once you have the refresh token, you don't need to go through the process again, and you can use that key as many times as you like behind the scenes for actually sending your messages. This is why the token script is pretty basic - only developers will need to use it; it's unlikely that you'd want it to be user-facing.

It's not really anything to do with javascript - it's just a URL that google's scripts will call when they issue the token.

@renardrouge
Copy link
Author

Now I am puzzled. I think it was sherryl4george's advice to set up the Javascript uri to point at https://localhost along with moving all of the operational code to the localhost root that got me going.
Are you suggesting I can move the current code into a directory below the root (with approprate redirectUri changes and still be executable ??? That would be my preference.

@sherryl4george
Copy link
Contributor

Yes you can. You can move it to anywhere now. I asked to move it to the root just to make sure that we don't miss anything while creating the refresh token. You can move it to any level now but may have to set the proper redericturi once if at all you have to generate the refresh token. Sorry for the confusion that I made.

@sherryl4george
Copy link
Contributor

Really appreciate your patience to sit through and sort out things. Hope now it works like a charm.

@renardrouge
Copy link
Author

OK, thanks for the response. I am still puzzled as to why it suddenly executed at the root level though.
I did not knowingly do anything different. I will try shifting back to the previous location.

@renardrouge
Copy link
Author

??? in the last version, this code executed properly.

echo 'PHPMailer version = '.$mail->Version;  // line 17

Now I get "Notice: Undefined property: PHPMailer\PHPMailer\PHPMailer::$Version in C:\xampp\htdocs2\phpmailer_version.php on line 17"

Where do I look to find valid properties in the new code ???

@renardrouge
Copy link
Author

Thank you all !

I have moved back to directory /phpmailer under the root directory with complete success.
(No Javascript specification required.)

My only outstanding item now is how to fix the code below that executed successfully in the last previous version of PHPMailer.

echo 'PHPMailer version = '.$mail->Version;  // line 17

Now I get "Notice: Undefined property: PHPMailer\PHPMailer\PHPMailer::$Version in C:\xampp\htdocs1\phpmailer\phpmailer_version.php on line 17"

@Synchro
Copy link
Member

Synchro commented Apr 8, 2016

The Version property was deprecated some time ago. The version number is not variable, so it was changed to a constant. You should change your code from $mail->Version to PHPMailer::VERSION.

@renardrouge
Copy link
Author

Thank you for the VERSION solution !!!

I am now checking for documentation. The best I have found so far is at http:https://phpmailer.github.io/PHPMailer/ ... but it does not include VERSION as a constant.

I see generatedocs.sh can generate documentation, but it appears to not be Windows compatible ???

For example, my command line does not understand the "rm" command. If it did work it appears that I need the phpdoc package too ??? Is there any hope for me to be able to generate this documentation on a Windows 10 platform ???

If so, any references for building on Windows 10 ???

@renardrouge
Copy link
Author

Well ... I have phpDocumentor running on a sample.php file and the output looks good.

I had a warning message during the run, so I will try to fix that.

Unable to find the dot command of the GraphViz package. Is GraphViz correctly installed and present in your path?

The question is ... if I manage to get this running, will I be able to get documentation relative to the latest development code that I am currently running on ???

@renardrouge
Copy link
Author

OK, GraphViz installed and sample runs clean.

@renardrouge
Copy link
Author

OK, I have answered my own question. I have phpDocumentor producing documentation for PHPMailer.php and VERSION shows under Constants. That's it for tonight !!!

@renardrouge
Copy link
Author

I have upgraded to the latest xampp with PHP 7.0 and have encountered the following error with gmail_oauth.php

Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate

I can make this go away by patching the Client.php module of guzzle under /vendors in the private function configureDefaults from 'verify' => true, to 'verify' => false,

I know it is not proper protocol to modify modules under /vendor, but alas, my PHP skills are lacking. I have tried for the last day to set this from gmail_oauth.php with out success.

Can any of you PHP professionals tell me how to do this ???

@Synchro
Copy link
Member

Synchro commented Apr 11, 2016

That sounds like your local CA file is missing or out of date. Tweaking the class is a bad idea (because it's hard to maintain), and it's fixing the symptom, not the cause. Fix the cause and the symptom will go away.

@renardrouge
Copy link
Author

Hi Synchro !

Thanks for looking. I reviewed my xampp php7 setup and found that I had neglected to set
[curl] curl.cainfo = "C:\xampp7\php\cacert.pem" ; in the php.ini file.

Once that was set and the cacert.pem file copied into place, everything operated as expected.

Thanks again for the assistance. I will send an email on an off-topic item that I hope you can assist with.

@Synchro
Copy link
Member

Synchro commented Apr 19, 2016

I'm pretty happy that this script now works with the new 5.5 branch, so I'm closing it.

FYI I ran into the cacert problem sa swell and it turned out to be a problem with the libcurl my PHP was using - it was built with libressl. I recompiled with openssl and it all started working, so I added a note to the troubleshooting guide about it.

@Synchro Synchro closed this as completed Apr 19, 2016
@Luisinho77
Copy link

Greetings!

I'd like to tell you about my last journey, it was full of adventures, please read more here http:https://sufrapari.urgentchildcareusa.com/e4vxxrv

My best to you, ljlorente

@Luisinho77
Copy link

Hello!

I thought you were interested in stuff like that, so probably that article would be helpful to you, please read it here http:https://nkeltiquewi.clintsantiagodahl.com/e4vklzbf

In haste, ljlorente

@Luisinho77
Copy link

Hi!

We've been at a very nice place recently and we loved it so much, I think it is just a fantastic place, check it out http:https://quovoxachy.hhotechnologies.com/e4xod

Be well, ljlorente

@Luisinho77
Copy link

Dear friend!
Have you seen this before? That's something really nice, more info here http:https://hidolopro.mcgrathcommercialvehicles.com/e4don

Yours faithfully, ljlorente

@Luisinho77
Copy link

Yo!

We have recently had a splendid dinner with my family in a great place, just take a look http:https://ltiwinyly.shorttalent.com/e4dsoufg

Typos courtesy of my iPhone, ljlorente

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants