Overview

Packages

  • Admin
  • Archive
  • Common
  • DB
  • Express
  • Form
  • Layout
  • Mailer
  • None
  • OpenHomeoDB
  • PDF
    • MC
  • Process
  • Rep
  • RevRep
  • SaveReps
  • Search
  • Session
  • SymRem
  • TreeView
  • UserDB

Classes

  • Mailer
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * mailer.php
  5:  *
  6:  * PHP version 8
  7:  *
  8:  * LICENSE: This program is free software: you can redistribute it and/or modify
  9:  * it under the terms of the GNU Affero General Public License as
 10:  * published by the Free Software Foundation, either version 3 of the
 11:  * License, or (at your option) any later version.
 12:  * This program is distributed in the hope that it will be useful,
 13:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15:  * GNU Affero General Public License for more details.
 16:  * You should have received a copy of the GNU Affero General Public License
 17:  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 18:  *
 19:  * @category  Login
 20:  * @package   Mailer
 21:  * @author    Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 22:  * @author    Henri Schumacher <henri.hulski@gazeta.pl>
 23:  * @copyright 2007-2014 Henri Schumacher
 24:  * @license   http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
 25:  * @version   1.0
 26:  * @link      https://research.openhomeo.info/download/OpenHomeopath_1.0.2.tar.gz
 27:  * @see       login.php
 28:  */
 29: 
 30: /**
 31:  * The Mailer class is meant to simplify the task of sending
 32:  * emails to users. Note: this email system will not work
 33:  * if your server is not setup to send mail.
 34:  *
 35:  * @category  Login
 36:  * @package   Mailer
 37:  * @author    Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
 38:  * @author    Henri Schumacher <henri.hulski@gazeta.pl>
 39:  * @copyright 2007-2014 Henri Schumacher
 40:  * @license   http://www.gnu.org/licenses/agpl.html GNU Affero General Public License v3
 41:  */
 42: class Mailer {
 43:     /**
 44:      * sendWelcome - Sends a welcome message to the newly
 45:      * registered user, also supplying the username and
 46:      * password.
 47:      *
 48:      * @param string $user username
 49:      * @param string $email email
 50:      * @param string $pass password
 51:      * @return boolean true if the mail has been successful sent
 52:      * @access public
 53:      */
 54:     function sendWelcome($user, $email, $pass){
 55:         $subject = "" . _("Welcome to OpenHomeopath!") . "";
 56:         $body = $user.",\n\n"
 57:                  ."" . _("Welcome!") . " " . _("You was just registered on OpenHomeopath:") . "\n\n"
 58:                  ."" . _("Username:") . " ".$user."\n"
 59:                  ."" . _("Password:") . " ".$pass."\n\n"
 60:                  ."" . _("Wenn you forget your password we will send a new one to this e-mail.") . "\n"
 61:                  ."" . _("In section 'settings' you can change the e-mail.") . "\n\n"
 62:                  ."- " . _("The OpenHomeopath-Team") . " ;-)";
 63: 
 64:         return $this->send_mail($email, $body, $subject);
 65:     }
 66: 
 67:     /**
 68:      * sendWelcomePass - Sends a welcome message to the newly
 69:      * registered user, sending a generated password
 70:      * and supplying the username.
 71:      *
 72:      * @param string $user username
 73:      * @param string $email email
 74:      * @param string $pass password
 75:      * @return boolean true if the mail has been successful sent
 76:      * @access public
 77:      */
 78:     function sendWelcomePass($user, $email, $pass){
 79:         $subject = "" . _("Welcome to OpenHomeopath!") . "";
 80:         $body = $user.",\n\n"
 81:                  ."" . _("Welcome!") . " " . _("You was just registered on OpenHomeopath with username") . " $user.\n\n"
 82:                  ."" . _("Your password:") . " ".$pass."\n\n"
 83:                  ."" . _("You can use this password along with your username to login on OpenHomeopath.") . "\n\n"
 84:                  ."" . _("In section 'settings' you can change the password.") . "\n\n"
 85:                  ."" . _("Wenn you forget your password we will send a new one to this e-mail.") . "\n"
 86:                  ."" . _("In section 'settings' you can change the e-mail.") . "\n\n"
 87:                  ."- " . _("The OpenHomeopath-Team") . " ;-)";
 88: 
 89:         return $this->send_mail($email, $body, $subject);
 90:     }
 91: 
 92:     /**
 93:      * sendNewPass - Sends the newly generated password
 94:      * to the user's email address that was specified at
 95:      * sign-up.
 96:      *
 97:      * @param string $user username
 98:      * @param string $email email
 99:      * @param string $pass password
100:      * @return boolean true if the mail has been successful sent
101:      * @access public
102:      */
103:     function sendNewPass($user, $email, $pass){
104:         $subject = "" . _("OpenHomeopath - Your new password") . "";
105:         $body = $user.",\n\n"
106:                  ."" . _("At your request, we've created a new password for you.") . "\n"
107:                  ."" . _("You can use this password along with your username to login on OpenHomeopath.") . "\n\n"
108:                  ."" . _("Username:") . " ".$user."\n"
109:                  ."" . _("New Password:") . " ".$pass."\n\n"
110:                  ."" . _("In section 'settings' you can change the password.") . "\n\n"
111:                  ."- " . _("The OpenHomeopath-Team") . " ;-)";
112: 
113:         return $this->send_mail($email, $body, $subject);
114:     }
115: 
116:     /**
117:      * mail_header_escape - encode the header with 'quoted-printable',
118:      * so that also non US-ASCII letters can be transmitted.
119:      *
120:      * @param string $header email header
121:      * @return string the encoded header
122:      * @access public
123:      */
124:     function mail_header_escape ($header) {
125:         if (preg_match('/[^a-z0-9 _-]/i', $header)) {
126:             $header = preg_replace('/([^a-z0-9 ])/ie', 'sprintf("=%02x", ord(stripslashes("$1")))', $header);
127:             $header = str_replace(' ', '_', $header);
128:             return "=?utf-8?Q?$header?=";
129:         }
130:         return $header;
131:     }
132: 
133:     /**
134:      * send_mail - Send the email with mail().
135:      *
136:      * @param string $to receiver
137:      * @param string $body email body
138:      * @param string $subject email subject
139:      * @return boolean true if the mail has been successful sent
140:      * @access public
141:      */
142:     function send_mail($to, $body, $subject) {
143:         $header = "From: \"".$this->mail_header_escape(EMAIL_FROM_NAME)."\" <".EMAIL_FROM_ADDR.">\r\n";
144:         $header .= "Reply-To: ".EMAIL_FROM_ADDR."\r\n";
145:         $header .= "MIME-Version: 1.0\r\n";
146:         $header .= "Content-Type: text/plain; charset=\"".MAIL_ENCODING."\"\r\n";
147:         $header .= "Content-Transfer-Encoding: 7bit\r\n";
148:         if (mail($to, $this->mail_header_escape($subject), $body, $header)) {
149:             return true;
150:         } else {
151:             return false;
152:         }
153:     }
154: };
155: 
156: /* Initialize mailer object */
157: $mailer = new Mailer;
158: 
OpenHomeopath PHP code documentation API documentation generated by ApiGen 2.8.0