Advertisement
r13y5h4

m455_m41L

Feb 10th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.22 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. This PHP script is written by Krishna Srikanth.
  5. This program will send HTML mails along with mime attachments.
  6. This program can read data from csv file and can send mass mails.
  7. Report bugs to - mandaksk%yahoo^-com
  8. Copyright is reserved to no one, as this is open source.
  9.  
  10. */
  11.  
  12. //Configuration variables. Change this as needed.
  13.  
  14. //default "from" details
  15. $from_name="";
  16. $from_email="";
  17. $can_change_from_id="yes"; // do you want to change from identity? yes or no
  18.  
  19. //default "to" details
  20. $to_name="";
  21. $to_email="";
  22. $can_change_to_id="yes"; // do you want to change to identity? yes or no
  23.  
  24. //attachment details
  25. $useattachments="yes"; //yes or no
  26. $no_of_attachments=2;
  27.  
  28. //signature
  29. $usesignature="yes"; // yes or no
  30. $default_signature="";
  31.  
  32. ?>
  33. <html>
  34. <head>
  35. <title>MMP - Mass Mailing Program</title>
  36. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  37. <style type="text/css">
  38. td, body{font-family:Arial; font-size:13px;}
  39. .notice{font-family:Verdana; font-size:10px;}
  40. </style>
  41. <script language="javascript">
  42. function mailcheck()
  43. {
  44. var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  45. var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  46. ///var r3 = new RegExp("^.+\\@(\\[?)[a-zA-Z\\-\\.]+\\.([a-zA-Z]{2,3})(\\]?)$");
  47. if(document.mailform.fromname.value==''){alert('Please enter your name');document.mailform.fromname.focus();return false;}
  48. if(document.mailform.fromemail.value==''){alert('Please enter your email-id');document.mailform.fromemail.focus();return false;}
  49. if(!r1.test(document.mailform.fromemail.value) && !r2.test(document.mailform.fromemail.value)){alert("Your email id doesn't appear to valid");document.mailform.fromemail.focus();return false;}
  50.  
  51. if(document.mailform.csvfile.value==''){
  52. if(document.mailform.toname.value==''){alert('Please enter the recipients name');document.mailform.toname.focus();return false;}
  53. if(document.mailform.toemail.value==''){alert('Please enter the recipients email-id');document.mailform.toemail.focus();return false;}
  54.  
  55. if(!r1.test(document.mailform.toemail.value) && !r2.test(document.mailform.toemail.value)){alert("The recipients email id doesn't appear to valid");document.mailform.toemail.focus();return false;}
  56. }
  57.  
  58. if(document.mailform.subject.value==''){alert('Please enter the subject');document.mailform.subject.focus();return false;}
  59. if(document.mailform.message.value==''){alert('Please enter the message');document.mailform.message.focus();return false;}
  60.  
  61. //alert('triggered');
  62. return true;
  63.  
  64. }
  65. function mymail()
  66. {
  67. if(mailcheck()){document.mailform.submit()}
  68. else{return false;}
  69. }
  70. function resetform()
  71. {
  72. document.mailform.reset();
  73. }
  74. </script>
  75. </head>
  76.  
  77. <body>
  78. <?php if($_POST){
  79. // include($mail_script_file);
  80. extract($_POST);
  81.  
  82. //addresses
  83. $headersfrom="From: $fromname <$fromemail>\n"; //from
  84. //$headers1.="To: $toname <$toemail>\n";
  85. $to= "$toname <$toemail>"; //to
  86. if(strlen(trim(strval($cc))) > 0) $headers .= "Cc: $cc \n";
  87. if(strlen(trim(strval($bcc))) > 0) $headers .= "Bcc: $bcc \n";
  88. //$to=$toemail;
  89. //echo $headers;
  90.  
  91. //define content type
  92. if($mailformat=="html")
  93. {
  94. $headers.="MIME-Version:1.0\n";
  95. $headers.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
  96. }
  97. else
  98. {
  99. $headers.='';
  100. }
  101.  
  102. //add pre tag to message
  103. if($mailformat=="html")
  104. {
  105. $message="<pre style='font-family:".$fontname."; font-size:".$fontsize."'>".$message;
  106. $message.="<br>&nbsp;<br>".$signature."</pre><br><br>";
  107. }
  108. $filesattached=false;
  109. for($i=1;$i<=count($_FILES);$i++)
  110. {
  111. if($_FILES['attachment'.$i]['name']!='')
  112. {
  113. $filesattached=true;
  114. }
  115. }
  116. if($filesattached){
  117. //$headers.="Content-type: multipart/alternative;\n";
  118. $headers.="Content-type: multipart/mixed; \n";
  119. $mime_boundary = "".md5(uniqid("KRISHNASRIKANTH"));
  120. $headers.= " boundary=\"{$mime_boundary}\"";
  121. }
  122. // create attachments
  123. if($filesattached){
  124. $message = "This is a multi-part message in MIME format.\n\n" .
  125. "--{$mime_boundary}\n" .
  126. "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
  127. "Content-Transfer-Encoding: 8bit\n\n" .
  128. $message . "\n\n";
  129.  
  130. for($i=1;$i<=count($_FILES);$i++)
  131. {
  132. if($_FILES['attachment'.$i]['name']!='')
  133. {
  134. $filesattached=true;
  135. //copy to healthy folder
  136. @copy($_FILES['attachment'.$i]['tmp_name'],"./".$_FILES['attachment'.$i]['name']);
  137.  
  138. //note down the file details
  139. //$tempname=$_FILES['attachment'.$i]['tmp_name'];
  140. $filename=$_FILES['attachment'.$i]['name'];
  141. $filetype=$_FILES['attachment'.$i]['type'];
  142. $filesize=$_FILES['attachment'.$i]['size'];
  143.  
  144. //$filesgot[]=$filename;
  145. $file = fopen($filename,'r');
  146. $filedata = fread($file,filesize($filename));
  147. fclose($file);
  148. /*
  149. $filedata = implode(file($filename),'');
  150. */
  151. $data= chunk_split(base64_encode($filedata));
  152.  
  153. $message .= "--{$mime_boundary}\n" .
  154. "Content-Type: {$filetype};\n" .
  155. " name=\"{$filename}\"\n" .
  156. "Content-Disposition: attachment;\n" .
  157. " filename=\"{$filename}\"\n" .
  158. "Content-Transfer-Encoding: base64\n\n" .
  159. $data . "\n\n";
  160.  
  161. //delete uploaded files.
  162. unlink($filename);
  163. }
  164. }
  165.  
  166. $message.="--{$mime_boundary}--\n";
  167.  
  168. }
  169.  
  170. //*finally send the composed mail
  171. if($_FILES['csvfile']['name']!='')
  172. {
  173. $csv=$_FILES['csvfile']['tmp_name'];
  174. //copy the csv to web directory
  175. /*if(copy($_FILES['csvfile']['tmp_name'],"./".$_FILES['csvfile']['name']))
  176. {*/
  177. echo '<b>Starting to send mails of ids from CSV:</b> '.$csv.'<br>';
  178. $csvfh=fopen($csv,"r");
  179. while($csvrec=fgetcsv($csvfh,250))
  180. {
  181. $csvheaders="To: $csvrec[0] <$csvrec[1]>\n";
  182. $to=$csvrec[1];
  183. if(mail($to,$subject,stripslashes($message),$headersfrom.$csvheaders.$headers))
  184. {
  185. echo '+ Mail sent to '.$csvrec[0].' ('.$csvrec[1].')<br>';
  186. }
  187. else
  188. {
  189. echo '- Could not send mail to '.$csvrec[0].' ('.$csvrec[1].')<br><br>';
  190. }
  191. }
  192. $fc=fclose($csvfh);
  193. echo '<hr>';
  194. unlink($csv);
  195. /*}
  196. else{echo "Could not work on CSV file";}*/
  197. }
  198. else{
  199. if(mail($to,$subject,stripslashes($message),$headersfrom.$headers1.$headers))
  200. {
  201. echo '<script language="javascript">alert("Mail sent to '.$toname.' ['.$toemail.']");</script>';
  202. }
  203. else
  204. {
  205. echo '<script language="javascript">alert("Could not send mail!! Check the script");</script>';
  206. }
  207. }//*/
  208. } ?>
  209. <form name="mailform" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>" onSubmit="mymail()">
  210. <table width="634" border="0" align="center" cellpadding="8" cellspacing="0">
  211. <tr>
  212. <td height="35" colspan="3"><div align="center"><strong>mmp 1.1 - Mass Mailing Program in PHP </strong></div></td>
  213. </tr>
  214. <tr valign="top">
  215. <td height="32" colspan="3"><div align="center"><strong>Actions</strong>: <a href="#" onClick="mymail()"><strong>Send the mail</strong></a>, <a href="#" onClick="resetform()"><strong>Reset the form</strong></a>, <a href="<?php echo $_SERVER['../PHP_SELF']; ?>"><strong>Write another mail</strong></a></div></td>
  216. </tr>
  217. <tr>
  218. <td height="32" colspan="3"><div align="left"><strong>Identitites</strong></div></td>
  219. </tr>
  220. <tr>
  221. <td height="32">From:</td>
  222. <td><input name="fromname" type="text" id="fromname" value="<?php echo $from_name; ?>" size="40" <?php if($can_change_from_id=="no"){echo 'readonly';} ?>></td>
  223. <td>Email-ID:
  224. <input name="fromemail" type="text" id="fromemail" value="<?php echo $from_email; ?>" size="40" <?php if($can_change_from_id=="no"){echo 'readonly';} ?>></td>
  225. </tr>
  226. <tr>
  227. <td width="12%" height="35"> To:</td>
  228. <td width="39%"> <input name="toname" type="text" id="toname" value="<?php echo $to_name; ?>" size="40" <?php if($can_change_to_id=="no"){echo 'readonly';} ?>></td><td width="49%"> Email-ID:
  229. <input name="toemail" type="text" id="toemail" value="<?php echo $to_email; ?>" size="40" <?php if($can_change_to_id=="no"){echo 'readonly';} ?>></td>
  230. </tr>
  231. <tr>
  232. <td>CSV file: <br> </td>
  233. <td colspan="2"><input type="file" name="csvfile" size="70">
  234. <br>
  235. <span class="notice">(Use this if you want to send mass mails using CSV file. The file should be in the format of name, email. <br>
  236. Note that Cc and Bcc will not work for CSV mass mailings.)</span></td>
  237. </tr>
  238. <tr>
  239. <td height="34">Cc:<br> </td>
  240. <td colspan="2"><input name="cc" type="text" id="cc" size="95">
  241. <br>
  242. <span class="notice">(email ids only, seperated by commas)</span></td>
  243. </tr>
  244. <tr>
  245. <td height="34">Bcc:</td>
  246. <td colspan="2"><input name="bcc" type="text" id="bcc" size="95">
  247. <br>
  248. <span class="notice">(email ids only, seperated by commas)</span></td>
  249. </tr>
  250. <tr>
  251. <td height="34">Subject:<br>
  252. </td>
  253. <td colspan="2"><input name="subject" type="text" id="subject" size="95">
  254. </td>
  255. </tr>
  256.  
  257. <tr>
  258. <td colspan="3"><hr></td>
  259. </tr>
  260. <tr>
  261. <td colspan="3"><table width="100%" border="0" cellpadding="0" cellspacing="0">
  262. <tr>
  263. <td height="32"><strong>Appearance</strong></td>
  264. <td>&nbsp;</td>
  265. </tr>
  266. <tr>
  267. <td width="30%" height="32">Mail format: </td>
  268. <td><input name="mailformat" type="radio" value="html" checked> HTML format <input name="mailformat" type="radio" value="text"> Plain text format </td>
  269. </tr>
  270. <tr>
  271. <td height="32">Over all font to be used:</td>
  272. <td><select name="fontname" id="fontname">
  273. <option value="**">Select One</option>
  274. <option value="Arial" selected>Default - Arial</option>
  275. <option value="Comic Sans MS">Comic Sans MS</option>
  276. <option value="Georgia">Georgia</option>
  277. <option value="Helvetica">Helvetica</option>
  278. <option value="Sans">Sans</option>
  279. <option value="sans-serif">Sans-Serif</option>
  280. <option value="Tahoma">Tahoma</option>
  281. <option value="Times">Times New Roman</option>
  282. <option value="Trebuchet MS">Trebuchet MS</option>
  283. <option value="Verdana">Verdana</option>
  284. </select> (Only in case of HTML mails)</td>
  285. </tr>
  286. <tr>
  287. <td height="32">Over all font size to be used:</td>
  288. <td><select name="fontsize" id="fontsize">
  289. <option value="13px" selected>Normal - 13 pixels</option>
  290. <option value="11px">Small - 11 pixels</option>
  291. <option value="15px">Big - 15 pixels</option>
  292. </select>
  293. (Only in case of HTML mails)</td>
  294. </tr>
  295.  
  296. <?php if($useattachments=="yes"){
  297. if($no_of_attachments=="1"){echo '<tr><td>Attachment:</td><td><input name="attachment" type="file" size="70"></td></tr>';}
  298. else{
  299. for($i=1;$i<=$no_of_attachments;$i++)
  300. {
  301. echo '<tr><td height=32>Attachment - '.$i.':</td><td><input name="attachment'.$i.'" type="file" size="70"></td></tr>';
  302. }
  303. }
  304. }
  305. ?>
  306. </table></td>
  307. </tr>
  308. <tr>
  309. <td colspan="3"><hr></td>
  310. </tr>
  311. <tr>
  312. <td height="35" colspan="3"><div align="center"><strong>Actions</strong>: <a href="#" onClick="mymail()"><strong>Send the mail</strong></a>, <a href="#" onClick="resetform()"><strong>Reset the form</strong></a>, <a href="<?php echo $_SERVER['../PHP_SELF']; ?>"><strong>Write another mail</strong></a></div></td>
  313. </tr>
  314. <tr>
  315. <td height="365" colspan="3"> <strong>Message</strong>: (Use HTML tags, if this is HTML mail) <br> <br><textarea name="message" cols="90" rows="25" id="message"></textarea></td>
  316. </tr>
  317. <?php if($usesignature=="yes"){ ?>
  318. <tr>
  319. <td height="95" valign="top">Signature:</td>
  320. <td colspan="2" valign="top"><textarea name="signature" cols="50" rows="5" id="signature"><?php echo $default_signature; ?></textarea></td>
  321. </tr><?php } ?>
  322. <tr>
  323. <td height="35" colspan="3"><div align="center"><strong>Actions</strong>: <a href="#" onClick="mymail()"><strong>Send the mail</strong></a>, <a href="#" onClick="resetform()"><strong>Reset the form</strong></a>, <a href="<?php echo $_SERVER['../PHP_SELF']; ?>"><strong>Write another mail</strong></a></div></td>
  324. </tr>
  325. </table>
  326. </form>
  327. </body>
  328. </html>
  329. <?php
  330. /*
  331.  
  332. This PHP script is written by Krishna Srikanth.
  333. Report bugs to - mandaksk%yahoo^com
  334. Copyright reserved to no one, as this is open source.
  335.  
  336. */
  337. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement