Click here to Skip to main content
15,891,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Debuggers,

Am struggling in a point to send mysql result as Email attachment through php.

I have tried in google and tried some steps. But nothing was worked for me.

Even i have used some class like class.email-query-results-as-csv-file.php. Nothing was working.
Does any have can help on me?

Thanks in Advance,
Elancheran

What I have tried:

setQuery("SELECT * FROM cam_ad_booking");
$emailCSV->sendEmail("elanworlds@gmail.com","elanworlds@gmail","MySQL Query Results as CSV Attachment");
?>
Posted
Updated 28-Sep-16 3:50am
v2
Comments
David_Wimbley 27-Sep-16 11:00am    
What isnt working, the email? creating the csv file? Both? What does the CSV creation code look like? What error message are you getting? Is there an exception? At what point does the code stop "working". We don't have enough information to begin to help you. You should learn how to debug in PHP and you can probably help yourself a lot better than we can guess at what your issue is.
Elan_cheran 28-Sep-16 8:52am    
I can able to create and export the csv file separately to save in local, and i can able to sent mail using google smtp as of now. But need to attach the csv file on fly with the mail.

1 solution

based on your comment, your issue has nothing to do with CSV file creation/mysql. Your issue is you don't know how to send an email with an attachment in PHP.

Given you did not post the function emailcsv->sendEmail you probably need to add another parameter to accept a file location or however you decide to handle it. Either way here is the research for sending emails in PHP with attachments:

Send attachments in email php - Google Search[^]

Send attachments with PHP Mail()? - Stack Overflow[^]

PHP: Sending Email (Text/HTML/Attachments)[^]

PHP mail attachment script and function | Tutdepot.com[^]

You've stated you can create the csv and save it to local, that means you have the full path to that files location. You also said you can send an email using google...great. Now all you need to do is use the above links, a little brain power, and then you'll be able to send your csv file (an attachment) via email in php.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900