Changeset 292 for branches/1.1dev
- Timestamp:
- Dec 9, 2007 1:14:19 AM (16 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/lib/Email.inc.php
r291 r292 7 7 * 8 8 * @author Quinn Comendant <quinn@strangecode.com> 9 * @version 1.0 9 * @version 1.0 - backported to codebase v1.1dev 10 10 * 11 11 … … 13 13 $email = new Email(array( 14 14 'to' => array($frm['email'], 'q@lovemachine.local'), 15 'from' => sprintf('%s <%s>', $ app->getParam('site_name'), $app->getParam('site_email')),15 'from' => sprintf('%s <%s>', $CFG->site_name, $CFG->site_email), 16 16 'subject' => 'Your account has been activated', 17 17 )); … … 19 19 // $email->setString('Or you can pass your message body as a string, also with {VARIABLES}.'); 20 20 $email->replace(array( 21 ' site_name' => $app->getParam('site_name'),22 ' site_url' => $app->getParam('site_url'),23 ' username' => $frm['username'],24 ' password' => $frm['password1'],21 'SITE_NAME' => $CFG->site_name, 22 'SITE_URL' => $CFG->site_url, 23 'USERNAME' => $frm['username'], 24 'PASSWORD' => $frm['password1'], 25 25 )); 26 26 if ($email->send()) { 27 $app->raiseMsg(sprintf(_("A confirmation email has been sent to %s."), $frm['email']), MSG_SUCCESS, __FILE__, __LINE__);27 raiseMsg(sprintf(_("A confirmation email has been sent to %s."), $frm['email']), MSG_SUCCESS, __FILE__, __LINE__); 28 28 } else { 29 $app->logMsg(sprintf('Error sending confirmation email to address %s', $frm['email']), LOG_NOTICE, __FILE__, __LINE__);29 logMsg(sprintf('Error sending confirmation email to address %s', $frm['email']), LOG_NOTICE, __FILE__, __LINE__); 30 30 } 31 31 … … 99 99 function setParam($params) 100 100 { 101 $app =& App::getInstance();102 103 101 if (isset($params) && is_array($params)) { 104 102 // Enforce valid email addresses. … … 113 111 $this->_params = array_merge($this->_params, $params); 114 112 } else { 115 $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);113 logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__); 116 114 } 117 115 } … … 126 124 function getParam($param) 127 125 { 128 $app =& App::getInstance();129 130 126 if (isset($this->_params[$param])) { 131 127 return $this->_params[$param]; 132 128 } else { 133 $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);129 logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); 134 130 return null; 135 131 } … … 146 142 function setTemplate($template) 147 143 { 148 $app =& App::getInstance();149 150 144 // Load file, using include_path. 151 145 if (!$this->_template = file_get_contents($template, true)) { 152 $app->logMsg(sprintf('Email template file does not exist: %s', $template), LOG_ERR, __FILE__, __LINE__);146 logMsg(sprintf('Email template file does not exist: %s', $template), LOG_ERR, __FILE__, __LINE__); 153 147 $this->_template = null; 154 148 $this->_template_replaced = null; … … 170 164 function setString($string) 171 165 { 172 $app =& App::getInstance();173 174 166 // Load file, using include_path. 175 167 if ('' == trim($string)) { 176 $app->logMsg(sprintf('Empty string provided.', null), LOG_ERR, __FILE__, __LINE__);168 logMsg(sprintf('Empty string provided.', null), LOG_ERR, __FILE__, __LINE__); 177 169 $this->_template_replaced = null; 178 170 return false; … … 195 187 function replace($replacements) 196 188 { 197 $app =& App::getInstance();198 189 199 190 // Ensure template exists. 200 191 if (!isset($this->_template)) { 201 $app->logMsg(sprintf('Cannot replace variables, no template defined.', null), LOG_ERR, __FILE__, __LINE__);192 logMsg(sprintf('Cannot replace variables, no template defined.', null), LOG_ERR, __FILE__, __LINE__); 202 193 return false; 203 194 } … … 205 196 // Ensure replacements argument is an array. 206 197 if (!is_array($replacements)) { 207 $app->logMsg(sprintf('Cannot replace variables, invalid replacements.', null), LOG_ERR, __FILE__, __LINE__);198 logMsg(sprintf('Cannot replace variables, invalid replacements.', null), LOG_ERR, __FILE__, __LINE__); 208 199 return false; 209 200 } … … 232 223 function send($to=null, $from=null, $subject=null, $headers=null) 233 224 { 234 $app =& App::getInstance();235 236 225 // Use arguments if provided. 237 226 if (isset($to)) { … … 250 239 // Ensure required values exist. 251 240 if (!isset($this->_params['subject'])) { 252 $app->logMsg(sprintf('Cannot send email to %s. SUBJECT not defined.', $this->_params['to']), LOG_ERR, __FILE__, __LINE__);241 logMsg(sprintf('Cannot send email to %s. SUBJECT not defined.', $this->_params['to']), LOG_ERR, __FILE__, __LINE__); 253 242 return false; 254 243 } else if (!isset($this->_template)) { 255 $app->logMsg(sprintf('Cannot send email: "%s". Template not set.', $this->_params['subject']), LOG_ERR, __FILE__, __LINE__);244 logMsg(sprintf('Cannot send email: "%s". Template not set.', $this->_params['subject']), LOG_ERR, __FILE__, __LINE__); 256 245 return false; 257 246 } else if (!isset($this->_params['to'])) { 258 $app->logMsg(sprintf('Cannot send email: "%s". TO not defined.', $this->_params['subject']), LOG_NOTICE, __FILE__, __LINE__);247 logMsg(sprintf('Cannot send email: "%s". TO not defined.', $this->_params['subject']), LOG_NOTICE, __FILE__, __LINE__); 259 248 return false; 260 249 } else if (!isset($this->_params['from'])) { 261 $app->logMsg(sprintf('Cannot send email: "%s". FROM not defined.', $this->_params['subject']), LOG_ERR, __FILE__, __LINE__);250 logMsg(sprintf('Cannot send email: "%s". FROM not defined.', $this->_params['subject']), LOG_ERR, __FILE__, __LINE__); 262 251 return false; 263 252 } … … 271 260 // Ensure all placeholders have been replaced. Find anything with {...} characters. 272 261 if (preg_match('/({[^}]+})/', $final_body, $unreplaced_match)) { 273 $app->logMsg(sprintf('Cannot send email. Variables left unreplaced in template: %s', (isset($unreplaced_match[1]) ? $unreplaced_match[1] : '')), LOG_ERR, __FILE__, __LINE__);262 logMsg(sprintf('Cannot send email. Variables left unreplaced in template: %s', (isset($unreplaced_match[1]) ? $unreplaced_match[1] : '')), LOG_ERR, __FILE__, __LINE__); 274 263 return false; 275 264 } … … 304 293 $full_mail_content = join($this->getParam('crlf'), array($final_to, $this->_params['subject'], $final_body)); 305 294 if (preg_match("/(^|[\n\r])(Content-Type|MIME-Version|Content-Transfer-Encoding|Bcc|Cc):/i", $full_mail_content)) { 306 $app->logMsg(sprintf('Mail header injection attack in content: %s', $full_mail_content), LOG_WARNING, __FILE__, __LINE__);295 logMsg(sprintf('Mail header injection attack in content: %s', $full_mail_content), LOG_WARNING, __FILE__, __LINE__); 307 296 sleep(3); 308 297 return false; … … 311 300 // Ensure message was successfully accepted for delivery. 312 301 if (mb_send_mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) { 313 $app->logMsg(sprintf('Email successfully sent to %s', $final_to), LOG_INFO, __FILE__, __LINE__);302 logMsg(sprintf('Email successfully sent to %s', $final_to), LOG_INFO, __FILE__, __LINE__); 314 303 return true; 315 304 } else { 316 $app->logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $final_to, $this->_params['subject'], str_replace("\r\n", '\r\n', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);305 logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $final_to, $this->_params['subject'], str_replace("\r\n", '\r\n', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__); 317 306 return false; 318 307 } … … 336 325 function validEmail($email) 337 326 { 338 $app =& App::getInstance();339 340 327 // If an array, check values recursively. 341 328 if (is_array($email)) { … … 351 338 return true; 352 339 } else { 353 $app->logMsg(sprintf('Invalid email: %s', $email), LOG_INFO, __FILE__, __LINE__);340 logMsg(sprintf('Invalid email: %s', $email), LOG_INFO, __FILE__, __LINE__); 354 341 return false; 355 342 }
Note: See TracChangeset
for help on using the changeset viewer.