- Issue created by @bmustafa
- Status changed to Postponed: needs info
over 1 year ago 10:13pm 1 May 2023 - 🇦🇺Australia imclean Tasmania
It looks like you've installed Symfony Mailer at some point. PHPMailer SMTP doesn't require Symfony Mailer, and Symfony Mailer doesn't require this module. They both perform similar functions.
Pick one email module and uninstall the other.
I'll leave this open for now in case you have anything further to add.
- 🇯🇴Jordan bmustafa
Yes i have disabled that per your advice, not sure why i got it enabled earlier.
however, the authentication fails with gmail, despite user name and password are correct.
i do not see that this module supports Oauth2 yet, can you please implement it, it is not difficult:- Install the latest version of PHPMailer using Composer:
- composer require phpmailer/phpmailer
- Install the Gmail API client library using Composer:
- composer require google/apiclient:^2.0
- Obtain the OAuth2 credentials for your Gmail account using the Gmail API client library.
- Use the obtained credentials to authenticate PHPMailer with OAuth2 and send an email.
Here is the sample code to send email using PHPMailer with OAuth2 authentication:
require_once 'vendor/autoload.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\OAuth; use Google\Client; use Google\Service\Gmail; // Replace placeholders with actual values define('CLIENT_SECRET_PATH', 'path/to/client_secret.json'); define('CREDENTIALS_PATH', 'path/to/credentials.json'); define('EMAIL_FROM', 'YOUR_EMAIL_ADDRESS_HERE'); define('NAME_FROM', 'YOUR_NAME_HERE'); define('EMAIL_TO', 'RECIPIENT_EMAIL_ADDRESS_HERE'); define('NAME_TO', 'RECIPIENT_NAME_HERE'); define('EMAIL_SUBJECT', 'EMAIL_SUBJECT_HERE'); define('EMAIL_BODY', 'EMAIL_BODY_HERE'); // Set up the Google API client $client = new Client(); $client->setApplicationName('My Application Name'); $client->setScopes([Gmail::GMAIL_READONLY]); $client->setAuthConfig(CLIENT_SECRET_PATH); $client->setAccessType('offline'); $client->setPrompt('select_account consent'); // Create a new Gmail API client instance $gmail = new Gmail($client); // Obtain the OAuth2 credentials for your Gmail account $authUrl = $client->createAuthUrl(); echo "Please visit this URL to authorize the application: $authUrl\n"; $authCode = readline("Enter the authorization code: "); $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); // Store the credentials for later use file_put_contents(CREDENTIALS_PATH, json_encode($accessToken)); // Create a new instance of PHPMailer $mail = new PHPMailer(); // Set the SMTP settings for Gmail $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->SMTPSecure = 'tls'; $mail->Port = 587; // Set the OAuth2 authentication settings $mail->setOAuth( new OAuth([ 'clientId' => $client->getConfig('client_id'), 'clientSecret' => $client->getConfig('client_secret'), 'refreshToken' => $accessToken['refresh_token'], 'userName' => EMAIL_FROM, ]) ); // Set the email message properties $mail->setFrom(EMAIL_FROM, NAME_FROM); $mail->addAddress(EMAIL_TO, NAME_TO); $mail->Subject = EMAIL_SUBJECT; $mail->Body = EMAIL_BODY; // Send the email if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message sent successfully'; }
Make sure to replace the placeholder values with your actual credentials and message details before running the code.
- Status changed to Closed: works as designed
over 1 year ago 2:29am 2 May 2023 - 🇦🇺Australia imclean Tasmania
@bmustafa have a look at PHPMailer OAuth2 → and see how that integrates with this module, you can add your own provider there.
Have a look at the issues for that module, including ✨ PHPMailer OAuth2 - Add support for Google's XOAuth2 Active .