PHP code example of mathsgod / phpmailer-gmail
1. Go to this page and download the library: Download mathsgod/phpmailer-gmail library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mathsgod / phpmailer-gmail example snippets
use PHPMailer\GmailMailer;
$gmail = '[email protected]';
$clientId = 'YOUR_GOOGLE_CLIENT_ID';
$clientSecret = 'YOUR_GOOGLE_CLIENT_SECRET';
$refreshToken = 'YOUR_REFRESH_TOKEN';
$mailer = new GmailMailer(true, $gmail, $clientId, $clientSecret, $refreshToken);
$mailer->addAddress('[email protected]');
$mailer->Subject = 'Test Email';
$mailer->Body = 'This is a test email sent via Gmail SMTP with OAuth2.';
if ($mailer->send()) {
echo "Message sent!";
} else {
echo "Mailer Error: " . $mailer->ErrorInfo;
}