Jump to content

Recommended Posts

Hi guys can anyone please help me? I have to run a script that generates a report into an excel document then emails the document simultaneous to the user with the spreadsheet attached! Although it needs to write a document for each users specific details in the database and mail that user his specific spreadsheet with his details in! Heres a sample of what im trying to do. Sorry forgot to mention in the previous post that the part that i cant get working at all is how to mail the document while the scripts runs all that happens now is it open an asks whether i want to save the document. If im going about this all wrong an there is an easier or better way please advise.

 

require_once 'Spreadsheet/Excel/Writer.php';

 

$sql = "select distinct agent from leads";

$qry = mysql_query($sql, $conn);

 

$workbook = new Spreadsheet_Excel_Writer();

 

$workbook->send('liveleads.xls');

 

$worksheet =& $workbook->addWorksheet(liveleads);

 

$worksheet->write(0, 0, 'agent');

$worksheet->write(0, 1, 'leadID'); // all leads for that agent

$worksheet->write(0, 2, 'contactperson'); // all contacts that agent has

 

while($array = mysql_fetch_array($qry)) {

$i = 1;

$sql2 = "select * from leads where agent = $array[agent]";

$qry2 = mysql_query($sql2, $conn);

     

        while($array2 = mysql_fetch_array($qry2)){

              $worksheet->write($i, 0, $array[agent]);

              $worksheet->write($i, 1, $array[leadID]);

              $worksheet->write($i, 2, $array[contactperson]);

              $i++;

 

 

        }

mail($array,"subject"etc.......");

}

$workbook->close();

 

#so basically i need to loop through the agents get the leads that belong to the specific agent

#then write an excel document for each agent listing his specific leads

#then mail each agent with his specific document attached containing his leads while the script runs

 

#Any help will be greatly appreciated :)

Hi sorry about that did not know.

 

The problem is im not sure on how to email the workbook to the end user while the script runs. basically this script is set to run once a week on a monday write up a spreadsheet of data and mail each user his specific speadsheet?

Hi sorry about that did not know.

 

The problem is im not sure on how to email the workbook to the end user while the script runs. basically this script is set to run once a week on a monday write up a spreadsheet of data and mail each user his specific speadsheet?

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.