added phpmailer to dependencies for mail services(smtp, mailgun), update js Mailer class
parent
bedb6fdfe5
commit
9462b91246
@ -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"];
|
||||
|
||||
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"];
|
||||
}
|
||||
|
||||
$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;
|
||||
|
||||
$render = $view->render($response, "dash/email.twig", [
|
||||
"title" => "EMAIL TESTER",
|
||||
"header" => "Snarky Descriptor",
|
||||
"content" => $body["content"],
|
||||
]);
|
||||
/* 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!"];
|
||||
}
|
||||
|
||||
$email = $render->getBody()->getContents();
|
||||
echo $email;
|
||||
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 %}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue