jmcc Posted July 9, 2010 Share Posted July 9, 2010 Hi How do I loop through a csv file on my computer and send an email to all clients in .csv file. Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/ Share on other sites More sharing options...
jmcc Posted July 10, 2010 Author Share Posted July 10, 2010 Something like this? $csv = str_getcsv(file_get_contents($_FILES['file']['tmp_name'])); foreach($csv as $emails){ echo $emails; } Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083867 Share on other sites More sharing options...
joel24 Posted July 10, 2010 Share Posted July 10, 2010 http://php.net/manual/en/function.fgetcsv.php >> <?php $row = 1; if (($handle = fopen("test.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; //data stored in $data echo $data['fieldname']; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } ?> Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083870 Share on other sites More sharing options...
jmcc Posted July 10, 2010 Author Share Posted July 10, 2010 Hi This is the error I get: Warning: fopen('test.csv') [function.fopen]: failed to open stream: No such file or directory in /home/sbantomh/public_html/ the .csv file is on my computer I, how do I call them from my HDD? Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083874 Share on other sites More sharing options...
joel24 Posted July 10, 2010 Share Posted July 10, 2010 You can't call a file from your HDD unless you are running the PHP off your HDD with Xampp etc. You'll need to have the CSV in the same folder or a 'csv' folder and then point the script to that file, i.e. "/" csvEmail.php "csv/" myCSV.csv then change ($handle = fopen("test.csv", "r") to ($handle = fopen("csv/myCSV.csv", "r") Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083878 Share on other sites More sharing options...
jmcc Posted July 10, 2010 Author Share Posted July 10, 2010 Hi I am still receiving the same error---this is my code: I have a simple form that posts the vars to my php page. $file = $_FILES[file] [name]; $row = 1; if (($handle = fopen("csv/$file", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $row++; for ($c=0; $c < $num; $c++) { $msisdn = $data[$c]; echo $msisdn; // call build url function $slap_url = build_url($base_url, $username, $password, $text, $msisdn, $cost); echo $slap_url; // PHP Curl redirect $url = 'http://gateway.networks.net/v2'; $params = "$slap_url"; $user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)"; $ch = curl_init(); curl_setopt($ch, CURLOPT_GET,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$params); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result=curl_exec ($ch); curl_close ($ch); } } fclose($handle); } When I upload the .csv file on to the webserver my script works, but not if i call the file from local HDD Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083881 Share on other sites More sharing options...
joel24 Posted July 10, 2010 Share Posted July 10, 2010 where are you running the script from? if you're runnin the script on the web server, the CSV file has to be on the web server, and if you're running the script from your HDD using Xampp, apache etc, you must ensure that you've configured the folder permissions so that the CSV file can be read, this varies from Windows to Linux etc - you'll have to google it depending on your OS etc. Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083890 Share on other sites More sharing options...
jmcc Posted July 10, 2010 Author Share Posted July 10, 2010 Hi Thank you for all your help, I will upload the files to the web server. Jay Link to comment https://forums.phpfreaks.com/topic/207309-send-email-to-list-in-csv-file/#findComment-1083892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.