View Full Version : Help with mail code
Hi All,
Im new here and was seeking a little advise on a mail script please
I have attached my mailform php code which works 100% if you add an attachement to it when submitting and the email is all laid out in a html table.
The issue arises when you don't add an attachement and the email comes in just plain text and all the html is gone and only 1 field is submitted.
Any help would be greatly appreciated.
thanks in advanced
bluewalrus
08-11-2010, 01:08 PM
You've got your message set up in the if for the file upload. Try this
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
}
$message = "
Message Recieved From: $name
<br /><br />
<table border='1' bordercolor='#3300FF' style='background-color:#CCFF66' width='50%' cellpadding='3' cellspacing='3'>
<tr>
<td style='background-color:yellow' colspan='2' align='center'><b>Contact Details</b></td>
<td></td>
<td style='background-color:yellow' colspan='4' align='center'><b>Equipment Owned</b></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Name</td>
<td>$name</td>
<td></td>
<td>$pc</td>
<td>$laptop</td>
<td>$printer</td>
<td>$tv</td>
</tr>
<tr>
<td>Email</td>
<td><a href='mailto:$email'>$email</a></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Phone</td>
<td>$phone</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Over 18</td>
<td>$group1</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
";
// Add a multipart boundary above the plain message
$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
Hi bluewalrus,
I swapped all that part of the code in my original file and all I get in the email now is all the actual html code laid out for the table
bluewalrus
08-11-2010, 07:02 PM
You need to adjust the headers. I'm not sure if you need a special one for the attachment though.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.