Hi guys,
I cant see anything wrong but the email i get sent has an empty xls file instead of the file just created.
The file is create and is how it should be but it just not being attached to the email.
Can anyone see anything wrong?
$sdTitle = $_POST['sdTitle'];
$sdName = $_POST['sdFname'];
$sdLast = $_POST['sdLname'];
$sdEmail = $_POST['sdEmail'];
$sdMoby = $_POST['sdMobile'];
$sdAdd1 = $_POST['sdAdd1'];
$sdAdd2 = $_POST['sdAdd2'];
$sdAdd3 = $_POST['sdAdd3'];
$sdAdd4 = $_POST['sdAdd4'];
$sdPost = $_POST['sdAdd5'];
$sdDob = $_POST['sdDob'];
$type = "application/x-msdownload";
$filepath = "temp/";
$file = $sdName."_".$sdLast.".xls";
$bod = "Hi <br>Please find attached ".$file. " file.";
$subject = "Form submission";
//----------------------------------//
function sendmsg($subject, $text, $from, $file, $type) {
$adminaddress = "paul@mydomain.com";
$content = fread(fopen("temp/".$file,"r"),filesize("temp/".$file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$name = $file;
$header = "From: $from
Reply-To: $from
";
$header .= "MIME-Version: 1.0
";
$header .= "Content-Type: multipart/mixed; boundary=$uid
";
$header .= "--$uid
";
$header .= "Content-Type: text/html
";
$header .= "Content-Transfer-Encoding: 8bit
";
$header .= "$text
";
$header .= "--$uid
";
$header .= "Content-Type: $type; name=\"$name\"
";
$header .= "Content-Transfer-Encoding: base64
";
$header .= "Content-Disposition: attachment; filename=\"$name\"
";
$header .= "$content
";
$header .= "--$uid--";
$ok = mail($adminaddress, $subject, "", $header);
if($ok){
echo "&retval=1&";
}
}
//----------------------------------//
// write xls file
$xls_file="<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<head>
<meta http-equiv='Content-type' content='text/html;charset=iso-8859-1' /></head>
<body>
<div id='Classeur1_16681' align=center x:publishsource='Excel'>
<table x:str border=0 cellpadding=0 cellspacing=0 width=100% style='border-collapse: collapse'>
<tr>
<td class=xl2216681 nowrap><b>Title</b></td>
<td class=xl2216681 nowrap><b>First Name</b></td>
<td class=xl2216681 nowrap><b>Last Name</b></td>
<td class=xl2216681 nowrap><b>Address 1</b></td>
<td class=xl2216681 nowrap><b>Address 2</b></td>
<td class=xl2216681 nowrap><b>Address 3</b></td>
<td class=xl2216681 nowrap><b>Address 4</b></td>
<td class=xl2216681 nowrap><b>Postcode</b></td>
<td class=xl2216681 nowrap><b>Mobile Number</b></td>
<td class=xl2216681 nowrap><b>Email</b></td>
<td class=xl2216681 nowrap><b>d.o.b</b></td>
<td class=xl2216681 nowrap><b>OPT IN?</b></td>
</tr>
<tr>
<td class=xl2216681 nowrap>$sdTitle</td>
<td class=xl2216681 nowrap>$sdName</td>
<td class=xl2216681 nowrap>$sdLast</td>
<td class=xl2216681 nowrap>$sdAdd1</td>
<td class=xl2216681 nowrap>$sdAdd2</td>
<td class=xl2216681 nowrap>$sdAdd3</td>
<td class=xl2216681 nowrap>$sdAdd4</td>
<td class=xl2216681 nowrap>$sdPost</td>
<td class=xl2216681 nowrap>$sdMoby</td>
<td class=xl2216681 nowrap>$sdEmail</td>
<td class=xl2216681 nowrap>$sdDob</td>
<td class=xl2216681 nowrap>$sdOpt</td>
</tr>
</table>
</div>
</body>
</html>";
// If file does not exist create and make writeable
if (!file_exists($filepath.$file)){
$handle = fopen($filepath.$file, 'w+');
if (fwrite($handle, $xls_file) === FALSE){
echo '&phpError=Cannot write to file ('.$filepath.$file.').&';
exit;
} else{
sendmsg($subject, $bod, 'no-reply@yourdomain.com', $file,$type);
}
}
Thanks
Paul