ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML_XHTML_EMail Class Reference
+ Collaboration diagram for SimpleSAML_XHTML_EMail:

Public Member Functions

 __construct ($to, $subject, $from=null, $cc=null, $replyto=null)
 Constructor. More...
 
 setBody ($body)
 
 send ()
 

Private Member Functions

 getHTML ($body)
 

Private Attributes

 $to = null
 
 $cc = null
 
 $body = null
 
 $from = null
 
 $replyto = null
 
 $subject = null
 
 $headers = array()
 

Detailed Description

Definition at line 9 of file EMail.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML_XHTML_EMail::__construct (   $to,
  $subject,
  $from = null,
  $cc = null,
  $replyto = null 
)

Constructor.

Definition at line 23 of file EMail.php.

References $cc, $from, $replyto, $subject, and $to.

24  {
25  $this->to = $to;
26  $this->cc = $cc;
27  $this->from = $from;
28  $this->replyto = $replyto;
29  $this->subject = $subject;
30  }

Member Function Documentation

◆ getHTML()

SimpleSAML_XHTML_EMail::getHTML (   $body)
private

Definition at line 46 of file EMail.php.

References $body.

Referenced by send().

47  {
48  return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
49  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
50 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
51 <head>
52  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
53  <title>SimpleSAMLphp Email report</title>
54  <style type="text/css">
55 pre, div.box {
56  margin: .4em 2em .4em 1em;
57  padding: 4px;
58 
59 }
60 pre {
61  background: #eee;
62  border: 1px solid #aaa;
63 }
64  </style>
65 </head>
66 <body>
67 <div class="container" style="background: #fafafa; border: 1px solid #eee; margin: 2em; padding: .6em;">
68 ' . $body . '
69 </div>
70 </body>
71 </html>';
72  }
+ Here is the caller graph for this function:

◆ send()

SimpleSAML_XHTML_EMail::send ( )

Definition at line 78 of file EMail.php.

References $from, $headers, $message, $replyto, SimpleSAML\Logger\debug(), getHTML(), and Monolog\Handler\mail().

79  {
80  if ($this->to === null) {
81  throw new Exception('EMail field [to] is required and not set.');
82  } elseif ($this->subject === null) {
83  throw new Exception('EMail field [subject] is required and not set.');
84  } elseif ($this->body === null) {
85  throw new Exception('EMail field [body] is required and not set.');
86  }
87 
88  $random_hash = bin2hex(openssl_random_pseudo_bytes(16));
89 
90  if (isset($this->from)) {
91  $this->headers[]= 'From: ' . $this->from;
92  }
93  if (isset($this->replyto)) {
94  $this->headers[]= 'Reply-To: ' . $this->replyto;
95  }
96 
97  $this->headers[] = 'Content-Type: multipart/alternative; boundary="simplesamlphp-' . $random_hash . '"';
98 
99  $message = '
100 --simplesamlphp-' . $random_hash . '
101 Content-Type: text/plain; charset="utf-8"
102 Content-Transfer-Encoding: 8bit
103 
104 ' . strip_tags(html_entity_decode($this->body)) . '
105 
106 --simplesamlphp-' . $random_hash . '
107 Content-Type: text/html; charset="utf-8"
108 Content-Transfer-Encoding: 8bit
109 
110 ' . $this->getHTML($this->body) . '
111 
112 --simplesamlphp-' . $random_hash . '--
113 ';
114  $headers = implode("\n", $this->headers);
115 
116  $mail_sent = @mail($this->to, $this->subject, $message, $headers);
117  SimpleSAML\Logger::debug('Email: Sending e-mail to [' . $this->to . '] : ' . ($mail_sent ? 'OK' : 'Failed'));
118  if (!$mail_sent) {
119  throw new Exception('Error when sending e-mail');
120  }
121  }
static debug($string)
Definition: Logger.php:211
mail($to, $subject, $message, $additional_headers=null, $additional_parameters=null)
catch(Exception $e) $message
+ Here is the call graph for this function:

◆ setBody()

SimpleSAML_XHTML_EMail::setBody (   $body)

Definition at line 36 of file EMail.php.

References $body.

37  {
38  $this->body = $body;
39  }

Field Documentation

◆ $body

SimpleSAML_XHTML_EMail::$body = null
private

Definition at line 13 of file EMail.php.

Referenced by getHTML(), and setBody().

◆ $cc

SimpleSAML_XHTML_EMail::$cc = null
private

Definition at line 12 of file EMail.php.

Referenced by __construct().

◆ $from

SimpleSAML_XHTML_EMail::$from = null
private

Definition at line 14 of file EMail.php.

Referenced by __construct(), and send().

◆ $headers

SimpleSAML_XHTML_EMail::$headers = array()
private

Definition at line 17 of file EMail.php.

Referenced by send().

◆ $replyto

SimpleSAML_XHTML_EMail::$replyto = null
private

Definition at line 15 of file EMail.php.

Referenced by __construct(), and send().

◆ $subject

SimpleSAML_XHTML_EMail::$subject = null
private

Definition at line 16 of file EMail.php.

Referenced by __construct().

◆ $to

SimpleSAML_XHTML_EMail::$to = null
private

Definition at line 11 of file EMail.php.

Referenced by __construct().


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