I am trying to send an email via php with an attchment. Before anyone suggests using pear or swiftmailer I am aware of all of them but have a host who refuses to install any of them on my clients hosting account.
So I am stuck with writing this function from scratch.
Anyway my code half works in that it is sending me an email but without the attachment and in the body of the email I see the following
This is a multi-part message in MIME format. --==Multipart_Boundary_x9cb327f93cc70e9f329be5f652ca6252x-- Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit --==Multipart_Boundary_x9cb327f93cc70e9f329be5f652ca6252x Content-Type: pdf; name="zwgScheduleMar" Content-Disposition: attachment; filename="zwgScheduleMar" Content-Transfer-Encoding: base64 endnU2NoZWR1bGVNYXJwZGY= --==Multipart_Boundary_x9cb327f93cc70e9f329be5f652ca6252x--
I am thinking their is an error in my header code for the email
Here is my code
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}--\r\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n ";
// Base64 encode the file data
$data = chunk_split(base64_encode(zwgScheduleMar.pdf));
$fileatt_name = 'zwgScheduleMar';
$fileatt_type = 'pdf';
// Add file attachment to the message
$message .= "--{$mime_boundary}\r\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}--\r\n";
I am hoping someone might help me spot my error in the above code
Thank you