forked from projects/fipamo
added phpmailer to dependencies for mail services(smtp, mailgun), update js Mailer class
This commit is contained in:
parent
bedb6fdfe5
commit
9462b91246
8 changed files with 182 additions and 32 deletions
|
@ -38,6 +38,7 @@ class DashControl
|
|||
"currentTheme" => $settings["global"]["theme"],
|
||||
"themes" => $themes,
|
||||
"mailOption" => $settings["email"]["active"],
|
||||
"mailConfig" => $settings["email"],
|
||||
"status" => Session::active(),
|
||||
];
|
||||
} else {
|
||||
|
|
|
@ -1,19 +1,76 @@
|
|||
<?php
|
||||
use Slim\Views\Twig;
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class Mailer
|
||||
{
|
||||
public static function sendMail($request, $body, $response)
|
||||
{
|
||||
$view = Twig::fromRequest($request);
|
||||
$config = new Settings();
|
||||
$settings = $config->getSettings();
|
||||
$mailConfig = $settings["email"];
|
||||
|
||||
$render = $view->render($response, "dash/email.twig", [
|
||||
"title" => "EMAIL TESTER",
|
||||
"header" => "Snarky Descriptor",
|
||||
"content" => $body["content"],
|
||||
]);
|
||||
if ($body["mail_task"] == "TESTING") {
|
||||
$html =
|
||||
"<h1>Hi! It's Fipamo!</h1><br>" .
|
||||
"<strong>It's just a test</strong><br>" .
|
||||
$body["content"];
|
||||
} else {
|
||||
$html =
|
||||
"<h1>Hi! It's Fipamo!</h1><br>" .
|
||||
"<strong>Really cool content and stuff</strong><br>" .
|
||||
$body["content"];
|
||||
}
|
||||
|
||||
$email = $render->getBody()->getContents();
|
||||
echo $email;
|
||||
$mail = new PHPMailer();
|
||||
|
||||
//set values based on current active protocol
|
||||
switch ($mailConfig["active"]) {
|
||||
case "option-smtp":
|
||||
$mail->setFrom($mailConfig["smtp"]["email"], "System Email");
|
||||
$mail->Host = "playvicio.us";
|
||||
$mail->Username = $mailConfig["smtp"]["email"];
|
||||
$mail->Password = $mailConfig["smtp"]["password"];
|
||||
|
||||
break;
|
||||
case "option-mg":
|
||||
$mail->setFrom($mailConfig["mailgun"]["domain"], "No Reply");
|
||||
$mail->Host = "smtp.mailgun.org";
|
||||
$mail->Username = $mailConfig["mailgun"]["domain"];
|
||||
$mail->Password = $mailConfig["mailgun"]["key"];
|
||||
break;
|
||||
default:
|
||||
//no mail service
|
||||
return $result = [
|
||||
"type" => "noMailService",
|
||||
"message" => "Mail is not configured. Handle that.",
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
$mail->Body = $html;
|
||||
$mail->IsHTML(true);
|
||||
$mail->isSMTP();
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->SMTPSecure = "ssl";
|
||||
$mail->addAddress("services@playvicio.us", ""); //pull email address from current user
|
||||
$mail->Subject = "A test email";
|
||||
$mail->Port = 465;
|
||||
|
||||
// Uncomment for debug info
|
||||
//$mail->SMTPDebug = 4;
|
||||
|
||||
/* Finally send the mail. */
|
||||
try {
|
||||
$mail->send();
|
||||
$result = ["type" => "mailSent", "message" => "Message Away!"];
|
||||
} catch (Exception $e) {
|
||||
echo $e->errorMessage();
|
||||
$result = ["type" => "mailNotSent", "message" => "Message Not Away!"];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
{% if mailOption == "option-smtp" %}
|
||||
<div id="mail-smtp" data-enabled='true'>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="settings.email.smtp.domain"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="settings.email.smtp.email" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="settings.email.smtp.password"/>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="{{mailConfig['smtp']['domain']}}"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="{{mailConfig['smtp']['email']}}" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="{{mailConfig['smtp']['password']}}"/>
|
||||
</div>
|
||||
<div id="mail-mg" data-enabled='false'>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="settings.email.mailgun.domain" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="settings.email.mailgun.key "/>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="{{mailConfig['mailgun']['domain']}}" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="{{mailConfig['mailgun']['key']}}"/>
|
||||
</div>
|
||||
{% elseif(mailOption == 'option-mg') %}
|
||||
<div id="mail-smtp" data-enabled='false'>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="settings.email.smtp.domain"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="settings.email.smtp.email" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="settings.email.smtp.password"/>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="{{mailConfig['smtp']['domain']}}"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="{{mailConfig['smtp']['email']}}" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="{{mailConfig['smtp']['password']}}"/>
|
||||
</div>
|
||||
<div id="mail-mg" data-enabled='true'>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="settings.email.mailgun.domain" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="settings.email.mailgun.key "/>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="{{mailConfig['mailgun']['domain']}}" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="{{mailConfig['mailgun']['key']}}"/>
|
||||
</div>
|
||||
{% else %}
|
||||
<div id="mail-smtp" data-enabled='false'>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="settings.email.smtp.domain"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="settings.email.smtp.email" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="settings.email.smtp.password"/>
|
||||
<input type='text' name='smtp-domain' id='smtp-domain' placeholder='domain'value="{{mailConfig['smtp']['domain']}}"/>
|
||||
<input type='text' name='smtp-email' id='smtp-email' placeholder='email' value="{{mailConfig['smtp']['email']}}" />
|
||||
<input type='text' name='smtp-pass' id='smtp-pass' placeholder='password' value="{{mailConfig['smtp']['password']}}"/>
|
||||
</div>
|
||||
<div id="mail-mg" data-enabled='false'>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="settings.email.mailgun.domain" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="settings.email.mailgun.key "/>
|
||||
<input type='text' name='mg-domain' id='mg-domain' placeholder='domain' value="{{mailConfig['mailgun']['domain']}}" />
|
||||
<input type='text' name='mg-key' id='mg-key' placeholder='api key' value="{{mailConfig['mailgun']['key']}}"/>
|
||||
</div>
|
||||
{% endif %}
|
|
@ -8,6 +8,7 @@
|
|||
"lodash-php/lodash-php": "^0.0.7",
|
||||
"rbdwllr/reallysimplejwt": "^4.0",
|
||||
"fightbulc/moment": "^1.33",
|
||||
"tgalopin/html-sanitizer": "^1.4"
|
||||
"tgalopin/html-sanitizer": "^1.4",
|
||||
"phpmailer/phpmailer": "^6.4"
|
||||
}
|
||||
}
|
||||
|
|
78
composer.lock
generated
78
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "f829b5451dc7ceba4625d240a185b162",
|
||||
"content-hash": "c511eb33107b993cbfe6dfd51465be02",
|
||||
"packages": [
|
||||
{
|
||||
"name": "erusev/parsedown",
|
||||
|
@ -451,6 +451,82 @@
|
|||
},
|
||||
"time": "2018-02-13T20:26:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpmailer/phpmailer",
|
||||
"version": "v6.4.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHPMailer/PHPMailer.git",
|
||||
"reference": "9256f12d8fb0cd0500f93b19e18c356906cbed3d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/9256f12d8fb0cd0500f93b19e18c356906cbed3d",
|
||||
"reference": "9256f12d8fb0cd0500f93b19e18c356906cbed3d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-ctype": "*",
|
||||
"ext-filter": "*",
|
||||
"ext-hash": "*",
|
||||
"php": ">=5.5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
|
||||
"doctrine/annotations": "^1.2",
|
||||
"phpcompatibility/php-compatibility": "^9.3.5",
|
||||
"roave/security-advisories": "dev-latest",
|
||||
"squizlabs/php_codesniffer": "^3.5.6",
|
||||
"yoast/phpunit-polyfills": "^0.2.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "Needed to send email in multibyte encoding charset or decode encoded addresses",
|
||||
"hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication",
|
||||
"league/oauth2-google": "Needed for Google XOAUTH2 authentication",
|
||||
"psr/log": "For optional PSR-3 debug logging",
|
||||
"stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication",
|
||||
"symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PHPMailer\\PHPMailer\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1-only"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marcus Bointon",
|
||||
"email": "phpmailer@synchromedia.co.uk"
|
||||
},
|
||||
{
|
||||
"name": "Jim Jagielski",
|
||||
"email": "jimjag@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Andy Prevost",
|
||||
"email": "codeworxtech@users.sourceforge.net"
|
||||
},
|
||||
{
|
||||
"name": "Brent R. Matzelle"
|
||||
}
|
||||
],
|
||||
"description": "PHPMailer is a full-featured email creation and transfer class for PHP",
|
||||
"support": {
|
||||
"issues": "https://github.com/PHPMailer/PHPMailer/issues",
|
||||
"source": "https://github.com/PHPMailer/PHPMailer/tree/v6.4.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/Synchro",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2021-04-29T12:25:04+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/container",
|
||||
"version": "1.1.1",
|
||||
|
|
8
public/assets/scripts/dash.min.js
vendored
8
public/assets/scripts/dash.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -23,6 +23,21 @@ export default class Mailer {
|
|||
notify.alert(err.message, false);
|
||||
});
|
||||
}
|
||||
testMail() {
|
||||
let mailData = {
|
||||
content: "This is a test email",
|
||||
mail_task: "TESTING",
|
||||
};
|
||||
let admin = new FipamoAdminAPI();
|
||||
admin
|
||||
.sendMail(mailData)
|
||||
.then((result) => {
|
||||
notify.alert(result.message, true);
|
||||
})
|
||||
.catch((err) => {
|
||||
notify.alert(err.message, false);
|
||||
});
|
||||
}
|
||||
//--------------------------
|
||||
// event handlers
|
||||
//--------------------------
|
||||
|
|
|
@ -116,9 +116,9 @@ export default class SettingsIndex {
|
|||
}
|
||||
}
|
||||
handleMailer() {
|
||||
//let mailer = new Mailer();
|
||||
let mailer = new Mailer();
|
||||
mailer.testMail();
|
||||
//mailer.sendMail();
|
||||
notify.alert("Mail will be active soon. Hang tight", true);
|
||||
}
|
||||
handleThemes(e) {
|
||||
e.stopPropagation();
|
||||
|
|
Loading…
Reference in a new issue