Hi Hericles,

What is the query trying to do?

The query is fetching all the record frm 3 tables using inner join and I am using pagination displaying it.

I tried adding Indexes in all the column that im searching or connecting with and it improves that over all performance of the system. I am on the observation part now. hope that it fix the problem permanently.

I'll close this thread later on when i validated that the solution is effective.

Thanks!

Hi Everyone!

I have an application that has thousand of records. the problem that i am having right now is that my website is performing slow.when i am trying to swtich to other link on the site which have a query running on the background it takes ages to load. i already tried using cloudflare to optimize the system but the slow querying still persist. can anybody have an idea that can help me optmize the poor performace of my database?

By the way the system is hosted in a dedicated server but the resources consumption is very high.

Thanks Neil.

Hi never find got it already.thanks!

Hi Diafol!

Thanks for that but how can i remove the "" on the numbers?
[["Boat + Cab","3"],["Bus + Boat","41040"],["Bus + Boat + Cab","840"],["Bus Only","14343.75"],["Door to Door","674973.75"]]

the format should look like this.

[["Boat + Cab",3],["Bus + Boat",41040],["Bus + Boat + Cab",840],["Bus Only",14343.75],["Door to Door",674973.75]]

thanks

Hi Guys!

I cant find a way to show my data array the way i need it to be hope you can help me. i already tried using array_push(), json_encode() but still no result. basically what i am getting is like this

Array ( [0] => Array ( [name] => Boat + Cab [TOTAL] => 3 ) 
                [1] => Array ( [name] => Bus + Boat [TOTAL] => 41040 )
                [2] => Array ( [name] => Bus + Boat + Cab [TOTAL] => 840 ) 
                [3] => Array ( [name] => Bus Only [TOTAL] => 14343.75 ) 
                [4] => Array ( [name] => Door to Door [TOTAL] => 691073.75 ) )

But i need the data in this format

                    ['Boat + Cab', 3],
                    ['Bus + Boat', 41040],
                    ['BUS + BOAT', 1000],
                    ['Bus + Boat + Cab', 840]
                    ....etc

What should i do?

Thanks Neil,

WOW thats it? holycow im stuck on that for 2 days and you answered it very casually with

Yes exactly put line 17-18 inside while loop.

Where are you d past days men?heheheh

ITs WORKING FINE NOW!!!

THANKS ALOT

NEIL:)

happygeek commented: Tell your friends :) +13

Hi! thank you for giving your inputs on this matter.

To answer you on

Before line number 100 that is before ending while loop break the loop

break;
} //end of while

I tried adding the break ; but it only generate 1 exel file in contrast with the record

fix the while loop query code (LINE 21), it is giving more then one record i guess.

Yes it is giving me 1 or more records which is correct. coz for that day there are several client that have a billing duedate.

for

If you generating mulitple files, then intialise excel object inside while loop and after generating file, destroy it before while loop ends.

Yes and No. it depends on the client duedate whether it will create 1 or more excel file.
Also what do you mean by ?

intialise excel object inside while loop

Do i need to put line 17 and 18 inside my while loop?

Thanks Neil

`

Anyone has an idea?

Hi!

Im creating individual excel file base on the duedate and client name of a reservation and sending it automatically on that date.but im having a trouble dispalying the SUM/ Grandtotal of each excel summary that i created. the grandtotal inside my while loop is also incrementing. i dont now what i am doing wrong.

Example

for today i have 4 Client that has a duedate today. and the script automatically generated the excel file summary of each client.

Client 1. 7 STONES

1.jpg

Client 2. Your Travel Planner

2.jpg

Client 3. ZOEMIE

3.jpg

And the Last Zulu Plaza . Notice that this one has no problem dispalying trhe Grandtotal

4.jpg

You can see that from the First excel file to the 3rd it has a duplicate Grandtotal

This is the Script that i used creating the excel files.

<?php
error_reporting(E_ALL);
include '../includes/pdo_config.php';
include '../includes/phpexcel_config.php';
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('Asia/Manila');

/** PHPExcel_IOFactory */
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';

$today = date('Y-m-d');

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("templates/Billing.xls");

try {
    $getname=$con->prepare("SELECT msicph_globalsouthwest.accounts_info.name,
                                                   msicph_globalsouthwest.accounts_info.email
                                                    FROM msicph_globalsouthwest.accounts_info
                                                      WHERE msicph_globalsouthwest.accounts_info.name
                                                       IN ( SELECT msicph_southwest.reservations.resfor
                                                         FROM msicph_southwest.reservations
                                                          WHERE msicph_southwest.reservations.`duedate` = DATE_SUB(CURDATE(), INTERVAL - 3 DAY))");
    $getname->execute();
    $i = 0;
    ob_start();
    while ($dataname = $getname->fetch(PDO::FETCH_ASSOC)) {

                $resfor=$dataname['name'];
                $email=$dataname['email'];

                $stmts = $con->prepare("SELECT * FROM reservations WHERE resfor='$resfor' and 
                                                `duedate` = DATE_SUB(CURDATE(), INTERVAL - 3 DAY)"); 
                $stmts->execute();
                $objPHPExcel->getActiveSheet()->setCellValue('I1', PHPExcel_Shared_Date::PHPToExcel(time()));

                $baseRow = 5;

                $run = 0; // control variable to set a pause every 20 messages 
                ob_start();
                foreach($stmts ...

Got it! Line 45 is the one causing the problem..i just remove that line and everything working fine.

jkon commented: It says that I answered that one but you did. +1 because you answered the questions (although the error was in the use of this external class) +8

Hi JKON! this is the dump file for the client name

CREATE TABLE IF NOT EXISTS `accounts_info` (
  `aid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `email` varchar(50) NOT NULL,
  `contact_no` varchar(50) NOT NULL,
  `address` varchar(100) NOT NULL,
  `accred_no` varchar(50) NOT NULL,
  `bill_term` int(2) NOT NULL,
  `cashbond` float NOT NULL,
  `contact_person` varchar(100) NOT NULL,
  PRIMARY KEY (`aid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=253 ;

--
-- Dumping data for table `accounts_info`
--

INSERT INTO `accounts_info` (`name`) VALUES
('Zulu Plaza'),
('ZOEMIE'),
('Your Travel Planner'),
('WILLYS'),
('WHITE HOUSE'),
('WHITE CORAL'),
('WEST CLIFF VILLA'),
('Water Color'),
('Villa Romero'),
('VILLA ROMERO'),
('VICTORY BEACH'),
('VELIS INN'),
('TWO SEASONS'),
('TROPICS'),
('Travel Planner'),
('TONGLEN'),
('THE TIDES'),
('THE PALMS '),
('The Lind'),
('Tans Guesthouse'),
('Taj'),
('SURFSIDE'),
('SUR BEACH '),
('SPR Boracay'),
('SOL MARINA'),
('Sitio boracay'),
('SIMPLE TRAVEL'),
('SHANGRILA'),
('Serendipity/Secret Garden'),
('SEA WIND'),
('SEA BIRD'),
('SAND CASTLE'),
('ROYAL PARK'),
('RESIDENCIA'),
('RED COCONUT'),
('REAL MARIS'),
('RAKSO TRAVEL'),
('POP PEARL OF THE PACIFIC'),
('Paradiso'),
('PARADISE GARDEN'),
('Panorama'),
('ORCHIDS'),
('Oirent Beach'),
('ONE CRESENT'),
('OCEAN CLUB'),
('NIGI NIGI MAIN NU NOOS'),
('NANDANA'),
('My Boracay Guide'),
('MR. HOLIDAY'),
('MORNING BEACH'),
('MONACO SUITES'),
('MITOS PLACE'),
('MILFLORES'),
('MICROTEL'),
('Metropolitan Doctors'),
('MAXIMA'),
('MANILA TRAVEL '),
('MANGO RAY'),
('LUGAR BONITO'),
('LINGGANAY'),
('LE SOLEIL'),
('LAS BRISAS'),
('LA RESERVE'),
('LA ISLA BONITA'),
('LA CARMELA'),
('JONYS'),
('ISLAND STAFF'),
('ISLAND JEWEL INN'),
('Isla Gecko'),
('HOTEL SOFIA'),
('HEY JUDE-SOUTHBEACH'),
('HEY JUDE'),
('HENNAN LAGOON'),
('HENNAN GARDEN'),
('Hannah Hotel'),
('Guillius Italian'),
('GRAND VISTA'),
('GRAND PRIX HIDEAWAY'),
('GRAND BORACAY'),
('GOLDEN PHEONIX'),
('Go Discover'),
('FRIDAYS'),
('FTC BORACAY'),
('Ferra Hotel'),
('FRENDZ RESORT'),
('FAT JIMMYS'),
('FAITHFULLY'),
('FAIRWAYS'),
('ESTACIO UNO'), ...

also i'll post again the sql dump here without the contact info when i reach home. sorry im on mobile

Hi jkon sorry for the late response. my sql dump was cleaned by a mod because of the sensitive data that was posted thats why it didn't match.basically what im trying to do is send an .xls invoice to the client 3 days before the duedate. what i am trying to do right now is collect all the reservations of each client dynamically and create individual.xls file for it. on the first image i said that the last record should not be there because its a transaction of the second image. i use the resfor field as identifier on the 2nd select statement to group all the data.

hope i explained it clearly :)

thanks,!!

Anybody have an idea whats wrong im doing?

Also this are the sql dump if you wanna check it:)

CREATE TABLE IF NOT EXISTS `accounts_info` (
  `aid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `email` varchar(50) NOT NULL,
  `contact_no` varchar(50) NOT NULL,
  `address` varchar(100) NOT NULL,
  `accred_no` varchar(50) NOT NULL,
  `bill_term` int(2) NOT NULL,
  `cashbond` float NOT NULL,
  `contact_person` varchar(100) NOT NULL,
  PRIMARY KEY (`aid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=252 ;

--
-- Dumping data for table `accounts_info`
--

INSERT INTO `accounts_info` (`aid`, `name`, `email`, `contact_no`, `address`, `accred_no`, `bill_term`, `cashbond`, `contact_person`) VALUES
(161, 'Zulu Plaza', 'test@example.com', '', '', '', 7, 0, 'vicky'),
(160, 'ZOEMIE', '', '', 'ILIG ILIGAN COVE BRGY. YAPAK MALAY AKLAN', '', 7, 0, 'MS. AGEL TIPAY')

CREATE TABLE IF NOT EXISTS `reservations` (
  `resid` int(11) NOT NULL AUTO_INCREMENT,
  `foname` varchar(50) NOT NULL,
  `resnum` varchar(20) NOT NULL,
  `resfor` varchar(100) NOT NULL,
  `name` varchar(100) NOT NULL,
  `total_adult` int(11) NOT NULL,
  `total_senior` int(11) NOT NULL,
  `total_child` int(11) NOT NULL,
  `email` varchar(100) NOT NULL,
  `rental_date` date NOT NULL,
  `rental_time` time NOT NULL,
  `depart_date` date NOT NULL,
  `depart_time` time NOT NULL,
  `service_type` varchar(100) NOT NULL,
  `vehicle_type` varchar(100) NOT NULL,
  `modetrans` varchar(20) NOT NULL,
  `from` varchar(100) NOT NULL,
  `to` varchar(100) NOT NULL,
  `remark` varchar(500) NOT NULL,
  `note` varchar(250) NOT NULL,
  `rates` float NOT NULL,
  `total_extras` float NOT NULL,
  `total_rates` float NOT NULL,
  `grand_total` float NOT NULL,
  `payment_type` varchar(50) NOT NULL,
  `payment_info` varchar(50) NOT NULL,
  `status` varchar(10) NOT NULL,
  `payment_stat` varchar(25) NOT NULL,
  `duedate` date NOT NULL,
  `active` int(5) NOT NULL DEFAULT '1',
  PRIMARY KEY (`resid`),
  UNIQUE KEY `resnum` (`resnum`)
) ...

Hi jkon i am still orienting my self to pdo and still getting the feel of it.dont know yet most of the tricks and other stuffs. The "../includes/pdo_config.php" is just the database config of one of the table.(im using 2 db on this case) by the way i updated my script and its almost working but im still getting a wild data that should not be included in one of the excel file that the script generates.

kindly look on my updated script pls

<?php
error_reporting(E_ALL);
include '../includes/pdo_config.php'; // database msicph_southwest and table reservations config
include '../includes/phpexcel_config.php'; // database msicph_globalsouthwest and table accounts_info
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('Europe/London');

/** PHPExcel_IOFactory */
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';

$today = date('Y-m-d');

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("templates/Billing.xls");

try {
                         $getname=$conn->prepare("SELECT msicph_globalsouthwest.accounts_info.name
                                                  FROM msicph_globalsouthwest.accounts_info
                                                 WHERE msicph_globalsouthwest.accounts_info.name IN (
                                                SELECT msicph_southwest.reservations.resfor
                                                FROM msicph_southwest.reservations)"); 
                         $getname->execute();
                         while ($dataname = $getname->fetch(PDO::FETCH_ASSOC)) {

                                    $resfor=$dataname['name'];

                                    $stmts = $con->prepare("SELECT * FROM reservations WHERE 
                                                `duedate` = DATE_SUB(CURDATE(), INTERVAL - 3 DAY) and resfor='$resfor'"); 
                                    $stmts->execute();
                                    $objPHPExcel->getActiveSheet()->setCellValue('I1', PHPExcel_Shared_Date::PHPToExcel(time()));

                                    $baseRow = 5;

                                    foreach($stmts as $r => $dataRow) {
                                    $billname=$dataRow['resfor'];

                                    $rental_date=$dataRow['rental_date'];
                                    $rental_time=$dataRow['rental_time'];
                                    $row = $baseRow + $r;
                                    $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

                                    $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $dataRow['resnum'])
                                                          ->setCellValue('B'.$row, $dataRow['name'])
                                                          ->setCellValue('C'.$row, date('M d, Y', strtotime($dataRow['rental_date']))." / ".$dataRow['rental_time'])
                                                          ->setCellValue('D'.$row, $dataRow['service_type'])
                                                          ->setCellValue('E'.$row, $dataRow['modetrans'])
                                                          ->setCellValue('F'.$row, $dataRow['from'])
                                                          ->setCellValue('G'.$row, $dataRow['to'])
                                                          ->setCellValue('H'.$row, $dataRow['duedate'])
                                                          ->setCellValue('I'.$row, $dataRow['total_rates']);
                                    }  // end of foreachloop

                            //END OF FOREACH
                                $add=$r + 10;
                                $last=$r + 5;
                                $basecell="I".$add;

                                $objPHPExcel->getActiveSheet()->setCellValue($basecell,'=SUM(I4'.':I'.$last.')');
                                $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);

                                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                                $objWriter->save(str_replace(__FILE__,'excelfiles/'.$resfor.'.xls',__FILE__));

                                //$objWriter->save(str_replace('.php', '.xls', __FILE__));
                                echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, ...

anybody has an idea what am i doing wrong? when i try to creat a excel file base on the list of name i got from the reservations table using a loop im not getting the right data on the excel file.

notice the select query on both script. I dont know if the problem is the while loop or the foreach..

But when i try to get a specific resfor its working the way it should be

Working script

<?php
error_reporting(E_ALL);

ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('Europe/London');

/** PHPExcel_IOFactory */
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';

$today = date('Y-m-d');

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("templates/Billing.xls");

try {

             include '../includes/pdo_config.php';
                         $stmts = $con->prepare("SELECT * FROM reservations WHERE 
                                                `duedate` = DATE_SUB(CURDATE(), INTERVAL - 3 DAY) and resfor='7 STONES' "); 
                          $stmts->execute();
                          $result = $stmts->setFetchMode(PDO::FETCH_ASSOC);

                        $objPHPExcel->getActiveSheet()->setCellValue('I1', PHPExcel_Shared_Date::PHPToExcel(time()));

                        $baseRow = 5;

                        foreach($stmts as $r => $dataRow) {
                           $billname=$dataRow['resfor'];

                            $rental_date=$dataRow['rental_date'];
                            $rental_time=$dataRow['rental_time'];
                            $row = $baseRow + $r;
                            $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

                            $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $dataRow['resnum'])
                                                          ->setCellValue('B'.$row, $dataRow['name'])
                                                          ->setCellValue('C'.$row, date('M d, Y', strtotime($dataRow['rental_date']))." / ".$dataRow['rental_time'])
                                                          ->setCellValue('D'.$row, $dataRow['service_type'])
                                                          ->setCellValue('E'.$row, $dataRow['modetrans'])
                                                          ->setCellValue('F'.$row, $dataRow['from'])
                                                          ->setCellValue('G'.$row, $dataRow['to'])
                                                          ->setCellValue('H'.$row, $dataRow['duedate'])
                                                          ->setCellValue('I'.$row, $dataRow['total_rates']);

                            }
                               $add=$r + 10;
                                $last=$r + 5;
                                $basecell="I".$add;

                                $objPHPExcel->getActiveSheet()->setCellValue($basecell,'=SUM(I4'.':I'.$last.')');
                                $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);

                                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                                $objWriter->save(str_replace(__FILE__,'excelfiles/'.$billname.'.xls',__FILE__));

                                                                //$objWriter->save(str_replace('.php', '.xls', __FILE__));
                                echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;

                                // Echo done
                                echo date('H:i:s') , " Done writing file" , EOL;
                                echo 'File has been created in ' , getcwd() , EOL;

  } // TRY
 catch(PDOException $e) {
    //echo "Error: " . $e->getMessage();

}
$con = null;

Hi Everyone!

Can anybody point me to the right direction or check what am i doing wrong. Im trying to export data from php to excel using phpexcel( which is working fine if im am only getting 1 specific record). but when i tried adding a loop to create a workbook im having a problem. the data does not match the actual record from DB

this is the script

Currently editing:  
/home/msicph/public_html/sedaatria/demo/toexcel/genexcel.php
 Encoding:    Reopen  Switch to Code Editor     Close  Save

<?php
error_reporting(E_ALL);

ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');

date_default_timezone_set('Europe/London');

/** PHPExcel_IOFactory */
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';

$today = date('Y-m-d');

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load("templates/Billing.xls");

try {
include '../includes/global_config.php';

            $q1= $con->prepare("SELECT name FROM accounts_info"); 
            $q1->execute();
            include '../includes/pdo_config.php';
            while ($row = $q1->fetch())  {
            $name=$row['name'];

                         $stmts = $con->prepare("SELECT * FROM reservations WHERE 
                                                `duedate` = DATE_SUB(CURDATE(), INTERVAL - 3 DAY) and resfor='$name' "); 
                          $stmts->execute();

                        $objPHPExcel->getActiveSheet()->setCellValue('I1', PHPExcel_Shared_Date::PHPToExcel(time()));

                        $baseRow = 5;

                        foreach($stmts as $r => $dataRow) {
                           $billname=$dataRow['resfor'];

                            $rental_date=$dataRow['rental_date'];
                            $rental_time=$dataRow['rental_time'];
                            $row = $baseRow + $r;
                            $objPHPExcel->getActiveSheet()->insertNewRowBefore($row,1);

                            $objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $dataRow['resnum'])
                                                          ->setCellValue('B'.$row, $dataRow['name'])
                                                          ->setCellValue('C'.$row, date('M d, Y', strtotime($dataRow['rental_date']))." / ".$dataRow['rental_time'])
                                                          ->setCellValue('D'.$row, $dataRow['service_type'])
                                                          ->setCellValue('E'.$row, $dataRow['modetrans'])
                                                          ->setCellValue('F'.$row, $dataRow['from'])
                                                          ->setCellValue('G'.$row, $dataRow['to'])
                                                          ->setCellValue('H'.$row, $dataRow['duedate'])
                                                          ->setCellValue('I'.$row, $dataRow['total_rates']);

                                $add=$r + 10;
                                $last=$r + 5;
                                $basecell="I".$add;

                                $objPHPExcel->getActiveSheet()->setCellValue($basecell,'=SUM(I4'.':I'.$last.')');
                                $objPHPExcel->getActiveSheet()->removeRow($baseRow-1,1);

                                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                                $objWriter->save(str_replace(__FILE__,'excelfiles/'.$name.'.xls',__FILE__));

                                //$objWriter->save(str_replace('.php', '.xls', __FILE__));
                                echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;

                                // Echo done
                                echo date('H:i:s') , " Done writing file" , EOL;
                                echo 'File has been created in ' , getcwd() , EOL;

                            } //END OF FOREACH

            } ...

Foud the problem. it seems that the on access scanning of sophos is the one causing of the bugs.

Hi

Has anyone of you having a problem opening firefox , google chrome and thunderbird since yesterday? coz almost all of our unit that is running in ubuntu and Zorin OS are experiencing the same bugs.. i already tried updating and upgrading the OS but still having the error and i also tried re installing the applications but im not getting any progress..

Hi as cereal been pointing out you just need to add your "phpmailer " /sending code on your form action like

<form action="phpmailer.php" method="post">

after that you need to pass the data from your form to the phpmailer.php script that you wrote like this

<?php
require 'PHPMailerAutoload.php';

//======= this is the data form your form====
$name=$_POST['name'];
$email=$_POST['email'];
$website=$_POST['website'];
 $query=$_POST['query'];
//===========end=======

$mail = new PHPMailer;
//$mail->SMTPDebug = 3;
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
$mail->Username = 'reply_office@---.com';
$mail->Password = '---';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = 'reply_office@---.com';
$mail->FromName = 'Mailer';
$mail->addAddress('office@---.com');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body    = 'My name is $name. you can send me an email at $email and visit my webpage at $website and my asdfghj is $query';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

?>

after you made the changes you are ready to Go.

can you run this script?

<?php
echo phpinfo();
?>

please read http://php.net/manual/en/function.date-diff.php to better understand why you are getting that error message. Another thing your date_default_timezone is not correct please refer to this list for the correct timezone.

ronjacob012 commented: will help you as soon as possible +0

According to the php manual, date_diff is only available in PHP 5.3+ so thats why you are getting a fatal error. check the version of your php by echoing phpinfo();

please be more specific what error are you getting? the sample i gave you is working perfectly on my side without any glitch.

dont put your if statement in a straight line if you have a comment on it.

if($diff=='2'){ 
//send email 
}else
{ 
//do nothing 
} 

?>

what error?

Your First script will work. you just need to make a cronjob for it to send the email automatically.

$currentdate=date_create("2014-06-15");
$duedate=date_create("2014-06-13");
$diff=date_diff($currentdate,$duedate);
echo $diff->format("%a");

if($diff=='2'){

    //send email
}else{
    //do nothing
}

No its not. the pc needs to be turned on for the task scheduler to work. the best option you have is yo use a cronjob on your webserver that will check your script on a given interval of time.