From b87462979b8be41d8f18d71e20b1d9b938aa7ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20B?= Date: Fri, 2 Oct 2015 18:52:29 +0200 Subject: [PATCH] Change line endings from CRLF to LF All files in PHPMailer have LF line endings, except those two. Harmonize line endings to LF for consistency. --- examples/gmail_xoauth.phps | 170 ++++++++++++++++++------------------- get_oauth_token.php | 132 ++++++++++++++-------------- 2 files changed, 151 insertions(+), 151 deletions(-) diff --git a/examples/gmail_xoauth.phps b/examples/gmail_xoauth.phps index 4f7d57fc..a40c0fa4 100644 --- a/examples/gmail_xoauth.phps +++ b/examples/gmail_xoauth.phps @@ -1,85 +1,85 @@ -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 - Use the same Email used in Google Developer Console -$mail->oauthUserEmail = "someone@gmail.com"; - -//Obtained From Google Developer Console -$mail->oauthClientId = "RANDOMCHARS-----duv1n2.apps.googleusercontent.com"; - -//Obtained From Google Developer Console -$mail->oauthClientSecret = "RANDOMCHARS-----lGyjPcRtvP"; - -//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console. -//Set Redirect URI in Developer Console as [https/http]:////get_oauth_token.php -// eg: http://localhost/phpmail/get_oauth_token.php -$mail->oauthRefreshToken = "RANDOMCHARS-----DWxgOvPT003r-yFUV49TQYag7_Aod7y0"; - -//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('from@example.com', 'First Last'); - -//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!"; -} +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 - Use the same Email used in Google Developer Console +$mail->oauthUserEmail = "someone@gmail.com"; + +//Obtained From Google Developer Console +$mail->oauthClientId = "RANDOMCHARS-----duv1n2.apps.googleusercontent.com"; + +//Obtained From Google Developer Console +$mail->oauthClientSecret = "RANDOMCHARS-----lGyjPcRtvP"; + +//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console. +//Set Redirect URI in Developer Console as [https/http]:////get_oauth_token.php +// eg: http://localhost/phpmail/get_oauth_token.php +$mail->oauthRefreshToken = "RANDOMCHARS-----DWxgOvPT003r-yFUV49TQYag7_Aod7y0"; + +//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('from@example.com', 'First Last'); + +//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!"; +} diff --git a/get_oauth_token.php b/get_oauth_token.php index 2809601c..08ed7f17 100644 --- a/get_oauth_token.php +++ b/get_oauth_token.php @@ -1,66 +1,66 @@ -//get_oauth_token.php - * e.g.: http://localhost/phpmail/get_oauth_token.php - * * Ensure dependencies are installed with 'composer install' - * * Set up an app in your Google developer console - * * Set the script address as the app's redirect URL - * If no refresh token is obtained when running this file, revoke access to your app - * using link: https://accounts.google.com/b/0/IssuedAuthSubTokens and run the script again. - * This script requires PHP 5.4 or later - * PHP Version 5.4 - */ - -require 'vendor/autoload.php'; - -session_start(); - -//If this automatic URL doesn't work, set it yourself manually -$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; -//$redirectUri = 'http://localhost/phpmailer/get_oauth_token.php'; - -//These details obtained are by setting up app in Google developer console. -$clientId = 'RANDOMCHARS-----duv1n2.apps.googleusercontent.com'; -$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP'; - -//Set Redirect URI in Developer Console as [https/http]:////get_oauth_token.php -$provider = new League\OAuth2\Client\Provider\Google( - array( - 'clientId' => $clientId, - 'clientSecret' => $clientSecret, - 'redirectUri' => $redirectUri, - 'scopes' => array('https://mail.google.com/'), - 'accessType' => 'offline' - ) -); - -if (!isset($_GET['code'])) { - // If we don't have an authorization code then get one - $authUrl = $provider->getAuthorizationUrl(); - $_SESSION['oauth2state'] = $provider->state; - header('Location: ' . $authUrl); - exit; -// Check given state against previously stored one to mitigate CSRF attack -} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { - unset($_SESSION['oauth2state']); - exit('Invalid state'); -} else { - $provider->accessType = 'offline'; - // Try to get an access token (using the authorization code grant) - $token = $provider->getAccessToken( - 'authorization_code', - array( - 'code' => $_GET['code'] - ) - ); - // Use this to interact with an API on the users behalf - // echo $token->accessToken.'
'; - - // Use this to get a new access token if the old one expires - echo 'Refresh Token: ' . $token->refreshToken; - - // Unix timestamp of when the token will expire, and need refreshing - // echo $token->expires; -} +//get_oauth_token.php + * e.g.: http://localhost/phpmail/get_oauth_token.php + * * Ensure dependencies are installed with 'composer install' + * * Set up an app in your Google developer console + * * Set the script address as the app's redirect URL + * If no refresh token is obtained when running this file, revoke access to your app + * using link: https://accounts.google.com/b/0/IssuedAuthSubTokens and run the script again. + * This script requires PHP 5.4 or later + * PHP Version 5.4 + */ + +require 'vendor/autoload.php'; + +session_start(); + +//If this automatic URL doesn't work, set it yourself manually +$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; +//$redirectUri = 'http://localhost/phpmailer/get_oauth_token.php'; + +//These details obtained are by setting up app in Google developer console. +$clientId = 'RANDOMCHARS-----duv1n2.apps.googleusercontent.com'; +$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP'; + +//Set Redirect URI in Developer Console as [https/http]:////get_oauth_token.php +$provider = new League\OAuth2\Client\Provider\Google( + array( + 'clientId' => $clientId, + 'clientSecret' => $clientSecret, + 'redirectUri' => $redirectUri, + 'scopes' => array('https://mail.google.com/'), + 'accessType' => 'offline' + ) +); + +if (!isset($_GET['code'])) { + // If we don't have an authorization code then get one + $authUrl = $provider->getAuthorizationUrl(); + $_SESSION['oauth2state'] = $provider->state; + header('Location: ' . $authUrl); + exit; +// Check given state against previously stored one to mitigate CSRF attack +} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { + unset($_SESSION['oauth2state']); + exit('Invalid state'); +} else { + $provider->accessType = 'offline'; + // Try to get an access token (using the authorization code grant) + $token = $provider->getAccessToken( + 'authorization_code', + array( + 'code' => $_GET['code'] + ) + ); + // Use this to interact with an API on the users behalf + // echo $token->accessToken.'
'; + + // Use this to get a new access token if the old one expires + echo 'Refresh Token: ' . $token->refreshToken; + + // Unix timestamp of when the token will expire, and need refreshing + // echo $token->expires; +}