CMS  Version 3.9
EmailHandler Class Reference

Public Member Functions

 EmailHandler ($toAddr, $subject, $message="", $emailFrom="", $emailName="", $attachments=array(), $iCalMgr=null)
 
 getMessageScript ($msg, $random_hash, $attachments, $iCalMgr)
 
 formatAttachments ($attachments, $random_hash)
 
 formatiCalendar ($iCalMgr, $random_hash)
 The iCal event should come in formatted by the event handler formatICal function. More...
 
 send ()
 

Public Attributes

 $transport
 
 $onSendComplete
 

Detailed Description

Definition at line 171 of file email_manager.inc.

Member Function Documentation

◆ EmailHandler()

EmailHandler::EmailHandler (   $toAddr,
  $subject,
  $message = "",
  $emailFrom = "",
  $emailName = "",
  $attachments = array(),
  $iCalMgr = null 
)
Parameters
String$toAddr
String$subject
String$message
String$emailFrom- if blank, use settings email_from; if not blank and != settings, set this value into Reply To header instead
String$emailName- same as above
Array$attachments- optional array of full file paths to attach. Key is display name of file (which may be the same as the basename of the file path), value is santized file path. If a string is received, it will be conerted to an array with the key the basename of the path
iCalendarEventManagerobj $iCalMgr

Definition at line 188 of file email_manager.inc.

189  {
190  global $config;
191 
192  $site_email_from = Settings::getValue('email', 'email_from');
193  $site_email_name = Settings::getValue('email', 'email_name');
194 
195  $replyTo = $site_email_from;
196  $replyToName = $site_email_name;
197 
198  if($emailFrom)
199  {
200  $replyTo = $emailFrom;
201  }
202 
203  if($emailName)
204  {
205  $replyToName = $emailName;
206  }
207 
208  $toAddr = trim($toAddr);
209 
210  if ($config['html_email_template'])
211  {
212  $file = $config['homedir'] . $config['html_email_template'];
213  trace("Loading email template '$file'", 3);
214  $template = file_get_contents($file);
215  $template = str_replace("{var:styles}", Fakoli::getStyles(), $template);
216  $message = str_replace("{message}", $message, $template);
217  }
218 
219  $this->transport = EmailManager::createTransport();
220 
221  $this->transport->setTo($toAddr);
222  $this->transport->setFrom($site_email_from, $site_email_name);
223  $this->transport->setReplyTo($replyTo, $replyToName);
224  $this->transport->setReturnPAth($site_email_from);
225  $this->transport->setSubject($subject);
226  $this->transport->setHTMLMessage($message);
227  $this->transport->setPlainMessage(HTMLToText($message));
228 
229  if($attachments && !is_array($attachments))
230  {
231  $attachments = array_combine(basename($attachments), $attachments);
232  }
233 
234  foreach($attachments as $filename => $attachment)
235  {
236  $this->transport->addAttachment($filename, $attachment);
237  }
238 
239  if($iCalMgr)
240  {
241  $iCalMgr->setOrganizer($replyTo, $replyToName);
242  $iCalMgr->setAttendee($toAddr);
243 
244  $this->transport->setICalAttachment($iCalMgr->format(), $iCalMgr->data->get("method"));
245  }
246 
247  }
if(! $attachment_id) $attachment
Definition: delete.inc:42
$file
Definition: delete.inc:47
static createTransport($mode=null)
static getStyles()
Returns the HTML link tags for CSS files specified by the registered components in their manifest fil...
Definition: core.inc:603
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $config
Definition: import.inc:4
$message
Definition: mail_to.inc:49
if(!Settings::getValue("debug", "enable_trace_file_downloads")) $filename
Definition: trace.inc:42

◆ formatAttachments()

EmailHandler::formatAttachments (   $attachments,
  $random_hash 
)
Parameters
HTML$message
Array$files- files to attach

Definition at line 302 of file email_manager.inc.

303  {
304  if(!count($attachments)) return "";
305 
306  foreach($attachments as $display_name => $attachment)
307  {
308  if(is_file($attachment))
309  {
310  $base_filename = basename($attachment);
311 
312  $fileAttachments .= "----PHP-alt-{$random_hash}\n";
313  $fp = @fopen($attachment, "rb");
314  $fileContents = @fread($fp, filesize($attachment));
315  @fclose($fp);
316  $fileContents = chunk_split(base64_encode($fileContents));
317  $fileAttachments .= "Content-Type: application/octet-stream; name=\"". $base_filename ."\"\n" .
318  "Content-Description: ".$base_filename."\n" .
319  "Content-Disposition: attachment;\n" . " filename=\"".$display_name ."\"; size=".filesize($attachment).";\n" .
320  "Content-Transfer-Encoding: base64\n\n" .$fileContents . "\n\n";
321  }
322  }
323 
324  return $fileAttachments;
325  }

◆ formatiCalendar()

EmailHandler::formatiCalendar (   $iCalMgr,
  $random_hash 
)

The iCal event should come in formatted by the event handler formatICal function.

Here we provide the organizer's email if not already set, based on the reply to email and format the header for this block.

Definition at line 334 of file email_manager.inc.

335  {
336  $method = $iCalMgr->data->get("method");
337 
338  $cal_message = "----PHP-alt-{$random_hash}\n";
339  $cal_message .= "Content-Type: text/calendar; charset=utf-8;method={$method}\n";
340  $cal_message .= "Content-Disposition: inline; filename=meeting.ics\n";
341  $cal_message .= "Content-Transfer-Encoding: 8bit\n";
342 
343  $cal_message .= $iCalMgr->format();
344 
345  return $cal_message;
346  }
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573

◆ getMessageScript()

EmailHandler::getMessageScript (   $msg,
  $random_hash,
  $attachments,
  $iCalMgr 
)

Definition at line 253 of file email_manager.inc.

254  {
255  global $config;
256 
257 
258  $fileAttachments = $this->formatAttachments($attachments, $random_hash);
259 
260  if($iCalMgr)
261  {
262  $iCal = $this->formatiCalendar($iCalMgr, $random_hash);
263  }
264 
265  //define the body of the message.
266  ob_start(); //Turn on output buffering
267  ?>
268 
269 ----PHP-alt-<?php echo "$random_hash\n"; ?>
270 Content-Type: text/plain
271 Content-Disposition: inline
272 Content-Transfer-Encoding: 8bit
273 
274 <?php echo trim(HTMLToText($msg)); ?>
275 
276 
277 ----PHP-alt-<?php echo "$random_hash\n"; ?>
278 Content-Type: text/html
279 Content-Disposition: inline
280 Content-Transfer-Encoding: 8bit
281 
282 <?php echo $html ?>
283 
284 <?php echo $fileAttachments ?>
285 
286 <?php echo $iCal ?>
287 
288 ----PHP-alt-<?php echo $random_hash; ?>--
289  <?php
290  //copy current buffer contents into $message variable
291  // and delete current output buffer
292  $message = ob_get_clean();
293 
294  return $message;
295  }
formatiCalendar($iCalMgr, $random_hash)
The iCal event should come in formatted by the event handler formatICal function.
formatAttachments($attachments, $random_hash)
$msg
Definition: save.inc:10

◆ send()

EmailHandler::send ( )

Definition at line 348 of file email_manager.inc.

349  {
350  $rtn = $this->transport->send();
351 
352  trace("EmailHandler send rtn $rtn", 3);
353  // Call the callback whether successful or not; calling script
354  // decides how to handle either way.
355  if ($this->onSendComplete AND is_callable($this->onSendComplete))
356  {
357  call_user_func($this->onSendComplete, $rtn);
358  }
359  return $rtn;
360  }

Member Data Documentation

◆ $onSendComplete

EmailHandler::$onSendComplete

Definition at line 174 of file email_manager.inc.

◆ $transport

EmailHandler::$transport

Definition at line 173 of file email_manager.inc.


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