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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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