init without history
Dieser Commit ist enthalten in:
Commit
5ffc456b15
8 geänderte Dateien mit 2082 neuen und 0 gelöschten Zeilen
5
.gitattributes
gevendort
Normale Datei
5
.gitattributes
gevendort
Normale Datei
|
@ -0,0 +1,5 @@
|
|||
.gitignore export-ignore
|
||||
.gitattributes export-ignore
|
||||
.gitea export-ignore
|
||||
composer.json export-ignore
|
||||
composer.lock export-ignore
|
70
README.md
Normale Datei
70
README.md
Normale Datei
|
@ -0,0 +1,70 @@
|
|||
|
||||
# PHPMailer Plugin for CONTENIDO
|
||||
|
||||
This plugin will add PHPMailer to your CONTENIDO CMS. You need at last version 4.10.1
|
||||
|
||||
|
||||
You may use PHPMailer in your module, plugin or other project within CONTENIDO using
|
||||
the following sample code, which can be found in README file of the PHPMailer lib,
|
||||
which you can get on [github](https://github.com/PHPMailer/PHPMailer).
|
||||
|
||||
```php
|
||||
$mailer = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
//Server settings
|
||||
$mailer->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
|
||||
$mailer->isSMTP(); //Send using SMTP
|
||||
$mailer->Host = 'smtp.example.com'; //Set the SMTP server to send through
|
||||
$mailer->SMTPAuth = true; //Enable SMTP authentication
|
||||
$mailer->Username = 'user@example.com'; //SMTP username
|
||||
$mailer->Password = 'secret'; //SMTP password
|
||||
$mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
|
||||
$mailer->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
||||
|
||||
//Recipients
|
||||
$mailer->setFrom('from@example.com', 'Mailer');
|
||||
$mailer->addAddress('joe@example.net', 'Joe User'); //Add a recipient
|
||||
$mailer->addAddress('ellen@example.com'); //Name is optional
|
||||
$mailer->addReplyTo('info@example.com', 'Information');
|
||||
$mailer->addCC('cc@example.com');
|
||||
$mailer->addBCC('bcc@example.com');
|
||||
|
||||
//Attachments
|
||||
$mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments
|
||||
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
|
||||
|
||||
//Content
|
||||
$mail->isHTML(true); //Set email format to HTML
|
||||
$mail->Subject = 'Here is the subject';
|
||||
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
|
||||
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||
|
||||
$mail->send();
|
||||
echo 'Message has been sent';
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
```
|
||||
---
|
||||
|
||||
## Todo
|
||||
|
||||
- add behaviours used in former phpmailer implementations for CONTENIDO
|
||||
- add backend area for default configurations (SMTP, ec.)
|
||||
|
||||
## History
|
||||
|
||||
#### V1.0.0
|
||||
|
||||
- first official release of PHPMailer plugin
|
||||
|
||||
#### V0.0.2
|
||||
|
||||
- internal testing
|
||||
|
||||
#### V0.0.1
|
||||
|
||||
- initial version of PHPMailer plugin (intern)
|
||||
|
||||
|
7
classes/PHPMailer.php
Normale Datei
7
classes/PHPMailer.php
Normale Datei
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
|
||||
|
||||
class PHPMailer extends \PHPMailer\PHPMailer\PHPMailer
|
||||
{
|
||||
|
||||
}
|
26
composer.json
Normale Datei
26
composer.json
Normale Datei
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "phpbo/phpmailer",
|
||||
"description": "plugin for cms CONTENIDO to add PHPMailer",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"minimum-stability": "stable",
|
||||
"authors": [
|
||||
{
|
||||
"name": "ortwin pinke",
|
||||
"email": "o.pinke@php-backoffice.de",
|
||||
"homepage": "https://php-backoffice.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"phpmailer/phpmailer": "v6.9.1",
|
||||
"decomplexity/sendoauth2": "v4.1.0",
|
||||
"google/apiclient": "v2.17.0",
|
||||
"league/oauth2-google": "4.0.1",
|
||||
"greew/oauth2-azure-provider":"v1.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"rector/rector": "1.2.4"
|
||||
}
|
||||
}
|
1758
composer.lock
generiert
Normale Datei
1758
composer.lock
generiert
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
22
includes/config.plugin.php
Normale Datei
22
includes/config.plugin.php
Normale Datei
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
|
||||
|
||||
global $cfg;
|
||||
|
||||
$pluginName = basename(dirname(__DIR__, 1));
|
||||
|
||||
$cfg['plugins'][$pluginName] = cRegistry::getBackendPath() . cRegistry::getConfigValue('path', 'plugins') . $pluginName . DIRECTORY_SEPARATOR;
|
||||
|
||||
$customFunctionsFile = cRegistry::getConfigValue('plugins', $pluginName) . 'includes/functions.custom.php';
|
||||
|
||||
if (cFileHandler::exists($customFunctionsFile)) {
|
||||
plugin_include($pluginName, 'includes/functions.custom.php');
|
||||
}
|
||||
|
||||
plugin_include($pluginName, 'vendor/autoload.php');
|
||||
|
||||
$pluginClassesPath = "contenido" . DIRECTORY_SEPARATOR . cRegistry::getConfigValue('path', 'plugins') . $pluginName . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR;
|
||||
|
||||
cAutoload::addClassmapConfig([
|
||||
'PHPMailer' => $pluginClassesPath . 'PHPMailer.php'
|
||||
]);
|
176
includes/functions.custom.php
Normale Datei
176
includes/functions.custom.php
Normale Datei
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
|
||||
|
||||
use Greew\OAuth2\Client\Provider\Azure;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\OAuth;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
/**
|
||||
* @param bool|null $exception
|
||||
* @return PHPMailer
|
||||
* @throws Exception
|
||||
*/
|
||||
function initPHPMailer(bool $exception = null): PHPMailer
|
||||
{
|
||||
if(cFileHandler::exists(cRegistry::getClientConfig(1)['config']['path'] . 'config.phpmailer.php')) {
|
||||
$config = parse_ini_file(cRegistry::getClientConfig(1)['config']['path'] . 'config.phpmailer.php', true);
|
||||
} else if (cFileHandler::exists(cRegistry::getConfigValue('path', 'config') . 'config.phpmailer.php')) {
|
||||
$config = parse_ini_file(cRegistry::getConfigValue('path', 'config') . 'config.phpmailer.php', true);
|
||||
} else {
|
||||
throw new Exception("SMTP config not found!");
|
||||
}
|
||||
|
||||
$mailer = new PHPMailer($exception);
|
||||
|
||||
//Enable SMTP debugging
|
||||
//SMTP::DEBUG_OFF = off (for production use)
|
||||
//SMTP::DEBUG_CLIENT = client messages
|
||||
//SMTP::DEBUG_SERVER = client and server messages
|
||||
$mailer->SMTPDebug = SMTP::DEBUG_OFF;
|
||||
|
||||
//Tell PHPMailer to use SMTP
|
||||
$mailer->isSMTP();
|
||||
|
||||
//Set the hostname of the mail server
|
||||
$mailer->Host = $config['smtp']['host'];
|
||||
|
||||
//Set the SMTP port number:
|
||||
// - 465 for SMTP with implicit TLS, a.k.a. RFC8314 SMTPS or
|
||||
// - 587 for SMTP+STARTTLS
|
||||
$mailer->Port = $config['smtp']['port'];
|
||||
|
||||
//Set the encryption mechanism to use:
|
||||
// - SMTPS (implicit TLS on port 465) or
|
||||
// - STARTTLS (explicit TLS on port 587)
|
||||
$mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
|
||||
//Whether to use SMTP authentication
|
||||
$mailer->SMTPAuth = true;
|
||||
|
||||
//Set AuthType to use XOAUTH2
|
||||
$mailer->AuthType = 'XOAUTH2';
|
||||
|
||||
//Create a new OAuth2 provider instance
|
||||
$provider = new Azure(
|
||||
[
|
||||
'clientId' => $config['smtp']['clientId'],
|
||||
'clientSecret' => $config['smtp']['clientSecret'],
|
||||
'tenantId' => $config['smtp']['tenantId'],
|
||||
]
|
||||
);
|
||||
|
||||
//Pass the OAuth provider instance to PHPMailer
|
||||
$mailer->setOAuth(
|
||||
new OAuth(
|
||||
[
|
||||
'provider' => $provider,
|
||||
'clientId' => $config['smtp']['clientId'],
|
||||
'clientSecret' => $config['smtp']['clientSecret'],
|
||||
'refreshToken' => $config['smtp']['refreshToken'],
|
||||
'userName' => $config['smtp']['email'],
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$mailer->From = $config['smtp']['email'];
|
||||
|
||||
return $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $html
|
||||
* @param string $subject
|
||||
* @param array $recipients
|
||||
* @param array $attachments
|
||||
* @param string $fromEmail
|
||||
* @param string $fromName
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
* @throws cDbException
|
||||
* @throws cException
|
||||
* @throws phpmailerException
|
||||
*/
|
||||
function enwiSendMailSmtp(string $html, string $subject, array $recipients, array $attachments, string $fromEmail = '', string $fromName = ''): bool
|
||||
{
|
||||
$bOK = true;
|
||||
if (strlen($html) == 0) {
|
||||
echo '<pre>No message specified</pre>';
|
||||
$bOK = false;
|
||||
}
|
||||
if (strlen($subject) == 0) {
|
||||
echo '<pre>No subject specified</pre>';
|
||||
$bOK = false;
|
||||
}
|
||||
if (count($recipients) == 0 || (isset($recipients['email']) && strlen($recipients['email']) == 0) || (isset($recipients[0]['email']) && strlen($recipients[0]['email']) == 0)) {
|
||||
echo '<pre>No recipient(s) specified</pre>';
|
||||
$bOK = false;
|
||||
}
|
||||
if (!$bOK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$encoding = cRegistry::getEncoding();
|
||||
|
||||
$mail = initPHPMailer();
|
||||
$mail->CharSet = $encoding;
|
||||
|
||||
$mail->Subject = html_entity_decode($subject, ENT_QUOTES, $encoding);
|
||||
$mail->FromName = html_entity_decode(((strlen($fromName)) ? $fromName : getEffectiveSetting('email', 'sender-name')), ENT_QUOTES, $encoding);
|
||||
|
||||
// recipients
|
||||
if (isset($recipients[0]) && is_array($recipients[0])) {
|
||||
for ($i = 0, $n = count($recipients); $i < $n; $i ++) {
|
||||
if (strlen($recipients[$i]['email'])) {
|
||||
$mail->AddAddress($recipients[$i]['email'], ((strlen($recipients[$i]['name'])) ? html_entity_decode($recipients[$i]['name'], ENT_QUOTES, $encoding) : $recipients[$i]['email']));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$mail->AddAddress($recipients['email'], ((strlen($recipients['name'])) ? html_entity_decode($recipients['name'], ENT_QUOTES, $encoding) : $recipients['email']));
|
||||
}
|
||||
|
||||
// set replyto if needed
|
||||
if(filter_var($fromEmail, FILTER_VALIDATE_EMAIL)) {
|
||||
$fromName = (strlen($fromName) > 0)?$fromName:'';
|
||||
$mail->addReplyTo($fromEmail, $fromName);
|
||||
}
|
||||
|
||||
// html and only txt body
|
||||
$mail->Body = $html;
|
||||
|
||||
$message = substr($html, strpos($html, '<body'));
|
||||
$message = str_replace(array("\n", '</p>', '<br />', '<br>', '</li>'), array('', "</p>\n\n", "\n", "\n", "\n"), $message);
|
||||
$message = trim(strip_tags($message));
|
||||
$message = explode("\n", $message);
|
||||
for ($i = 0, $n = count($message); $i < $n; $i ++) {
|
||||
$message[$i] = trim($message[$i]);
|
||||
}
|
||||
$message = implode("\n", $message);
|
||||
$message = html_entity_decode($message, ENT_QUOTES, $encoding);
|
||||
try {
|
||||
$message = cString::replaceDiacritics($message);
|
||||
} catch (cInvalidArgumentException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# <-- Nur-Text-Bereich
|
||||
$mail->AltBody = $message;
|
||||
|
||||
if(count($attachments) > 0) {
|
||||
foreach ($attachments as $attachment) {
|
||||
if(is_file($attachment)) {
|
||||
$mail->addAttachment($attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mail->WordWrap = 76;
|
||||
|
||||
if ($mail->Send()) {
|
||||
return true;
|
||||
} else {
|
||||
echo '<pre>' . $mail->ErrorInfo . '</pre>';
|
||||
return false;
|
||||
}
|
||||
}
|
18
plugin.xml
Normale Datei
18
plugin.xml
Normale Datei
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<plugin>
|
||||
<general active="1">
|
||||
<plugin_name>PHPMailer</plugin_name>
|
||||
<plugin_foldername>phpmailer</plugin_foldername>
|
||||
<uuid>97537492-1120-5352-7BE8-6D34CDF5F085</uuid>
|
||||
<description></description>
|
||||
<author>Ortwin Pinke</author>
|
||||
<copyright>PHP-Backoffice.de</copyright>
|
||||
<mail>info@php-backoffice.de.de</mail>
|
||||
<website>https://php-backoffice.de</website>
|
||||
<version>1.0.0</version>
|
||||
</general>
|
||||
<requirements php="8.0.0">
|
||||
<contenido minversion="4.10.1" />
|
||||
</requirements>
|
||||
<contenido/>
|
||||
</plugin>
|
Laden …
In neuem Issue referenzieren