-
-
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
Create sendoauth2.phps #2985
Create sendoauth2.phps #2985
Conversation
OAuth2 authentication for both Microsoft 365 Exchange email and Google Gmail. Client secrets and X.509 certificates are supported for Exchange. Client secrets are supported for Gmail. Authorization_code grant flow and client_credentials grant flow for SMTP are supported for Exchange. Authorization_code grant flow is supported for Gmail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this - I know you've been very helpful in decrypting the intricacies of inconsistent OAuth implementations!
examples/sendoauth2.phps
Outdated
*/ | ||
|
||
//Set the wrapper namespace | ||
namespace decomplexity\SendOauth2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the right way to work with external libraries. The namespace should be up to the developer, and if they want to use your class, they should import it using:
use decomplexity\SendOauth2\SendOauth2B;
Just as they do for PHPMailer.
examples/sendoauth2.phps
Outdated
//Sender and recipients | ||
$mail->setFrom('from@example.com', 'Mailer'); // 'Header' From address with optional sender name | ||
$mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient | ||
$mail->addAddress('ellen@example.com'); //Name is optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the purpose of this example is purely to demonstrate how to use your auth wrapper, I suggest removing anything that is covered in other examples, such as extra recipients, attachments, etc.
$mail->Host = 'smtp.office365.com'; //Set the SMTP server (smtp.gmail.com for Gmail) | ||
$mail->SMTPAuth = true; //Enable SMTP authentication | ||
$mail->Username = 'user@example.com'; //SMTP username | ||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable implicit TLS encryption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These days we should be recommending SMTPS on port 465, as per RFC8314:
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
examples/sendoauth2.phps
Outdated
|
||
$mail->setOAuth($oauthTokenProvider); //Pass OAuthTokenProvider to PHPMailer | ||
|
||
//Attachments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, I suggest removing these attachment lines.
Updated from @Synchro's comments
OAuth2 authentication for both Microsoft 365 Exchange email and Google Gmail. Client secrets and X.509 certificates are supported for Exchange. Client secrets are supported for Gmail. Authorization_code grant flow and client_credentials grant flow for SMTP are supported for Exchange. Authorization_code grant flow is supported for Gmail.