Page 1 of 1

email a csv file

Posted: Thu Jun 30, 2005 7:58 am
by nhan
is there a way in php after exporting a certain file from mysql database which is in csv format, it will email the said file into a certain recepient.. :?:

cant figure out the syntax... heheheh... thanks!

Posted: Thu Jun 30, 2005 8:40 am
by Roja
I just did this *exact* thing.

I used phpmailer, and the code looks something like this:

Code: Select all

$mail = new my_phpmailer; // %mail is now a phpmailer email message.
$mail->Subject = "This is the subject of the email!";
$mail->AddStringAttachment($buf, $filename, "8bit", "application/msexcel");
$mail->AddAddress("Roja@example.com", ""); // Who its sent to
$mail->Body    = "This is the body of the email!\n\n";
$mail->From    = "bob_in_accounting@example.com";
$result = $mail->Send();
This assumes you have phpmailer included, and have the csv pulled as a string from the file into the variable $buf, and you want it to have the filename $filename.

The result of the attempt to send will be in $result.

Simple?