LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_mailer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
20require_once (LEPTON_PATH . "/modules/lib_phpmailer/library.php");
21
22class LEPTON_mailer extends PHPMailer\PHPMailer\PHPMailer
23{
24
28 public static $instance;
29
35 public static function getInstance( &$settings=array() )
36 {
37 if (null === static::$instance)
38 {
39 static::$instance = new static();
40 static::$instance->__construct();
41 }
42
43 // clear all "old" addresses
44 static::$instance->clearAllRecipients(); // seems not to work by getInstance()
45
46 return static::$instance;
47 }
48
52 public function __construct()
53 {
54 // set method to send out emails
55 if ( MAILER_ROUTINE == "smtp" && strlen( MAILER_SMTP_HOST ) > 5 )
56 {
57 $bCheckModul = extension_loaded('openssl');
58 // use SMTP for all outgoing mails send
59 $this->IsSMTP();
60 $this->SMTPAuth = true; // default if smtp
61 $this->SMTPSecure = MAILER_SMTP_SECURE;
62 $this->Port = MAILER_SMTP_PORT;
63
64 // check if decrypting possible
65 if ( $bCheckModul === true)
66 {
67 // decrypt values
68 $this->Host = LEPTON_database::decryptstring(MAILER_SMTP_HOST);
69 $this->Username = LEPTON_database::decryptstring(MAILER_SMTP_USERNAME);
70 $this->Password = LEPTON_database::decryptstring(MAILER_SMTP_PASSWORD);
71 }
72 else
73 {
74 // use unencrypted values
75 $this->Host = MAILER_SMTP_HOST;
76 $this->Username = MAILER_SMTP_USERNAME;
77 $this->Password = MAILER_SMTP_PASSWORD;
78 }
79 }
80 else
81 {
82 // use PHP mail() function for outgoing mails send by Website Baker
83 $this->IsMail();
84 }
85
86 // set language file for PHPMailer error messages
87 if ( defined( "LANGUAGE" ) )
88 {
89 $this->SetLanguage( strtolower( LANGUAGE ), "language" ); // english default (also used if file is missing)
90 }
91
92 // set default charset
93 $this->CharSet = defined( 'DEFAULT_CHARSET' ) ? DEFAULT_CHARSET : 'utf-8';
94
95 // set default sender name
96 if ( $this->FromName == 'Root User' )
97 {
98 $this->FromName = isset( $_SESSION[ 'DISPLAY_NAME' ] )
99 ? $_SESSION[ 'DISPLAY_NAME' ]
100 : MAILER_DEFAULT_SENDERNAME
101 ;
102 }
103
104 /*
105 some mail provider (lets say mail.com) reject mails send out by foreign mail
106 relays but using the providers domain in the from mail address (e.g. myname@mail.com)
107 */
108 $this->From = SERVER_EMAIL; // FROM MAIL: (server mail)
109
110 // set default mail formats
111 $this->IsHTML( true );
112 $this->WordWrap = 80;
113 $this->Timeout = 30;
114 }
115
126 public function sendmail( $sFrom="", $sSendTo="", $sSubject="", $sMessage="")
127 {
128 $this->From = $sFrom;
129 $this->AddAddress( $sSendTo );
130 $this->Subject = $sSubject; // SUBJECT
131 $this->Body = $sMessage; // CONTENT (HTML)
132 $this->AltBody = $sMessage; // CONTENT (PLAINTEXT)
133 $this->CharSet="UTF-8"; // force text to be utf-8
134
135 return $this->send();
136 }
137}
sendmail( $sFrom="", $sSendTo="", $sSubject="", $sMessage="")
static getInstance(&$settings=array())