Replace mail() with PHPMailer + new logo

This commit is contained in:
2020-04-06 17:53:49 +02:00
parent 13a9155634
commit 66a9a566c0
11 changed files with 6875 additions and 6 deletions

View File

@@ -1,4 +1,11 @@
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once 'inc/PHPMailer/Exception.php';
require_once 'inc/PHPMailer/PHPMailer.php';
require_once 'inc/PHPMailer/SMTP.php';
class Email extends PhpObject {
@@ -62,7 +69,7 @@ class Email extends PhpObject {
$this->asDests = $asDests;
}
public function send() {
/*public function send() {
$sEOL = "\r\n";
foreach($this->asDests as $asDest) {
//Message
@@ -102,5 +109,55 @@ class Email extends PhpObject {
//Send
if(!mail($asDest['email'], $asTemplate['subject'], $sBody, $sHeaders)) $this->addError('Could not send '.$this->sTemplate.' email to '.$asDest['email']);
}
}*/
public function send() {
//Instantiation and passing `true` enables exceptions
$oPHPMailer = new PHPMailer(true);
//Server settings
if(Settings::DEBUG) $oPHPMailer->SMTPDebug = SMTP::DEBUG_SERVER;//Enable verbose debug output
$oPHPMailer->isSMTP(); //Send using SMTP
$oPHPMailer->CharSet = Settings::TEXT_ENC; //Mail Character Set
$oPHPMailer->Encoding = 'base64'; //Base 64 Character Encoding
$oPHPMailer->Host = Settings::MAIL_SERVER; //Set the SMTP server to send through
$oPHPMailer->SMTPAuth = true; //Enable SMTP authentication
$oPHPMailer->Username = Settings::MAIL_USER; //SMTP username
$oPHPMailer->Password = Settings::MAIL_PASS; //SMTP password
$oPHPMailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$oPHPMailer->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
$oPHPMailer->setFrom(Settings::MAIL_USER, 'Spotty');
$oPHPMailer->addReplyTo(Settings::MAIL_USER, 'Spotty');
foreach($this->asDests as $asDest) {
try {
//Message
$asTemplate = $this->getTemplate($asDest['language']);
$oEmail = $asTemplate['email'];
//Unsubscribe Link
$sUnsubLink = $this->sServName.'?a=unsubscribe_email&id='.$asDest['id_user'];
$oEmail->setTag('unsubscribe_link', $sUnsubLink);
//Email Content
$sHtmlMessage = $oEmail->getMask();
$sPlainMessage = strip_tags(str_replace('<br />', "\n", $sHtmlMessage));
//Recipients
$oPHPMailer->addAddress($asDest['email'], $asDest['name']);
//Content
$oPHPMailer->isHTML(true);
$oPHPMailer->Subject = $asTemplate['subject'];
$oPHPMailer->Body = $sHtmlMessage;
$oPHPMailer->AltBody = $sPlainMessage;
$oPHPMailer->send();
}
catch (Exception $e) {
$this->addError('Message could not be sent to "'.$asDest['email'].'". Mailer Error: '.$oPHPMailer->ErrorInfo);
}
}
}
}