Page 1 of 1

Email attachments empty [SOLVED]

Posted: Fri Feb 04, 2005 8:36 am
by Naughtyboy
Hello all,

I am writing a mail form which passes the form field results to the recipient as an HTML email and as a CVS attachment. I am using the script found here http://www.hollowearth.co.uk/tech/php/e ... hments.php as a basis of my script. So far I have been able to get the form information sent to myself along with a CSV attachment however when I open the attachment is is always blank. Does anyone have ideas as to why this is?

Code: Select all

<?php

// this determines the recipient email based on the recipient name
if ($RecipientName == 'forrest') &#123;
$Recipient =  'me@mydomain.com';
&#125;  elseif ($RecipientName == 'frazier') &#123;
$Recipient =  'you@mydomain.com';
&#125;


// email subject
$Subject = "Customer Request Form";

// mime for attaching attachment to email
$mime_boundary = "<<<--==+X&#1111;".md5(time())."]";

$headers .= "From: $SendersName <$SendersEmail>\r\n"; 


$header .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: multipart/mixed;\r\n";  
$headers .= " boundary="".$mime_boundary.""";  


$message .= "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";

$message .= "Content-Type: text/html; charset=iso-8859-1\r\n"; //specifies it is to be an html email
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .="
Dear $RecipientName, <br />
<br />
$SendersName has sent you an e-mail using your online contact form.<br /> 
<br />
<b>Message:</b> <br />
$Body <br />
<br />
<hr noshade="true" size="1" color="#000000" /> 
You can contact $SendersName at <a href="mailto:$SendersEmail">$SendersEmail</a> or just reply to this e-mail."; 
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";

// atachment info
$message .= "Content-Type: application/octet-stream;\r\n";
$message .= " name="filename.csv"\r\n";
$message .= "Content-Transfer-Encoding: quoted-printable\r\n";
$message .= "Content-Disposition: attachment;\r\n";
$message .= " filename="filename.csv"\r\n";
$message .= "\r\n";
$message .= $fileContent;
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";

$ok = mail("$Recipient", "$Subject", $message, $headers);

// Message the user will see if the e-mail is succesfully sended :) 
header("Location: $ThanksPage");
exit;
?>

feyd | please use the formatting we provide

Posted: Fri Feb 04, 2005 8:44 am
by feyd
where does $fileContent magically appear from?

Posted: Fri Feb 04, 2005 8:55 am
by Naughtyboy
So I need to create an array for $fileContent that contains all the form fields. Right?

Posted: Fri Feb 04, 2005 8:58 am
by feyd
$fileContent is never defined in the code you posted. It's either somewhere else in the code, or appears from somewhere.. where does it come from?

Posted: Fri Feb 04, 2005 9:21 am
by Naughtyboy
Apparently right now it doesnt exist. However if I add

Code: Select all

$fileContent = "$RecipientName, $SendersName ";
Then my file content will be $RecipientName in the first column and $SendersName in the second.

Thanks