root/trunk/wifidog-auth/wifidog/classes/Mail.php @ 758

Revision 758, 3.3 KB (checked in by fproulx, 8 years ago)

2005-09-16 Francois Proulx <francois.proulx@…>

  • Added Mail Classes to circumvent mb_send_mail UTF-8 problems
  • This class provides UTF-8 mailing for validation e-mail, lost password, lost username...
  • Fixes reported bug where users would not receive validation email on some servers
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/********************************************************************\
4 * This program is free software; you can redistribute it and/or    *
5 * modify it under the terms of the GNU General Public License as   *
6 * published by the Free Software Foundation; either version 2 of   *
7 * the License, or (at your option) any later version.              *
8 *                                                                  *
9 * This program is distributed in the hope that it will be useful,  *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
12 * GNU General Public License for more details.                     *
13 *                                                                  *
14 * You should have received a copy of the GNU General Public License*
15 * along with this program; if not, contact:                        *
16 *                                                                  *
17 * Free Software Foundation           Voice:  +1-617-542-5942       *
18 * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
19 * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
20 *                                                                  *
21 \********************************************************************/
22/**@file Mail.php
23 * @author Copyright (C) 2005 Francois Proulx <francois.proulx@gmail.com>
24 */
25
26/*
27 * This a wrapper class conforming RFC822 capable of sending valid UTF-8 MIME headers
28 */
29class Mail
30{       
31        // Business domain attributes
32        private $from_name;
33        private $from_email;
34        private $to_name;
35        private $to_email;
36        private $subject;
37        private $body;
38       
39        public function __construct()
40        {
41        }
42       
43        private function encodeMimeHeader($header)
44        {
45                // BASE 64 according to the RFC
46                // Taken from : www.php.net mb_send_mail comments
47                $header = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $header);
48                $header = str_replace(' ', '_', $header);
49                return "=?utf-8?Q?$header?=";
50        }
51       
52        public function getMessageBody()
53        {
54                return $this->body;
55        }
56       
57        public function getMessageSubject()
58        {
59                return $this->subject;
60        }
61       
62        public function getRecipientName()
63        {
64                return $this->to_name;
65        }
66       
67        public function getRecipientEmail()
68        {
69                return $this->to_email;
70        }
71       
72        public function getSenderName()
73        {
74                return $this->from_name;
75        }
76       
77        public function getSenderEmail()
78        {
79                return $this->from_email;       
80        }
81       
82        // Packs e-mail and send it according to RFC822
83        public function send()
84        {
85                $headers = "From: \"".$this->getSenderName()."\" <".$this->getSenderEmail().">\r\n";
86                $headers .= "Reply-To: ".$this->getSenderEmail()."\r\n";
87                $headers .= "Content-Type: text/plain; charset=utf-8";
88                $args = "-f".$this->getSenderEmail();
89                return mail($this->getRecipientEmail(), $this->getMessageSubject(), $this->getMessageBody(), $headers, $args);
90        }
91       
92        public function setMessageBody($body)
93        {
94                $this->body = $body;
95        }
96       
97        public function setMessageSubject($subject)
98        {
99                $this->subject = $this->encodeMimeHeader($subject);
100        }
101       
102        public function setRecipientEmail($mail)
103        {
104                $this->to_email = $mail;
105        }
106       
107        public function setSenderName($name)
108        {
109                // Encode header
110                $this->from_name = $this->encodeMimeHeader($name);
111        }
112       
113        public function setSenderEmail($mail)
114        {
115                $this->from_email = $mail;
116        }
117}
118
119?>
Note: See TracBrowser for help on using the browser.