Jump to content

send email to list in .csv file


jmcc

Recommended Posts

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);
}
?>

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")

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.