Guest User

Untitled

a guest
Nov 26th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. while( $row = mysql_fetch_row( $sqlQuery ) )
  2. {
  3. $line = '';
  4. foreach( $row as $value )
  5. {
  6. if ( ( !isset( $value ) ) || ( $value == "" ) )
  7. {
  8. $value = "t";
  9. }
  10. else
  11. {
  12. $value = str_replace( '"' , '""' , $value );
  13. $value = '"' . $value . '"' . "t";
  14. }
  15. $line .= $value;
  16. }
  17. $data .= trim( $line ) . "n";
  18. }
  19. $data = str_replace( "r" , "" , $data );
  20.  
  21. $cho = "$headern$data";
  22. echo $cho;
  23.  
  24. $headers = "From:abcdf.k@gmail.com(PFC Web Admin) rn";
  25. $headers .= "MIME-Version: 1.0rn";
  26. $headers .= "Content-Type: application/vnd.ms-excel";
  27. $headers .= 'Content-Disposition: attachment; filename=Test.xls' . "rn";
  28. $headers .= "Content-Transfer-Encoding: base64rn";
  29. $headers .= "".$cho."rn";
  30. $subject = 'Record November';
  31.  
  32. $mail = mail( 'abc.k@gmail.com', $subject, $msg, $headers );
  33. if( $mail == true )
  34. {
  35. echo "Message successfully sent";
  36. }
  37. else
  38. {
  39. echo "Message could not be sent";
  40. }
  41.  
  42. <?php
  43. include_once('inc/dbConnect.inc.php');
  44. error_reporting(E_ERROR);
  45. $sql = mysql_query("SELECT * FROM tablename");
  46. $row=mysql_fetch_assoc($sql);
  47. $filename='temp/'.$filename.'.csv';
  48. $fp=fopen($filename,"w");
  49. $seperator="";
  50.  
  51. $comma="";
  52.  
  53. foreach($row as $name =>$value)
  54.  
  55. {
  56.  
  57. $seperator.=$comma.''.str_replace('','""',$name);
  58. $comma=",";
  59.  
  60. }
  61. $seperator.="n";
  62. $seperator;
  63.  
  64. fputs($fp,$seperator);
  65.  
  66. mysql_data_seek($sql,0);
  67.  
  68. while($row=mysql_fetch_assoc($sql))
  69.  
  70. {
  71.  
  72. $seperator="";
  73.  
  74. $comma="";
  75. foreach($row as $name =>$value)
  76.  
  77. {
  78.  
  79. $seperator.=$comma.''.str_replace('','""',$value);
  80. $comma=",";
  81.  
  82. }
  83.  
  84. $seperator.="n";
  85. fputs($fp,$seperator);
  86.  
  87. }
  88.  
  89. fclose($fp);
  90. $my_file = $filename.'.csv';
  91. $path = "temp/";
  92.  
  93.  
  94. $from_name = "hhhhh";
  95.  
  96. $from_mail = "abc@gmail.com";
  97.  
  98. $mailto = "abc@gmail.com";
  99.  
  100. $subject = "This is a mail with attachment.";
  101.  
  102. $message = "Hi,rn do you got attachment?rnrHara";
  103.  
  104. $replyto="haraprasad@lemonpeak.com";
  105. $file = $path.$my_file;
  106. $file_size = filesize($file);
  107.  
  108.  
  109. $handle = fopen($file, "r");
  110.  
  111. $content = fread($handle, $file_size);
  112.  
  113. fclose($handle);
  114.  
  115. $content = chunk_split(base64_encode($content));
  116.  
  117. $uid = md5(uniqid(time()));
  118.  
  119. $name = basename($file);
  120.  
  121. $header = "From: ".$from_name." <".$from_mail.">rn";
  122.  
  123. $header .= "Reply-To: ".$replyto."rn";
  124. $header .= "MIME-Version: 1.0rn";
  125.  
  126. $header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
  127.  
  128. $header .= "This is a multi-part message in MIME format.rn";
  129.  
  130. $header .= "--".$uid."rn";
  131.  
  132. $header .= "Content-type:text/plain; charset=iso-8859-1rn";
  133.  
  134. $header .= "Content-Transfer-Encoding: 7bitrnrn";
  135.  
  136. $header .= $message."rnrn";
  137. $header .= "--".$uid."rn";
  138.  
  139. $header .= "Content-Type: application/octet-stream; name="".$filename.""rn"; // use different content types here
  140.  
  141. $header .= "Content-Transfer-Encoding: base64rn";
  142.  
  143. $header .= "Content-Disposition: attachment; filename="".$filename.""rnrn";
  144. $header .= $content."rnrn";
  145.  
  146. $header .= "--".$uid."--";
  147.  
  148. mail($mailto, $subject, "", $header)
  149.  
  150. ?>
Add Comment
Please, Sign In to add comment