1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87:
<?php
include_once PATH_TO_ROOT . '/kernel/lib/php/phpmailer/src/Exception.php';
include_once PATH_TO_ROOT . '/kernel/lib/php/phpmailer/src/PHPMailer.php';
include_once PATH_TO_ROOT . '/kernel/lib/php/phpmailer/src/SMTP.php';
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
class MailToPHPMailerConverter
{
private $mailer;
private $mail_to_send;
public function convert(Mail $mail)
{
$this->mail_to_send = $mail;
$this->mailer = new PHPMailer(true);
$this->mailer->CharSet = 'utf-8';
$this->mailer->SMTPAutoTLS = false;
$this->convert_mail();
return $this->mailer;
}
private function convert_mail()
{
foreach ($this->mail_to_send->get_recipients() as $recipient => $name)
{
$this->mailer->AddAddress($recipient, $name);
}
foreach ($this->mail_to_send->get_cc_recipients() as $recipient => $name)
{
$this->mailer->AddCC($recipient, $name);
}
foreach ($this->mail_to_send->get_bcc_recipients() as $recipient => $name)
{
$this->mailer->AddBCC($recipient, $name);
}
$this->mailer->SetFrom($this->mail_to_send->get_sender_mail(), $this->mail_to_send->get_sender_name());
$this->mailer->AddReplyTo($this->mail_to_send->get_reply_to_mail() ? $this->mail_to_send->get_reply_to_mail() : $this->mail_to_send->get_sender_mail(), $this->mail_to_send->get_reply_to_name() ? $this->mail_to_send->get_reply_to_name() : $this->mail_to_send->get_sender_name());
$this->mailer->Subject = $this->mail_to_send->get_subject();
$this->convert_content();
}
private function convert_content()
{
if ($this->mail_to_send->is_html())
{
$this->mailer->MsgHTML($this->mail_to_send->get_content());
}
else
{
$this->mailer->Body = $this->mail_to_send->get_content();
}
}
}
?>