/[cvs]/nfo/php/libs/org.netfrag.elib/smtp/smtpmail.class
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.elib/smtp/smtpmail.class

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Wed Jan 23 17:40:36 2002 UTC (22 years, 7 months ago) by cvsjoko
Branch: nfo, MAIN
CVS Tags: v003, HEAD
Changes since 1.1: +0 -0 lines
initial

1 cvsjoko 1.1 <?
2     //if ($EMAIL_INC) return;
3     //$EMAIL_INC= "defined";
4     define("SmtpPort",25);
5    
6     class Smtp {
7    
8     var $Subject; // string the email's subject
9     var $FromName; // string sender's name (opt)
10     var $ToName; // string recipient's name (opt)
11     var $Body; // string body copy
12     var $Attachment; // attachment (optional)
13     var $AttachmentType;
14     var $Socket;
15     var $Line;
16     var $Status;
17    
18     function Smtp($Server = "localhost", $Port = SmtpPort)
19     {
20     return $this->Open($Server, $Port);
21     }
22    
23     function SmtpMail($FromEmail, $FromName, $ToEmail, $ToName, $Subject, $Body, $Attachment=null, $AttachmentType="TEXT")
24     {
25     $this->Subject = $Subject;
26     $this->ToName = $ToName;
27    
28     $this->FromName = $FromName;
29     $this->Body = $Body;
30    
31     $this->Attachment = $Attachment;
32     $this->AttachmentType = $AttachmentType;
33    
34     if ($this->Helo() == false){
35     return false;
36     }
37     if ($this->MailFrom($FromEmail) == false){
38     return false;
39     }
40     if ($this->RcptTo($ToEmail) == false){
41     return false;
42     }
43     if ($this->Body() == false){
44     return false;
45     }
46     if ($this->Quit() == false){
47     return false;
48     }
49     }
50    
51     function Open($Server, $Port)
52     {
53    
54     $this->Socket = fsockopen($Server, $Port);
55     if ($this->Socket < 0) return false;
56    
57     $this->Line = fgets($this->Socket, 1024);
58    
59     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
60     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
61    
62     if ($this->Status["LASTRESULT"] <> "2") return false;
63    
64     return true;
65     }
66    
67    
68     function Helo()
69     {
70     if (fputs($this->Socket, "helo\r\n") < 0 ){
71     return false;
72     }
73     $this->Line = fgets($this->Socket, 1024);
74    
75     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
76     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
77    
78     if ($this->Status["LASTRESULT"] <> "2") return false;
79    
80     return true;
81     }
82    
83     function Ehlo()
84     {
85    
86     /* Well, let's use "helo" for now.. Until we need the
87     extra func's [Unk]
88     */
89     if(fputs($this->Socket, "helo localhost\r\n")<0){
90     return false;
91     }
92     $this->Line = fgets($this->Socket, 1024);
93    
94     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
95     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
96    
97     if ($this->Status["LASTRESULT"] <> "2") return false;
98    
99     return true;
100     }
101    
102    
103     function MailFrom($FromEmail)
104     {
105    
106     if (fputs($this->Socket, "MAIL FROM: <$FromEmail>\r\n")<0){
107     return false;
108     }
109    
110     $this->Line = fgets($this->Socket, 1024);
111    
112     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
113     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
114    
115     if ($this->Status["LASTRESULT"] <> "2") return false;
116    
117     return true;
118     }
119    
120     function RcptTo($ToEmail)
121     {
122    
123     if(fputs($this->Socket, "RCPT TO: <$ToEmail>\r\n")<0){
124     return false;
125     }
126     $this->Line = fgets($this->Socket, 1024);
127    
128     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
129     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
130    
131     if ($this->Status["LASTRESULT"] <> "2") return false;
132     return true;
133     }
134    
135     function Body()
136     {
137     $FileSize = 0;
138     $Attachment = null;
139     $fp = null;
140    
141     $buffer = sprintf("From: %s\r\nTo:%s\r\nSubject:%s\r\n", $this->FromName, $this->ToName, $this->Subject);
142    
143     if(fputs($this->Socket, "DATA\r\n")<0){
144     return false;
145     }
146     $this->Line = fgets($this->Socket, 1024);
147    
148     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
149     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
150    
151     if ($this->Status["LASTRESULT"] <> "3") return false;
152    
153     if(fputs($this->Socket, $buffer)<0){
154     return false;
155     }
156    
157    
158     if ($this->Attachment == null){
159    
160     if(fputs($this->Socket, "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=ISO-8859-1\r\nContent-Transfer-Encoding: 7bit\r\n\r\n")<0){
161     return false;
162     }
163     if(fputs($this->Socket, "$this->Body\r\n\r\n")<0){
164     return false;
165     }
166    
167     if(fputs($this->Socket, ".\r\n")<0){
168     return false;
169     }
170    
171     $this->Line = fgets($this->Socket, 1024);
172     if (substr($this->Line, 0, 1) <> "2"){
173     return false;
174     }else{
175     return true;
176     }
177     }else{
178     if(fputs($this->Socket,"MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"----=_NextPart_000_01BCFA61.A3697360\"\r\n".
179     "Content-Transfer-Encoding: 7bit\r\n\r\n".
180     "This is a multi-part message in MIME format.\r\n".
181     "\r\n------=_NextPart_000_01BCFA61.A3697360\r\n".
182     "Content-Type: text/plain; charset=ISO-8859-1\r\n".
183     "Content-Transfer-Encoding: 7bit\r\n".
184     "\r\n")<0){
185     return false;
186     }
187    
188    
189     /* output the body file */
190     if(fputs($this->Socket, "$this->Body\r\n\r\n")<0){
191     return false;
192     }
193    
194     if ( fputs($this->Socket,"\r\n------=_NextPart_000_01BCFA61.A3697360\r\n")<0){
195     return false;
196     }
197     $FileSize = filesize($this->Attachment);
198     if ($FileSize == false){
199     return false;
200     }
201     if (($fp = fopen($this->Attachment,"r"))== false) {
202     return false;
203     }else{
204     $Attachment = fread($fp,$FileSize);
205     }
206    
207     // we don't want any of the directory in the attachment
208     if (($AttachName = strrchr($this->Attachment,'/')) == false){
209    
210     // no directory so just copy the name in
211     $AttachName = $this->Attachment;
212     }
213    
214     if( fputs($this->Socket,
215     "Content-Type: application/octet-stream; \r\nname=\"$AttachName\"\r\n".
216     "Content-Transfer-Encoding: quoted-printable\r\n".
217     "Content-Description: $AttachName\r\n".
218     "Content-Disposition: attachment; \r\n\tfilename=\"$AttachName\"\r\n".
219     "\r\n")<0){
220     return false;
221     }
222    
223     /* output the attachment file */
224     if( fputs($this->Socket, $Attachment)<0){
225     return false;
226     }
227     if ( fputs($this->Socket,"\r\n\r\n------=_NextPart_000_01BCFA61.A3697360--\r\n")<0){
228     return false;
229     }
230    
231     if( fputs($this->Socket,".\r\n")<0){
232     return false;
233     }
234    
235     $this->Line = fgets($this->Socket, 1024);
236     if (substr($this->Line, 0, 1) <> "2")
237     return false;
238    
239     return true;
240    
241     }
242     }
243    
244     function Quit()
245     {
246    
247     if(fputs($this->Socket, "QUIT\r\n")<0){
248     return false;
249     }
250     $this->Line = fgets($this->Socket, 1024);
251    
252     $this->Status["LASTRESULT"] = substr($this->Line, 0, 1);
253     $this->Status["LASTRESULTTXT"] = substr($this->Line, 0, 1024);
254    
255     if ($this->Status["LASTRESULT"] <> "2") return 0;
256    
257     return 1;
258     }
259     function Close()
260     {
261     fclose($this->Socket);
262     }
263     }
264    
265     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed