-1

I have the header at the very beginning of my script and so I've no idea why I'm getting this error, anyone have any other ideas? im trying to send an email later in the script but it contains czech characters.

<?php
ob_start();
header('Content-Type: text/plain; charset=Windows-1252;');
$dayofweek = getdate();
if($dayofweek[weekday] == "Friday") {
    die(0);
/*} elseif($dayofweek[weekday] == "Saturday") {
    die(0); */
} else{
        $aCSVFile = 'filepath';
        if(file_exists($aCSVFile)) {
        echo("$dayofweek[weekday]");
        $connect = mysql_connect("localhost","dbname","dbpass");
        echo("\n connected to sql");
        mysql_select_db("dbname",$connect); 
        echo("\n connected to db");
        $convertNow = mb_convert_encoding($aCSVFile, 'UTF-8', 'auto');
        $handle = fopen($convertNow,"r");
        echo("\n file opened");
        //loop through the csv file and insert into database            
do {
    if ($data[0]) {            
        mysql_query("INSERT INTO bakery_items(UserID, Order_status, Date_from, Date_until, Product_ID, Product_quantity, OrderID) VALUES
            (
                '$data[0]',
                '$data[1]',
                '$data[2]',
                '$data[3]',
                '$data[4]',
                '$data[5]',
                '$data[6]'
            )
        "); 
    }
} while ($data = fgetcsv($handle,1000,",","'"));
  unlink($aCSVFile);
    $fileToSendPath = 'somefilepath';
$fileToSend = fopen($fileToSendPath,'w');
    $Cmdbase = "base string";
              if($dayofweek[weekday] != "Thursday") {
              $Cmdbase = "SELECT Product as PRODUKT, Total as POČET FROM ORDER_LIST";
    } else {
              $Cmdbase = "SELECT Product as PRODUKT, Total as POČET FROM ORDER_LIST_WKND";
    }
$sql = mysql_query($Cmdbase);
while($row = mysql_fetch_array($sql))
{
        $user = $row['PRODUKT'];
        $pass = $row['POČET'];

        $accounts = "$user:$pass \n";
    fwrite($fileToSend, $accounts);

              }
      $bodytext = "Dobrý Den, Posíláme vám náše obědnavku pro nasledujici den, děkujeme.";
      /*$bodytext = mb_convert_encoding($Bodytxt,'HTML-ENTITIES', 'Windows-1252');*/
              fclose($fileToSend);
      echo('file created');       
      require_once('wp-includes/PHPMailer-master/class.phpmailer.php');
      $email = new PHPMailer();
      $email->From      = 'myemail@email.cz';
      $email->FromName  = 'Broodjes';
      $email->Subject   = 'Obědnavka od ';
          $email->Body      = $bodytext;
          $email->AddAddress('soso@hotmail.com' );

      $file_to_attach = 'someFilePath';
              $email->AddAttachment( $file_to_attach , 'Obednavka_NaVenkove.txt' );
      return $email->Send();
      echo('file sent');
      unlink($fileToSendPath);
          }

} ?>

ob_start(); gives the same error really unsure of how to do it, I don't know if it makes a difference but there is an instance of wordpress installed but the script is created by myself not working I've updated my code in the question to give you all

Paddydrum
  • 13
  • 7
  • Try to add ob_start() on the first line. – patwoj98 Apr 15 '17 at 11:36
  • I've read that ob_start() isn't best practice though, what should i place as the parameters for ob_start? – Paddydrum Apr 15 '17 at 11:47
  • ob_start doesn't take any parameteres. Just put it. It works with that. I use it and I know that it is good practise. – patwoj98 Apr 15 '17 at 11:48
  • This really is a duplicate, did you read the answers in the linked question? It will tell you how to find the script that started the output. It is quite possible that you can't send headers at this point because wordpress already started output before this script is called. – jmarkmurphy Apr 18 '17 at 12:26
  • @jmarkmurphy I asked a moderator to remove this post because I have resolved the error. In the end I removed the header, because I found that the problem was in the encoding in phpmailer. so i changed the charset there and it all works! unfortunately i can't remove the question nor answer it myself and the answer given wasn't what solved my issue. I did read the other question and found that it hadn't solved my issue (otherwise I would have marked the answer given as the correct answer) – Paddydrum Apr 19 '17 at 15:33

1 Answers1

0

May be white spaces, try this:

<?php
header('Content-Type: text; charset=Windows-1252;');
     $dayofweek = getdate();
     if($dayofweek[weekday] == "Friday") {
          die(0);
    /*} elseif($dayofweek[weekday] == "Saturday") {
              die(0); */
      }?>
Fran Cerezo
  • 940
  • 3
  • 8
  • 19