Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This PHP script is written by Krishna Srikanth.
- This program will send HTML mails along with mime attachments.
- This program can read data from csv file and can send mass mails.
- Report bugs to - mandaksk%yahoo^-com
- Copyright is reserved to no one, as this is open source.
- */
- //Configuration variables. Change this as needed.
- //default "from" details
- $from_name="";
- $from_email="";
- $can_change_from_id="yes"; // do you want to change from identity? yes or no
- //default "to" details
- $to_name="";
- $to_email="";
- $can_change_to_id="yes"; // do you want to change to identity? yes or no
- //attachment details
- $useattachments="yes"; //yes or no
- $no_of_attachments=2;
- //signature
- $usesignature="yes"; // yes or no
- $default_signature="";
- ?>
- <html>
- <head>
- <title>MMP - Mass Mailing Program</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <style type="text/css">
- td, body{font-family:Arial; font-size:13px;}
- .notice{font-family:Verdana; font-size:10px;}
- </style>
- <script language="javascript">
- function mailcheck()
- {
- var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
- var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
- ///var r3 = new RegExp("^.+\\@(\\[?)[a-zA-Z\\-\\.]+\\.([a-zA-Z]{2,3})(\\]?)$");
- if(document.mailform.fromname.value==''){alert('Please enter your name');document.mailform.fromname.focus();return false;}
- if(document.mailform.fromemail.value==''){alert('Please enter your email-id');document.mailform.fromemail.focus();return false;}
- 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;}
- if(document.mailform.csvfile.value==''){
- if(document.mailform.toname.value==''){alert('Please enter the recipients name');document.mailform.toname.focus();return false;}
- if(document.mailform.toemail.value==''){alert('Please enter the recipients email-id');document.mailform.toemail.focus();return false;}
- 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;}
- }
- if(document.mailform.subject.value==''){alert('Please enter the subject');document.mailform.subject.focus();return false;}
- if(document.mailform.message.value==''){alert('Please enter the message');document.mailform.message.focus();return false;}
- //alert('triggered');
- return true;
- }
- function mymail()
- {
- if(mailcheck()){document.mailform.submit()}
- else{return false;}
- }
- function resetform()
- {
- document.mailform.reset();
- }
- </script>
- </head>
- <body>
- <?php if($_POST){
- // include($mail_script_file);
- extract($_POST);
- //addresses
- $headersfrom="From: $fromname <$fromemail>\n"; //from
- //$headers1.="To: $toname <$toemail>\n";
- $to= "$toname <$toemail>"; //to
- if(strlen(trim(strval($cc))) > 0) $headers .= "Cc: $cc \n";
- if(strlen(trim(strval($bcc))) > 0) $headers .= "Bcc: $bcc \n";
- //$to=$toemail;
- //echo $headers;
- //define content type
- if($mailformat=="html")
- {
- $headers.="MIME-Version:1.0\n";
- $headers.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
- }
- else
- {
- $headers.='';
- }
- //add pre tag to message
- if($mailformat=="html")
- {
- $message="<pre style='font-family:".$fontname."; font-size:".$fontsize."'>".$message;
- $message.="<br> <br>".$signature."</pre><br><br>";
- }
- $filesattached=false;
- for($i=1;$i<=count($_FILES);$i++)
- {
- if($_FILES['attachment'.$i]['name']!='')
- {
- $filesattached=true;
- }
- }
- if($filesattached){
- //$headers.="Content-type: multipart/alternative;\n";
- $headers.="Content-type: multipart/mixed; \n";
- $mime_boundary = "".md5(uniqid("KRISHNASRIKANTH"));
- $headers.= " boundary=\"{$mime_boundary}\"";
- }
- // create attachments
- if($filesattached){
- $message = "This is a multi-part message in MIME format.\n\n" .
- "--{$mime_boundary}\n" .
- "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
- "Content-Transfer-Encoding: 8bit\n\n" .
- $message . "\n\n";
- for($i=1;$i<=count($_FILES);$i++)
- {
- if($_FILES['attachment'.$i]['name']!='')
- {
- $filesattached=true;
- //copy to healthy folder
- @copy($_FILES['attachment'.$i]['tmp_name'],"./".$_FILES['attachment'.$i]['name']);
- //note down the file details
- //$tempname=$_FILES['attachment'.$i]['tmp_name'];
- $filename=$_FILES['attachment'.$i]['name'];
- $filetype=$_FILES['attachment'.$i]['type'];
- $filesize=$_FILES['attachment'.$i]['size'];
- //$filesgot[]=$filename;
- $file = fopen($filename,'r');
- $filedata = fread($file,filesize($filename));
- fclose($file);
- /*
- $filedata = implode(file($filename),'');
- */
- $data= chunk_split(base64_encode($filedata));
- $message .= "--{$mime_boundary}\n" .
- "Content-Type: {$filetype};\n" .
- " name=\"{$filename}\"\n" .
- "Content-Disposition: attachment;\n" .
- " filename=\"{$filename}\"\n" .
- "Content-Transfer-Encoding: base64\n\n" .
- $data . "\n\n";
- //delete uploaded files.
- unlink($filename);
- }
- }
- $message.="--{$mime_boundary}--\n";
- }
- //*finally send the composed mail
- if($_FILES['csvfile']['name']!='')
- {
- $csv=$_FILES['csvfile']['tmp_name'];
- //copy the csv to web directory
- /*if(copy($_FILES['csvfile']['tmp_name'],"./".$_FILES['csvfile']['name']))
- {*/
- echo '<b>Starting to send mails of ids from CSV:</b> '.$csv.'<br>';
- $csvfh=fopen($csv,"r");
- while($csvrec=fgetcsv($csvfh,250))
- {
- $csvheaders="To: $csvrec[0] <$csvrec[1]>\n";
- $to=$csvrec[1];
- if(mail($to,$subject,stripslashes($message),$headersfrom.$csvheaders.$headers))
- {
- echo '+ Mail sent to '.$csvrec[0].' ('.$csvrec[1].')<br>';
- }
- else
- {
- echo '- Could not send mail to '.$csvrec[0].' ('.$csvrec[1].')<br><br>';
- }
- }
- $fc=fclose($csvfh);
- echo '<hr>';
- unlink($csv);
- /*}
- else{echo "Could not work on CSV file";}*/
- }
- else{
- if(mail($to,$subject,stripslashes($message),$headersfrom.$headers1.$headers))
- {
- echo '<script language="javascript">alert("Mail sent to '.$toname.' ['.$toemail.']");</script>';
- }
- else
- {
- echo '<script language="javascript">alert("Could not send mail!! Check the script");</script>';
- }
- }//*/
- } ?>
- <form name="mailform" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>" onSubmit="mymail()">
- <table width="634" border="0" align="center" cellpadding="8" cellspacing="0">
- <tr>
- <td height="35" colspan="3"><div align="center"><strong>mmp 1.1 - Mass Mailing Program in PHP </strong></div></td>
- </tr>
- <tr valign="top">
- <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>
- </tr>
- <tr>
- <td height="32" colspan="3"><div align="left"><strong>Identitites</strong></div></td>
- </tr>
- <tr>
- <td height="32">From:</td>
- <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>
- <td>Email-ID:
- <input name="fromemail" type="text" id="fromemail" value="<?php echo $from_email; ?>" size="40" <?php if($can_change_from_id=="no"){echo 'readonly';} ?>></td>
- </tr>
- <tr>
- <td width="12%" height="35"> To:</td>
- <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:
- <input name="toemail" type="text" id="toemail" value="<?php echo $to_email; ?>" size="40" <?php if($can_change_to_id=="no"){echo 'readonly';} ?>></td>
- </tr>
- <tr>
- <td>CSV file: <br> </td>
- <td colspan="2"><input type="file" name="csvfile" size="70">
- <br>
- <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>
- Note that Cc and Bcc will not work for CSV mass mailings.)</span></td>
- </tr>
- <tr>
- <td height="34">Cc:<br> </td>
- <td colspan="2"><input name="cc" type="text" id="cc" size="95">
- <br>
- <span class="notice">(email ids only, seperated by commas)</span></td>
- </tr>
- <tr>
- <td height="34">Bcc:</td>
- <td colspan="2"><input name="bcc" type="text" id="bcc" size="95">
- <br>
- <span class="notice">(email ids only, seperated by commas)</span></td>
- </tr>
- <tr>
- <td height="34">Subject:<br>
- </td>
- <td colspan="2"><input name="subject" type="text" id="subject" size="95">
- </td>
- </tr>
- <tr>
- <td colspan="3"><hr></td>
- </tr>
- <tr>
- <td colspan="3"><table width="100%" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td height="32"><strong>Appearance</strong></td>
- <td> </td>
- </tr>
- <tr>
- <td width="30%" height="32">Mail format: </td>
- <td><input name="mailformat" type="radio" value="html" checked> HTML format <input name="mailformat" type="radio" value="text"> Plain text format </td>
- </tr>
- <tr>
- <td height="32">Over all font to be used:</td>
- <td><select name="fontname" id="fontname">
- <option value="**">Select One</option>
- <option value="Arial" selected>Default - Arial</option>
- <option value="Comic Sans MS">Comic Sans MS</option>
- <option value="Georgia">Georgia</option>
- <option value="Helvetica">Helvetica</option>
- <option value="Sans">Sans</option>
- <option value="sans-serif">Sans-Serif</option>
- <option value="Tahoma">Tahoma</option>
- <option value="Times">Times New Roman</option>
- <option value="Trebuchet MS">Trebuchet MS</option>
- <option value="Verdana">Verdana</option>
- </select> (Only in case of HTML mails)</td>
- </tr>
- <tr>
- <td height="32">Over all font size to be used:</td>
- <td><select name="fontsize" id="fontsize">
- <option value="13px" selected>Normal - 13 pixels</option>
- <option value="11px">Small - 11 pixels</option>
- <option value="15px">Big - 15 pixels</option>
- </select>
- (Only in case of HTML mails)</td>
- </tr>
- <?php if($useattachments=="yes"){
- if($no_of_attachments=="1"){echo '<tr><td>Attachment:</td><td><input name="attachment" type="file" size="70"></td></tr>';}
- else{
- for($i=1;$i<=$no_of_attachments;$i++)
- {
- echo '<tr><td height=32>Attachment - '.$i.':</td><td><input name="attachment'.$i.'" type="file" size="70"></td></tr>';
- }
- }
- }
- ?>
- </table></td>
- </tr>
- <tr>
- <td colspan="3"><hr></td>
- </tr>
- <tr>
- <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>
- </tr>
- <tr>
- <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>
- </tr>
- <?php if($usesignature=="yes"){ ?>
- <tr>
- <td height="95" valign="top">Signature:</td>
- <td colspan="2" valign="top"><textarea name="signature" cols="50" rows="5" id="signature"><?php echo $default_signature; ?></textarea></td>
- </tr><?php } ?>
- <tr>
- <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>
- </tr>
- </table>
- </form>
- </body>
- </html>
- <?php
- /*
- This PHP script is written by Krishna Srikanth.
- Report bugs to - mandaksk%yahoo^com
- Copyright reserved to no one, as this is open source.
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement