Jump to content

saransh

New Members
  • Posts

    3
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

saransh's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi ginerjm Thanks for the reply. still getting the same output after following your comments
  2. Hi requinix, Thanks for the reply,Yes file on the server has data. I think the issue is file permissions on server for read and write. But i am able to download data.
  3. Hi, I am new to this forum, I am trying to create a php script to email and attached database table data in csv file. Below is the script which i have created but i am received only blank csv file in attachment. I have no clue where i committed mistake. Please help! <?php $sql = "SELECT * From abc"; $res = mysql_query($sql); $fileatt_type = "text/csv"; $myfile = "myfile.csv"; $handle = fopen($myfile, "w"); $str = ""; while($row = mysql_fetch_array($res)) { $str = $row['username'].",".$row['mobile']."\n"; } fwrite($handle, $str); fclose($handle); $file_size = filesize($myfile); $handle = fopen($myfile, "w"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $to = 'abc@gmail.com'; $subject = 'Test email with attachment'; $message = 'welocme'; #$header = "From: ".$from_name." <".$from_mail.">\r\n"; #$header .= "Reply-To: ".$replyto."\r\n"; $header = "From: abc.com\r\n Reply-To: From: abc.com"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/html; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: text/csv; name=\"".$myfile."\"\r\n"; // use diff. tyoes here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$myfile."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($to, $subject, $message, $header)){ echo "Mail send"; } else{ echo "can not send mail"; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.