ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMailMimeTransportBase Class Reference

Class ilMailMimeTransportBase. More...

+ Inheritance diagram for ilMailMimeTransportBase:
+ Collaboration diagram for ilMailMimeTransportBase:

Public Member Functions

 __construct (\ilSetting $settings)
 ilMailMimeTransportBase constructor. More...
 
 send (ilMimeMail $mail)
 
Parameters
ilMimeMail$mail
Returns
bool
More...
 

Protected Member Functions

 getMailer ()
 
 setMailer ($mailer)
 
 resetMailer ()
 
 onBeforeSend ()
 

Protected Attributes

 $mailer
 
 $settings
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMailMimeTransportBase::__construct ( \ilSetting  $settings)

ilMailMimeTransportBase constructor.

Parameters
\ilSetting$settings

Definition at line 26 of file class.ilMailMimeTransportBase.php.

References $settings, setMailer(), and settings().

27  {
28  $this->settings = $settings;
29 
30  require_once 'libs/composer/vendor/autoload.php';
31  $mail = new PHPMailer();
32  $this->setMailer($mail);
33  }
PHPMailer - PHP email creation and transport class.
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

Member Function Documentation

◆ getMailer()

ilMailMimeTransportBase::getMailer ( )
protected
Returns
PHPMailer

Definition at line 38 of file class.ilMailMimeTransportBase.php.

References $mailer.

Referenced by resetMailer(), and send().

+ Here is the caller graph for this function:

◆ onBeforeSend()

ilMailMimeTransportBase::onBeforeSend ( )
protected

Definition at line 61 of file class.ilMailMimeTransportBase.php.

Referenced by send().

62  {
63  }
+ Here is the caller graph for this function:

◆ resetMailer()

ilMailMimeTransportBase::resetMailer ( )
protected

Definition at line 51 of file class.ilMailMimeTransportBase.php.

References getMailer().

Referenced by send().

52  {
53  $this->getMailer()->clearAllRecipients();
54  $this->getMailer()->clearAttachments();
55  $this->getMailer()->clearReplyTos();
56  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ send()

ilMailMimeTransportBase::send ( ilMimeMail  $mail)
final

Parameters
ilMimeMail$mail
Returns
bool

Implements ilMailMimeTransport.

Definition at line 68 of file class.ilMailMimeTransportBase.php.

References $GLOBALS, $message, $result, ilMimeMail\getAttachments(), ilMimeMail\getBcc(), ilMimeMail\getCc(), ilMimeMail\getFinalBody(), ilMimeMail\getFinalBodyAlt(), ilMimeMail\getFrom(), ilMimeMail\getImages(), ilLoggerFactory\getLogger(), getMailer(), ilMimeMail\getSubject(), ilMimeMail\getTo(), onBeforeSend(), resetMailer(), and user().

69  {
70  $this->resetMailer();
71 
72  foreach ($mail->getTo() as $recipients) {
73  $recipient_pieces = array_filter(array_map('trim', explode(',', $recipients)));
74  foreach ($recipient_pieces as $recipient) {
75  $this->getMailer()->AddAddress($recipient, '');
76  }
77  }
78 
79  foreach ($mail->getCc() as $carbon_copies) {
80  $cc_pieces = array_filter(array_map('trim', explode(',', $carbon_copies)));
81  foreach ($cc_pieces as $carbon_copy) {
82  $this->getMailer()->AddCC($carbon_copy, '');
83  }
84  }
85 
86  foreach ($mail->getBcc() as $blind_carbon_copies) {
87  $bcc_pieces = array_filter(array_map('trim', explode(',', $blind_carbon_copies)));
88  foreach ($bcc_pieces as $blind_carbon_copy) {
89  $this->getMailer()->AddBCC($blind_carbon_copy, '');
90  }
91  }
92 
93  $this->getMailer()->Subject = $mail->getSubject();
94 
95  if ($mail->getFrom()->hasReplyToAddress()) {
96  $this->getMailer()->addReplyTo($mail->getFrom()->getReplyToAddress(), $mail->getFrom()->getReplyToName());
97  }
98  if ($mail->getFrom()->hasEnvelopFromAddress()) {
99  $this->getMailer()->Sender = $mail->getFrom()->getEnvelopFromAddress();
100  }
101  $this->getMailer()->setFrom($mail->getFrom()->getFromAddress(), $mail->getFrom()->getFromName(), false);
102 
103  foreach ($mail->getAttachments() as $attachment) {
104  $this->getMailer()->AddAttachment($attachment['path'], $attachment['name']);
105  }
106 
107  foreach ($mail->getImages() as $image) {
108  $this->getMailer()->AddEmbeddedImage($image['path'], $image['cid'], $image['name']);
109  }
110 
111  if ($mail->getFinalBodyAlt()) {
112  $this->getMailer()->IsHTML(true);
113  $this->getMailer()->AltBody = $mail->getFinalBodyAlt();
114  $this->getMailer()->Body = $mail->getFinalBody();
115  } else {
116  $this->getMailer()->IsHTML(false);
117  $this->getMailer()->AltBody = '';
118  $this->getMailer()->Body = $mail->getFinalBody();
119  }
120 
121  ilLoggerFactory::getLogger('mail')->info(sprintf(
122  "Trying to delegate external email delivery:" .
123  " Initiated by: %s (%s) " .
124  "| To: %s | CC: %s | BCC: %s | Subject: %s " .
125  "| From: %s / %s " .
126  "| ReplyTo: %s / %s " .
127  "| EnvelopeFrom: %s",
128  $GLOBALS['DIC']->user()->getLogin(),
129  $GLOBALS['DIC']->user()->getId(),
130  implode(', ', $mail->getTo()),
131  implode(', ', $mail->getCc()),
132  implode(', ', $mail->getBcc()),
133  $mail->getSubject(),
134  $mail->getFrom()->getFromAddress(),
135  $mail->getFrom()->getFromName(),
136  $mail->getFrom()->getReplyToAddress(),
137  $mail->getFrom()->getReplyToName(),
138  $mail->getFrom()->getEnvelopFromAddress()
139  ));
140 
141  $this->getMailer()->CharSet = 'utf-8';
142 
143  $this->mailer->SMTPDebug = 4;
144  $this->mailer->Debugoutput = function ($message, $level) {
145  ilLoggerFactory::getLogger('mail')->debug($message);
146  };
147 
148  $this->onBeforeSend();
149  $result = $this->getMailer()->Send();
150  if ($result) {
151  ilLoggerFactory::getLogger('mail')->info(sprintf(
152  'Successfully delegated external mail delivery'
153  ));
154  } else {
155  ilLoggerFactory::getLogger('mail')->warning(sprintf(
156  'Could not deliver external email: %s',
157  $this->getMailer()->ErrorInfo
158  ));
159  }
160 
161  return $result;
162  }
$result
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
user()
Definition: user.php:4
catch(Exception $e) $message
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

◆ setMailer()

ilMailMimeTransportBase::setMailer (   $mailer)
protected
Parameters
PHPMailer$mailer

Definition at line 46 of file class.ilMailMimeTransportBase.php.

References $mailer.

Referenced by __construct().

47  {
48  $this->mailer = $mailer;
49  }
+ Here is the caller graph for this function:

Field Documentation

◆ $mailer

ilMailMimeTransportBase::$mailer
protected

Definition at line 15 of file class.ilMailMimeTransportBase.php.

Referenced by getMailer(), and setMailer().

◆ $settings

ilSetting ilMailMimeTransportBase::$settings
protected

Definition at line 20 of file class.ilMailMimeTransportBase.php.

Referenced by __construct().


The documentation for this class was generated from the following file: