Jump to content

PHP Email with dynamic attachments....


tj71587

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.

Archived

This topic is now archived and is closed to further replies.

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