View Full Version : My Mail Headers aren't working

07-23-2008, 01:12 AM
Hi Everyone,

I have set up a form which on submit, sends off an email to the client with a plain text version in the body and an HTML file attached to the email.

But they are not receiving the email. They are using Mail Marshal, and it is blocking my forms emails from getting through. However, my own domain is letting them through fine...as is hotmail & my ISP's email.

I am assuming I have messed up the headers for the mail function. Can you please take a look at my headers and tell me if I have messed up. I am fine with basic headers, but when we include attachments, that's when I start getting lost. So any help would be appreciated. Cheers.

Please note that I have removed the domain name and replaced with "testdomain"

$mailSubj = 'New Assessment - '.date('d/m/Y ', time()).' Test Email ';

$fileatt = $location; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "assessment.html"; // Filename that will be used for the file as the attachment

$email_from = "web@testdomain.com"; // Who the email is from

$email_message = $mailBody; // Message that the email has in it

$email_to = "admin@testdomain.com"; // Who the email is too

$headers = "From: Test company <".$email_from.">\n";
$headers .= "Bcc: test@testdomain.com\n";

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

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

$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n";

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));

$data = chunk_split(base64_encode($data));

$email_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" .

$ok = @mail($email_to, $mailSubj, $email_message, $headers);

07-23-2008, 01:30 AM
Maybe it's just their spam filter, ask them to add your domain to the "allowed list".

07-23-2008, 01:34 AM
Yeah, tried that :)

This is the response I got...

This is not something I can tell Mail Marshal to ignore.

It is seeing this as a fundamental mail structure fault rather than bad content.

Which leads me to believe my headers are screwed.

07-23-2008, 02:18 AM
You could try using something like PHPMailer. I had issues with emails getting put in the user's spam box when I was using the normal mail() function. Then I tried PHPMailer which does give you the option to send a plain text and html version of the email and since then the emails haven't been marked as spam.