Sponsorenverwaltung - Team StarCraft e.V.
 All Data Structures Files Functions Variables
class.mail.php
Go to the documentation of this file.
1 <?php
2  /**
3  * @file class.mail.php
4  *
5  * @brief Home of class UserCakeMail
6  *
7  * @details
8  * This script provides the ability to load, parse and send prepared email-
9  * templates
10  *
11  * This file requires the constant ABS_PATH and some global variables to be
12  * set in order to work properly. For more information please consider
13  * reading the included source code.
14  *
15  * This file is largely based on class.mail.php from Usercake (Version 2.0.2)
16  *
17  * @copyright (c) 2013, Team StarCraft e.V.
18  * @version 1.0.0
19  * @author UserCake (http://www.usercake.com)
20  * @date 02.07.2013
21  */
22 
23  /**
24  * @brief This class provides methods to load, parse and send prepared email-templates.
25  *
26  * @details
27  * This class provides methods to load, parse and send prepared email-templates.
28  * It uses phps mail-function. The current version is configured to send emails
29  * in ISO-8859-1 encoding.
30  *
31  * This class is largely based on the class UserCakeMail from Usercake (Version 2.0.2)
32  *
33  * @copyright (c) 2013, Team StarCraft e.V.
34  * @version 1.0.0
35  * @author UserCake (http://www.usercake.com)
36  * @date 02.07.2013
37  */
38  class UserCakeMail {
39  // UserCake uses a text based system with hooks to replace various strs in txt email templates
40  //! The content of the message
41  public $contents = NULL;
42 
43  /**
44  * Function used for replacing hooks in our templates
45  * @param string $templateName
46  * @param array $additionalHooks
47  * @return boolean
48  * - TRUE if loading and parsing the email-template worked properly
49  * - FALSE if errors occured while loading the template
50  * @author Usercake (http://www.usercake.com)
51  */
52  public function newTemplateMsg($templateName,$additionalHooks)
53  {
54  global $mail_templates_dir;
55 
56  $this->contents = file_get_contents(ABS_PATH.'libs/usercake/'.$mail_templates_dir.$templateName);
57 
58  //Check to see we can access the file / it has some contents
59  if(!$this->contents || empty($this->contents))
60  {
61  return false;
62  }
63  else
64  {
65  //Replace default hooks
66  $this->contents = replaceDefaultHook($this->contents);
67 
68  //Replace defined / custom hooks
69  $this->contents = str_replace($additionalHooks["searchStrs"],$additionalHooks["subjectStrs"],$this->contents);
70 
71  return true;
72  }
73  }
74 
75  /**
76  * Function for sending previously prepared message
77  * @param string $emailAddress the email-address of the receiver
78  * @param string $subject the subject of the message
79  * @param string $msg [optional] the content of the message
80  * - Default: NULL, if unchanged the $contents variable of the
81  * corresponding UserCakeMail-object will be used.
82  * @return boolean
83  * - TRUE if the mail was successfully accepted for delivery
84  * - FALSE otherwise.
85  * @author Usercake (http://www.usercake.com)
86  */
87  public function sendMail($emailAddress,$subject,$msg = NULL) {
89 
90  $header = "MIME-Version: 1.0" . "\r\n";
91  $header.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
92  $header .= "From: ". $websiteName . " <" . $emailAddress . ">\r\n";
93 
94  //Check to see if we sending a template email.
95  if($msg == NULL)
96  $msg = $this->contents;
97 
98  $message = $msg;
99 
100  $message = iconv('utf-8','iso-8859-1',$message);
101 
102  $message = wordwrap($message, 70);
103 
104  return mail($emailAddress,$subject,$message,$header);
105  }
106  }
107 
108 ?>