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"
PHP Code:
$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));
fclose($file);
$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" .
"--{$mime_boundary}\n";
unset($data);
unset($file);
unset($fileatt);
unset($fileatt_type);
unset($fileatt_name);
$ok = @mail($email_to, $mailSubj, $email_message, $headers);