CMS  Version 3.9
Mail Class Reference

Public Member Functions

 Mail ($from, $to, $subject, $body="", $headers="", $fullFrom="")
 
 send ()
 

Public Attributes

 $server
 
 $port
 
 $from
 
 $to
 
 $fullFrom
 
 $subject
 
 $body
 
 $headers
 

Detailed Description

Definition at line 39 of file mail.inc.

Member Function Documentation

◆ Mail()

Mail::Mail (   $from,
  $to,
  $subject,
  $body = "",
  $headers = "",
  $fullFrom = "" 
)

Definition at line 51 of file mail.inc.

52  {
53  if (Settings::getValue("email", "override_PHP_settings"))
54  {
55  $this->server = Settings::getValue("email", "mail_server");
56  $this->port = Settings::getValue("email", "smtp_port");
57  }
58  else
59  {
60  $this->server = ini_get("SMTP");
61  $this->port = ini_get("smtp_port");
62  }
63 
64  $this->from = $from;
65  $this->to = $to;
66  $this->subject = encode7bit($subject);
67  $this->body = $body;
68  $this->headers = $headers;
69  $this->fullFrom = encode7bit($fullFrom);
70  }
$to
Definition: mail.inc:44
$fullFrom
Definition: mail.inc:45
$from
Definition: mail.inc:43
$body
Definition: mail.inc:48
$headers
Definition: mail.inc:49
$subject
Definition: mail.inc:47
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
$forumRequest to
$documentMove from
$email subject

◆ send()

Mail::send ( )

Definition at line 72 of file mail.inc.

73  {
74  $debug = Settings::getValue("email", "use_debugging_mode");
75  $debugPath = Settings::getValue("email", "debugging_mode_output_path");
76 
77  if ($debug)
78  {
79  $fp = fopen($debugPath . DIRECTORY_SEPARATOR . $this->to, 'a');
80  if($fp === FALSE)
81  {
82  trace("Mail: unable to open debug log file in $debugPath name {$this->to}", 3);
83  return false;
84  }
85 
86  $rtn = fwrite($fp, "From: $this->from\n".
87  "To: $this->to\n".
88  $this->headers.
89  "Subject: $this->subject\n".
90  "\n".
91  "$this->body\n\n");
92 
93  if($rtn === FALSE)
94  {
95  trace("Mail: unable to write to debug log file in $debugPath name {$this->to}", 3);
96  return false;
97  }
98 
99  fclose($fp);
100  return true;
101  }
102 
103  $smtp = new SMTP;
104  //$smtp->do_debug = 1; # sets the amount of debug information we get
105 
106  # connect to the smtp server
107  if(!$smtp->connect($this->server, $this->smtp_port))
108  {
109  die ("Error: " . $smtp->error["error"] . "\n");
110  }
111 
112  # say hello so we all know who we are
113  $smtp->Hello();
114 
115  $username = Settings::getValue("email", "username");
116  $password = Settings::getValue("email", "password");
117 
118  if ($username && $password)
119  {
120  if (!$smtp->Authenticate($username, $password))
121  {
122  $err = $smtp->error["error"];
123  trace("SMTP Authentication failed: $err", 1);
124  $smtp->quit();
125  throw new FakoliException($err);
126  }
127  }
128 
129  # start the mail transaction with with the return path address
130  $smtp->Mail($this->from);
131 
132  if ($smtp->error) trace("FROM: ".print_r($smtp->error, true), 2);
133 
134  # state each recipient
135  # NOTE: this does _not_ add to: or cc: headers to the email
136  $smtp->Recipient($this->to);
137 
138 
139  if ($smtp->error) trace("RCPT: ".print_r($smtp->error, true), 2);
140 
141  if (!$this->fullFrom) $this->fullFrom = $this->from;
142 
143  # send the message including headers (headers must be followed by an
144  # empty newline
145  $data = "From: $this->fullFrom\n".
146  "To: $this->to\n".
147  $this->headers.
148  "Subject: $this->subject\n".
149  "\n".
150  "$this->body\n";
151 
152  $smtp->Data($data);
153 
154  if ($smtp->error) trace(print_r($smtp->error, true), 2);
155 
156  # the mail either been sent or failed either way we are done
157  $smtp->quit();
158 
159  return true;
160  }
$err
Definition: error_log.inc:9
$username
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
Definition: smtp.inc:54

Member Data Documentation

◆ $body

Mail::$body

Definition at line 48 of file mail.inc.

◆ $from

Mail::$from

Definition at line 43 of file mail.inc.

◆ $fullFrom

Mail::$fullFrom

Definition at line 45 of file mail.inc.

◆ $headers

Mail::$headers

Definition at line 49 of file mail.inc.

◆ $port

Mail::$port

Definition at line 42 of file mail.inc.

◆ $server

Mail::$server

Definition at line 41 of file mail.inc.

◆ $subject

Mail::$subject

Definition at line 47 of file mail.inc.

◆ $to

Mail::$to

Definition at line 44 of file mail.inc.


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