...

View Full Version : Php 2 Attachment Email, csv, and PDF



barkermn01
10-29-2009, 12:51 PM
Help please.

Im using fpdf to generate a pdf file, this works.

I am trying to send a email with a CSV & PDF Attachment then a HTML form in the email.
I think i must have the mime_boundary's wrong



ob_start();
$csv = "Base Unit:, ".$pRow['name'].", ".$pRow['cost']."\r\n";
$csv .= ",,"."\r\n";
?>
<div class="mainbody" style="margin-top:-50px;">
<div class="mainbody top"></div>
<div class="mainbody body">
<h1>Configurator Report</h1>
<hr />
<table width="800">
<tbody>
<tr>
<th colspan="2" width="600"><?php echo $pRow['name']; ?></th>
<th width="200">&pound;<?php echo number_format($pRow['option_1'],2); ?></th>
</tr>
<tr>
</tr>
<tr>
<th>Addons:</th>
<td></td>
<td></td>
</tr>
<tr>
<th></th>
<td></td>
<td></td>
</tr>
<tr>
<th></th>
<td></td>
<td></td>
</tr>
<?php
while($row = mysql_fetch_array($query)){
if(($selected = array_search($row['id'], $addons)) !== false){
if($row['name'] != "None"){
$csv .= ", ".$row['name'].", ".number_format($row['cost'], 2)."\r\n";
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td></td>
<td>&pound;<?php echo number_format($row['cost'], 2); ?></td>
</tr>
<?php
}
}
}
?>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th></th>
<th>Total:</th>
<td>&pound;<?php echo number_format($price, 2); ?></td>
</tr>
</tbody>
</table>
</div>
<div class="mainbody bot"></div>
</div>
</div>
<?php
$content = "";
$to = $_GET['email'];
$content = ob_get_clean();
$html = $content;
$csv .= ",,"."\r\n";
$csv .= ",Total:".number_format($price, 2)."\r\n";

echo "";

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->SetXY(160, 10);
$pdf->cell(0,0,"DTP Group");
$pdf->SetXY(160, 15);
$pdf->cell(0,0,"DTP House");
$pdf->SetXY(160, 20);
$pdf->cell(0,0,"4 Bowcliffe Road");
$pdf->SetXY(160, 25);
$pdf->cell(0,0,"Leeds");
$pdf->SetXY(160, 30);
$pdf->cell(0,0,"LS10 1HB");
$pdf->SetXY(160, 35);
$pdf->cell(0,0,"Tel: 0113 2760210");
$pdf->SetXY(160, 40);
$pdf->cell(0,0,"Fax: 0113 2771963");
$pdf->SetXY(10, 10);
$pdf->image("files/logo.gif");
$pdf->SetXY(10, 50);
$pdf->SetFont('Arial','B',10);
$pdf->cell(0,0, $pRow['name']);
$pdf->SetXY(13, 60);
$pdf->cell(0,0, "Addons:");
$y = 60;
$pdf->SetFont('Arial','',10);
$cost = 0.00;
while($row = mysql_fetch_array($query)){
if(($selected = array_search($row['id'], $addons)) !== false){
if($row['name'] != "None"){
// ,{addon Name}, {addon Cost}
$pdf->SetXY(40, $y);
$pdf->cell(0, 0, $row['name']);
$pdf->SetXY(180, $y);
$pdf->cell(0, 0, "".number_format($row['cost'],2));
if($row['cost'][0] == "-"){
eval('$cost = $cost - (int)'.str_replace('-',$row['cost']));
}else{
$cost = $cost + $row['cost'];
}
$y = $y + 5;
}
}
}
//Line(float x1, float y1, float x2, float y2)
$pdf->line(10,55, 200, 55);
$pdf->line(32,55, 32, $y+5);
$pdf->line(10,55, 10, $y+35);
$pdf->line(200,55, 200, $y+35);
$pdf->line(170,55, 170, $y+5);
$pdf->line(10,$y+5, 200, $y+5);
$y = $y + 10;
$pdf->setXY(150, $y);
$pdf->SetFont('Arial','B',10);
$pdf->cell(0,0, "Base Cost:");
$pdf->setXY(180, $y);
$pdf->cell(0,0, "".number_format($pRow['option_1'],2));
$pdf->line(10,$y+5, 200, $y+5);
$y = $y + 10;
$pdf->setXY(145.3, $y);
$pdf->cell(0,0, "Addons Cost:");
$pdf->line(10,$y+5, 200, $y+5);
$pdf->setXY(180, $y);
$pdf->cell(0,0, "".number_format($cost,2));
$y = $y + 10;
$pdf->setXY(150, $y);
$pdf->cell(0,0, "Total Cost:");
$pdf->setXY(180, $y);
$pdf->cell(0,0, "".number_format($price,2));
$pdf->line(10,$y+5, 200, $y+5);

$pdf = $pdf->Output("hello","S");// this will equal the pdf output content
$text = strip_tags($html);
$boundry = md5(date('r', time()));
$mime_boundary = "--Multipart_Boundary_x{$boundry}x";
$mime_boundary2 = "--Multipart_Boundary_{$boundry}";
$headers = "Date: ".date("D, d M Y H:m:s")."
From: DTP Site <noreply@dtpgroup.co.uk>
Subject: This is your Configurator Specs
MIME-Version: 1.0
Content-Type: multipart/related;
type=\"multipart/alternative\";
boundary=\"$mime_boundary\"";
$msg = "

--$mime_boundary
Content-type: multipart/alternative;
boundary=\"$mime_boundary2\"

--$mime_boundary2
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$text

--$mime_boundary2
Content-Type: text/html; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

$html

--$mime_boundary2--

--$mime_boundary
Content-Type: text/csv
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=\"DTP_Configurator_Specs.csv\"

$csv

--$mime_boundary
Content-Type: application/octet-stream
Content-Tramser-Encoding: base64
Content-Disposition: attachment; filename=\"DTP_Configurator_Specs.pdf\"

".chunk_split(base64_encode($pdf))."

--$mime_boundary--

";
$check = @mail($to, "This is your Configurator Specs", $msg, $headers);


In the email i get what appears to be a chunk_split base64 encoded pdf file but if i open the attachment it just wont open in any thing pdf reader google docs any thing,



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum