Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while( $row = mysql_fetch_row( $sqlQuery ) )
- {
- $line = '';
- foreach( $row as $value )
- {
- if ( ( !isset( $value ) ) || ( $value == "" ) )
- {
- $value = "t";
- }
- else
- {
- $value = str_replace( '"' , '""' , $value );
- $value = '"' . $value . '"' . "t";
- }
- $line .= $value;
- }
- $data .= trim( $line ) . "n";
- }
- $data = str_replace( "r" , "" , $data );
- $cho = "$headern$data";
- echo $cho;
- $headers = "From:abcdf.k@gmail.com(PFC Web Admin) rn";
- $headers .= "MIME-Version: 1.0rn";
- $headers .= "Content-Type: application/vnd.ms-excel";
- $headers .= 'Content-Disposition: attachment; filename=Test.xls' . "rn";
- $headers .= "Content-Transfer-Encoding: base64rn";
- $headers .= "".$cho."rn";
- $subject = 'Record November';
- $mail = mail( 'abc.k@gmail.com', $subject, $msg, $headers );
- if( $mail == true )
- {
- echo "Message successfully sent";
- }
- else
- {
- echo "Message could not be sent";
- }
- <?php
- include_once('inc/dbConnect.inc.php');
- error_reporting(E_ERROR);
- $sql = mysql_query("SELECT * FROM tablename");
- $row=mysql_fetch_assoc($sql);
- $filename='temp/'.$filename.'.csv';
- $fp=fopen($filename,"w");
- $seperator="";
- $comma="";
- foreach($row as $name =>$value)
- {
- $seperator.=$comma.''.str_replace('','""',$name);
- $comma=",";
- }
- $seperator.="n";
- $seperator;
- fputs($fp,$seperator);
- mysql_data_seek($sql,0);
- while($row=mysql_fetch_assoc($sql))
- {
- $seperator="";
- $comma="";
- foreach($row as $name =>$value)
- {
- $seperator.=$comma.''.str_replace('','""',$value);
- $comma=",";
- }
- $seperator.="n";
- fputs($fp,$seperator);
- }
- fclose($fp);
- $my_file = $filename.'.csv';
- $path = "temp/";
- $from_name = "hhhhh";
- $from_mail = "abc@gmail.com";
- $mailto = "abc@gmail.com";
- $subject = "This is a mail with attachment.";
- $message = "Hi,rn do you got attachment?rnrHara";
- $replyto="haraprasad@lemonpeak.com";
- $file = $path.$my_file;
- $file_size = filesize($file);
- $handle = fopen($file, "r");
- $content = fread($handle, $file_size);
- fclose($handle);
- $content = chunk_split(base64_encode($content));
- $uid = md5(uniqid(time()));
- $name = basename($file);
- $header = "From: ".$from_name." <".$from_mail.">rn";
- $header .= "Reply-To: ".$replyto."rn";
- $header .= "MIME-Version: 1.0rn";
- $header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
- $header .= "This is a multi-part message in MIME format.rn";
- $header .= "--".$uid."rn";
- $header .= "Content-type:text/plain; charset=iso-8859-1rn";
- $header .= "Content-Transfer-Encoding: 7bitrnrn";
- $header .= $message."rnrn";
- $header .= "--".$uid."rn";
- $header .= "Content-Type: application/octet-stream; name="".$filename.""rn"; // use different content types here
- $header .= "Content-Transfer-Encoding: base64rn";
- $header .= "Content-Disposition: attachment; filename="".$filename.""rnrn";
- $header .= $content."rnrn";
- $header .= "--".$uid."--";
- mail($mailto, $subject, "", $header)
- ?>
Add Comment
Please, Sign In to add comment