Jump to content

Recommended Posts

Hi there, I have a database filled with email addresses and would like to email them all an excel file, that has different values based on their id number.  I generate those excel files with a php script, but I was wondering if there was a way to execute a php script that would automatcially generate the same dyanamic excel file but also email it to the corresponding email?

 

<?php
include 'includes/config.php';
	include 'includes/opendb.php';

	$site1=$_POST['site'];
	$fromdate=$_POST['months'];
	$todaydate=date("Y-m-d");

	$query ="SELECT ticketno, connect, date, rmnum, problem, resolution, connected
			FROM helpdesk h
			WHERE h.sid = '$site1'";

		if ($fromdate <> 'All')
		{
		$query .= " AND h.date BETWEEN '$fromdate'AND '$todaydate'";
		}

		$query .= " ORDER BY h.ticketno DESC";
		$result = mysql_query($query);

		$tsv = array();
		$html = array();
		while($row = mysql_fetch_array($result, MYSQL_NUM))
		{
			$tsv[]  = implode("\t", $row);
			$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
		}

		$tsv  = implode("\r\n", $tsv);
		$html = "<table border=1>" . implode("\r\n", $html) . "</table>";

		$fileName = 'redwoodtickets.xls';
		header("Content-type: application/vnd.ms-excel"); 
		header("Content-Disposition: attachment; filename=$fileName");

		//echo $tsv;
		echo $html;

		include 'includes/closedb.php';
?>

 

This script is for when an individual is logged in, I would like it to generate over 20 different xls files to email based on each information and email the corresponding xls to the email that is registered.  Is this possible or am I just overambitious?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/73329-php-email-with-dynamic-attachments/
Share on other sites

yes, this is possible to do. i have a membership system that attaches dynamic PDFs, Excel is just another variation. look into an existing PHP email class that provides the ability to attach files. and/or learn how to write MIME headers to an email message and then attach a file.

I have been playing around with it for awhile...would the code i currently have work for a project liek this as far as generating or do I basically have to tear down and start back up...Im pretty new to php so I was kinda wondering if anyone can point me in the right direction...I have seen how to email attachements, but havent seen how to send one after generating.  Does anyone have experience with this that could share code or if they are not comforatble doing that point me in the right direction.  Thanks.

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.