Initial
This commit is contained in:
58
src/MDMailerHelper.php
Normal file
58
src/MDMailerHelper.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Wrapper class around mysqli.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
/**
|
||||
* MD mysqli wrapper.
|
||||
*/
|
||||
final class MDMailerHelper {
|
||||
|
||||
/**
|
||||
* PHP-encrypts a message to a given email address.
|
||||
*
|
||||
* @param string $to Recipient email address.
|
||||
* @param string $msg Message contents.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function pgp_encrypt(string $to, string $msg):string {
|
||||
|
||||
$msg = shell_exec("echo " . escapeshellarg($msg) . " | gpg2 --always-trust --recipient " . escapeshellarg($to) . " --encrypt --armor --local-user " . escapeshellarg(MD_CONF_EMAIL::PGP_ENC_KEY) . " --sign");
|
||||
if ($msg === null) return "Error encrypting message";
|
||||
return $msg;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @return PHPMailer
|
||||
*/
|
||||
public static function setup_PHPMailer():PHPMailer {
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
//Server settings
|
||||
# $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
|
||||
$mail->isSMTP(); // Send using SMTP
|
||||
$mail->Host = MD_CONF_EMAIL::SMTP_HOST; // Set the SMTP server to send through
|
||||
$mail->SMTPAuth = true; // Enable SMTP authentication
|
||||
$mail->Username = MD_CONF_EMAIL::SMTP_USERNAME; // SMTP username
|
||||
$mail->Password = MD_CONF_EMAIL::SMTP_PASSWORD; // SMTP password
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
|
||||
$mail->Port = 465; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||
|
||||
$mail->setFrom(MD_CONF_EMAIL::SMTP_FROM, MD_CONF_EMAIL::SMTP_DISPLAYED_FROM);
|
||||
$mail->addReplyTo(MD_CONF_EMAIL::SMTP_REPLY_TO_DEFAULT);
|
||||
|
||||
return $mail;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user