This commit is contained in:
Synchro 2015-10-20 13:52:29 +02:00
parent 65244ee9dc
commit 19fcea0556
7 changed files with 508 additions and 299 deletions

View File

@ -1,5 +1,4 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.4.
@ -20,16 +19,14 @@
*/
/**
* PHPMailerOAuthProvider - Wrapper for League OAuth2 Google/Yahoo/Microsoft provider.
*
* PHPMailerOAuthProvider class
* An abstract base class for service-provider-specific OAuth implementations.
* @author @hayageek
* @author Ravishanker Kusuma (hayageek@gmail.com)
*
* @link https://github.com/hayageek
*/
abstract class PHPMailerOAuthProvider extends PHPMailerOAuth
abstract class PHPMailerOAuthProvider
{
protected $ouathToken = null;
protected $oauthToken = null;
public function __construct(
$UserEmail = '',
@ -45,11 +42,6 @@ abstract class PHPMailerOAuthProvider extends PHPMailerOAuth
abstract public function getProvider();
/**
* An instance of the PHPMailerOAuthProvider class.
* @type PHPMailerOAuthProvider
* @access public
*/
public function getOAUTHInstance()
{
return $this;
@ -62,7 +54,6 @@ abstract class PHPMailerOAuthProvider extends PHPMailerOAuth
private function getToken()
{
echo "Getting Token";
$provider = $this->getProvider();
$grant = $this->getGrant();
@ -71,13 +62,11 @@ abstract class PHPMailerOAuthProvider extends PHPMailerOAuth
public function getOauth64()
{
/*
Get the new token only if it not available or expired
*/
if ($this->ouathToken == null || ($this->ouathToken != null && $this->ouathToken->hasExpired()))
// Get the new token only if it not available or expired
if ($this->oauthToken == null || ($this->oauthToken != null && $this->oauthToken->hasExpired()))
{
$this->ouathToken = $this->getToken();
$this->oauthToken = $this->getToken();
}
return base64_encode('user='.$this->oauthUserEmail."\001auth=Bearer ".$this->ouathToken."\001\001");
return base64_encode('user='.$this->oauthUserEmail."\001auth=Bearer ".$this->oauthToken."\001\001");
}
}

View File

@ -20,7 +20,9 @@
}
],
"require": {
"php": ">=5.0.0"
"php": ">=5.0.0",
"league/oauth2-client": "^1.0",
"league/oauth2-google": "^1.0"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "*",

461
composer.lock generated
View File

@ -4,8 +4,437 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "0eb36ae77d61050323a94e312176ea66",
"packages": [],
"hash": "02e636165eb9fb167184cddb274e95c1",
"packages": [
{
"name": "guzzlehttp/guzzle",
"version": "6.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/66fd14b4d0b8f2389eaf37c5458608c7cb793a81",
"reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "~1.0",
"guzzlehttp/psr7": "~1.1",
"php": ">=5.5.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.1-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2015-09-08 17:36:26"
},
{
"name": "guzzlehttp/promises",
"version": "1.0.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea",
"reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2015-10-15 22:28:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
"reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
],
"time": "2015-08-15 19:32:36"
},
{
"name": "ircmaxell/random-lib",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/ircmaxell/RandomLib.git",
"reference": "13efa4368bb2ac88bb3b1459b487d907de4dbf7c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ircmaxell/RandomLib/zipball/13efa4368bb2ac88bb3b1459b487d907de4dbf7c",
"reference": "13efa4368bb2ac88bb3b1459b487d907de4dbf7c",
"shasum": ""
},
"require": {
"ircmaxell/security-lib": "1.0.*@dev",
"php": ">=5.3.2"
},
"require-dev": {
"mikey179/vfsstream": "1.1.*",
"phpunit/phpunit": "3.7.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"RandomLib": "lib"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anthony Ferrara",
"email": "ircmaxell@ircmaxell.com",
"homepage": "http://blog.ircmaxell.com"
}
],
"description": "A Library For Generating Secure Random Numbers",
"homepage": "https://github.com/ircmaxell/RandomLib",
"keywords": [
"cryptography",
"random",
"random-numbers",
"random-strings"
],
"time": "2015-01-15 16:31:45"
},
{
"name": "ircmaxell/security-lib",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/ircmaxell/SecurityLib.git",
"reference": "80934de3c482dcafb46b5756e59ebece082b6dc7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ircmaxell/SecurityLib/zipball/80934de3c482dcafb46b5756e59ebece082b6dc7",
"reference": "80934de3c482dcafb46b5756e59ebece082b6dc7",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"mikey179/vfsstream": "1.1.*"
},
"type": "library",
"autoload": {
"psr-0": {
"SecurityLib": "lib"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anthony Ferrara",
"email": "ircmaxell@ircmaxell.com",
"homepage": "http://blog.ircmaxell.com"
}
],
"description": "A Base Security Library",
"homepage": "https://github.com/ircmaxell/PHP-SecurityLib",
"time": "2013-04-30 18:00:34"
},
{
"name": "league/oauth2-client",
"version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth2-client.git",
"reference": "32d94d0ffc846b7f0fd9a115a7b0795a47a2d11c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/32d94d0ffc846b7f0fd9a115a7b0795a47a2d11c",
"reference": "32d94d0ffc846b7f0fd9a115a7b0795a47a2d11c",
"shasum": ""
},
"require": {
"ext-curl": "*",
"guzzlehttp/guzzle": "~6.0",
"ircmaxell/random-lib": "~1.1",
"php": ">=5.5.0"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.8.*",
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "0.6.*",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alex Bilbie",
"email": "hello@alexbilbie.com",
"homepage": "http://www.alexbilbie.com",
"role": "Developer"
}
],
"description": "OAuth 2.0 Client Library",
"keywords": [
"Authentication",
"SSO",
"authorization",
"identity",
"idp",
"oauth",
"oauth2",
"single sign on"
],
"time": "2015-09-22 18:26:19"
},
{
"name": "league/oauth2-google",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/oauth2-google.git",
"reference": "4788fcef5cf0fdb65e0322c3f4d4632d8f1f3e82"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/oauth2-google/zipball/4788fcef5cf0fdb65e0322c3f4d4632d8f1f3e82",
"reference": "4788fcef5cf0fdb65e0322c3f4d4632d8f1f3e82",
"shasum": ""
},
"require": {
"league/oauth2-client": "~1.0"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Woody Gilk",
"email": "woody.gilk@gmail.com",
"homepage": "http://shadowhand.me"
}
],
"description": "Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client",
"keywords": [
"Authentication",
"authorization",
"client",
"google",
"oauth",
"oauth2"
],
"time": "2015-08-28 18:33:30"
},
{
"name": "psr/http-message",
"version": "1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
"reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2015-05-04 20:22:00"
}
],
"packages-dev": [
{
"name": "cilex/cilex",
@ -626,9 +1055,9 @@
],
"authors": [
{
"name": "Johannes Schmitt",
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh",
"homepage": "http://jmsyst.com",
"role": "Developer of wrapped JMSSerializerBundle"
}
],
@ -907,9 +1336,9 @@
],
"authors": [
{
"name": "Johannes Schmitt",
"name": "Johannes M. Schmitt",
"email": "schmittjoh@gmail.com",
"homepage": "https://github.com/schmittjoh",
"homepage": "http://jmsyst.com",
"role": "Developer of wrapped JMSSerializerBundle"
}
],
@ -1712,7 +2141,9 @@
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
}
],
"description": "Pimple is a simple Dependency Injection Container for PHP 5.3",
@ -2183,12 +2614,12 @@
"version": "v2.7.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/Config.git",
"url": "https://github.com/symfony/config.git",
"reference": "6c905bbed1e728226de656e4c07d620dfe9e80d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Config/zipball/6c905bbed1e728226de656e4c07d620dfe9e80d9",
"url": "https://api.github.com/repos/symfony/config/zipball/6c905bbed1e728226de656e4c07d620dfe9e80d9",
"reference": "6c905bbed1e728226de656e4c07d620dfe9e80d9",
"shasum": ""
},
@ -2233,12 +2664,12 @@
"version": "v2.7.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"url": "https://github.com/symfony/console.git",
"reference": "d6cf02fe73634c96677e428f840704bfbcaec29e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/d6cf02fe73634c96677e428f840704bfbcaec29e",
"url": "https://api.github.com/repos/symfony/console/zipball/d6cf02fe73634c96677e428f840704bfbcaec29e",
"reference": "d6cf02fe73634c96677e428f840704bfbcaec29e",
"shasum": ""
},
@ -2290,12 +2721,12 @@
"version": "v2.7.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher.git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "9310b5f9a87ec2ea75d20fec0b0017c77c66dac3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
"reference": "9310b5f9a87ec2ea75d20fec0b0017c77c66dac3",
"shasum": ""
},
@ -2348,12 +2779,12 @@
"version": "v2.7.3",
"source": {
"type": "git",
"url": "https://github.com/symfony/Filesystem.git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "2d7b2ddaf3f548f4292df49a99d19c853d43f0b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Filesystem/zipball/2d7b2ddaf3f548f4292df49a99d19c853d43f0b8",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/2d7b2ddaf3f548f4292df49a99d19c853d43f0b8",
"reference": "2d7b2ddaf3f548f4292df49a99d19c853d43f0b8",
"shasum": ""
},

View File

@ -1,87 +0,0 @@
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Load dependencies from composer
//If this causes an error, run 'composer install'
require '../vendor/autoload.php';
//Create a new PHPMailerOAuthGoogle instance
$mail = new PHPMailerOAuthGoogle;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Set AuthType
$mail->AuthType = 'XOAUTH2';
//User Email to use for SMTP authentication - Who authorised to access Google mail
$mail->oauthUserEmail = "sender@gmail.com";
//Obtained From Google Developer Console
$mail->oauthClientId = "{YOUR_APP_CLIENT_ID}";
//Obtained From Google Developer Console
$mail->oauthClientSecret = "{YOUR_APP_CLIENT_SECRET}";
//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
// eg: http://localhost/phpmail/get_oauth_token.php
$mail->oauthRefreshToken = "{OAUTH_TOKEN_FROM_GOOGLE}";
//Set who the message is to be sent from
//For gmail, this generally needs to be the same as the user you logged in as
$mail->setFrom('sender@gmail.com', 'test test');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

View File

@ -1,90 +0,0 @@
<?php
/**
* This example shows settings to use when sending via Outlook/Microsoft Live servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Load dependnecies from composer
//If this causes an error, run 'composer install'
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailerOAuthMicrosoft;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'text';
//Set the hostname of the mail server
$mail->Host = 'smtp-mail.outlook.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Set AuthType
$mail->AuthType = 'XOAUTH2';
//User Email to use for SMTP authentication - Who authorised to access Outlook mail
$mail->oauthUserEmail = "sender@hotmail.com";
//Obtained From https://account.live.com/developers/applications/index
$mail->oauthClientId = "{YOUR_CLIENT_ID}";
//Obtained From https://account.live.com/developers/applications/index
$mail->oauthClientSecret = "{YOUR_CLIENT_SECRET}";
//Obtained By running get_oauth_token.php
$mail->oauthRefreshToken = "{OAUTH_REFRESH_TOKEN}";
//Set who the message is to be sent from
//For gmail, this generally needs to be the same as the user you logged in as
$mail->setFrom('sender@hotmail.com', 'Test');
//Set who the message is to be sent to
$mail->addAddress('receiver@gmail.com', 'Test');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test.Gmail Final';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->msgHTML("<html><body>Hello 1</body></html>");
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

View File

@ -0,0 +1,51 @@
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Load dependencies from composer
//If this causes an error, run 'composer install'
require '../vendor/autoload.php';
//Create a new Gmail-specific PHPMailer instance
$mail = new PHPMailerOAuthGoogle;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
//Set AuthType
$mail->AuthType = 'XOAUTH2';
//User Email to use for SMTP authentication - Who authorised to access Google mail
$mail->oauthUserEmail = 'sender@gmail.com';
//Obtained From Google Developer Console
$mail->oauthClientId = '{YOUR_APP_CLIENT_ID}';
//Obtained From Google Developer Console
$mail->oauthClientSecret = '{YOUR_APP_CLIENT_SECRET}';
//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
// eg: http://localhost/phpmail/get_oauth_token.php
$mail->oauthRefreshToken = '{OAUTH_TOKEN_FROM_GOOGLE}';
$mail->setFrom('sender@gmail.com', 'test test');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'PHPMailer GMail XOAUTH2 SMTP test';
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}

View File

@ -1,87 +0,0 @@
<?php
/**
* This example shows settings to use when sending via Yaho servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Load dependnecies from composer
//If this causes an error, run 'composer install'
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailerOAuthYahoo;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.mail.yahoo.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Set AuthType
$mail->AuthType = 'XOAUTH2';
//User Email to use for SMTP authentication - Who authorised to send Yahoo mail
$mail->oauthUserEmail = "sender@yahoo.com";
//Obtained From https://developer.yahoo.com/apps/
$mail->oauthClientId = "{YAOOO_CLIENT_ID}";
//Obtained From https://developer.yahoo.com/apps/
$mail->oauthClientSecret = "{CLIENT_SECRET}";
// eg: http://localhost/phpmail/get_oauth_token.php
$mail->oauthRefreshToken = "{REFRESH_TOKEN}";
//Set who the message is to be sent from
//For gmail, this generally needs to be the same as the user you logged in as
$mail->setFrom('sender@yahoo.com', 'test');
//Set who the message is to be sent to
$mail->addAddress('receiver@gmail.com', 'test');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}