LEPTON CMS 7.0.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 // use SMTP for all outgoing mails send
58 $this->IsSMTP();
59 $this->Host = MAILER_SMTP_HOST;
60
61 // check if SMTP authentification is required
62 if ( MAILER_SMTP_AUTH == "true" && strlen( MAILER_SMTP_USERNAME ) > 1 && strlen( MAILER_SMTP_PASSWORD ) > 1 )
63 {
64 // use SMTP authentification
65 $this->SMTPAuth = true; // enable SMTP authentification
66 $this->Username = MAILER_SMTP_USERNAME; // set SMTP username
67 $this->Password = MAILER_SMTP_PASSWORD; // set SMTP password
68
69 $this->SMTPSecure = MAILER_SMTP_SECURE;
70 $this->Port = MAILER_SMTP_PORT;
71 }
72 }
73 else
74 {
75 // use PHP mail() function for outgoing mails send by Website Baker
76 $this->IsMail();
77 }
78
79 // set language file for PHPMailer error messages
80 if ( defined( "LANGUAGE" ) )
81 {
82 $this->SetLanguage( strtolower( LANGUAGE ), "language" ); // english default (also used if file is missing)
83 }
84
85 // set default charset
86 $this->CharSet = defined( 'DEFAULT_CHARSET' ) ? DEFAULT_CHARSET : 'utf-8';
87
88 // set default sender name
89 if ( $this->FromName == 'Root User' )
90 {
91 $this->FromName = isset( $_SESSION[ 'DISPLAY_NAME' ] )
92 ? $_SESSION[ 'DISPLAY_NAME' ]
93 : MAILER_DEFAULT_SENDERNAME
94 ;
95 }
96
97 /*
98 some mail provider (lets say mail.com) reject mails send out by foreign mail
99 relays but using the providers domain in the from mail address (e.g. myname@mail.com)
100 */
101 $this->From = SERVER_EMAIL; // FROM MAIL: (server mail)
102
103 // set default mail formats
104 $this->IsHTML( true );
105 $this->WordWrap = 80;
106 $this->Timeout = 30;
107 }
108
119 public function sendmail( $sFrom="", $sSendTo="", $sSubject="", $sMessage="")
120 {
121 $this->From = $sFrom;
122 $this->AddAddress( $sSendTo );
123 $this->Subject = $sSubject; // SUBJECT
124 $this->Body = $sMessage; // CONTENT (HTML)
125 $this->AltBody = $sMessage; // CONTENT (PLAINTEXT)
126 $this->CharSet="UTF-8"; // force text to be utf-8
127
128 return $this->send();
129 }
130}
sendmail( $sFrom="", $sSendTo="", $sSubject="", $sMessage="")
static getInstance(&$settings=array())