email a csv file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nhan
Forum Commoner
Posts: 95
Joined: Sun Feb 27, 2005 8:26 pm
Contact:

email a csv file

Post 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!
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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?
Post Reply