This commit is contained in:
2020-10-21 01:42:10 +02:00
committed by Stefan Rohde-Enslin
commit 12c4a0abf8
2 changed files with 307 additions and 0 deletions

58
src/MDMailerHelper.php Normal file
View 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;
}
}