I search and try different methods to produce a php mail with an attachment, which is saveable with the Client (Outlook). It doesn't work porper and I don't know why?
If the script send the mail with this code:
$result = mail($mail_to, $subject, $headers);
I got an email with an inline base64 coded attachment and if use it in this way:
$result = mail($mail_to, $subject, "", $headers);
or
$result = mail($mail_to, $subject, $text, $headers);
I got the PHP Error: "false" - the mail could not send.
So it isn't and Mailserverproblem, I think and from headersview I think, it should work and I get no mail error on the Linux site.
A part from the mail coming with the attachment inline:
MIME-Version: 1.0
From: user@nowhere.xyz
Content-Type: multipart/mixed; boundary="F34A3E8D822EE5A70EEDE9C3C143243C"
--F34A3E8D822EE5A70EEDE9C3C143243C
Content-Type: multipart/alternative; boundary="A0403290562B2A2F19FB62E48C51BE33"
--A0403290562B2A2F19FB62E48C51BE33
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Hello Mr. Xyz,
Some stupid text as an example.
--A0403290562B2A2F19FB62E48C51BE33--
--F34A3E8D822EE5A70EEDE9C3C143243C
Content-Type: application/CSV; charset="ISO-8859-1"; name="trouble.csv"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="trouble.csv"
...
YWNodW5nIG5pY2h0IGVyZm9yZGVybGljaCAvIG3DtmdsaWNoIjsiIjsiIjsK
--F34A3E8D822EE5A70EEDE9C3C143243C--
The matching PHP code:
$text = "Hello Mr. Xyz," . $nl . "Some stupid text as an example." . $nl;
$content = chunk_split(base64_encode($file));
$headers = "MIME-Version: 1.0" . $nl;
$headers .= "From: " . $mail_from . $nl;
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $boundary1 . "\"" . $nl . $nl;
$headers .= "--" . $boundary1 . $nl;
$headers .= "Content-Type: multipart/alternative; boundary=\"" . $boundary2 . "\"" . $nl . $nl;
$headers .= "--" . $boundary2 . $nl;
$headers .= "Content-Type: text/plain" . $nl;
$headers .= "Content-Transfer-Encoding: 8bit" . $nl . $nl;
$headers .= $text . $nl;
$headers .= "--" . $boundary2 . "--" . $nl . $nl;
$headers .= "--" . $boundary1 . $nl . $nl;
$headers .= "Content-Type: application/excel; charset=\"ISO-8859-1\"; name=\"xyz.csv\"" . $nl;
$headers .= "Content-Transfer-Encoding: base64" . $nl;
$headers .= "Content-Disposition: attachment; filename=\"xyz.csv\"" . $nl . $nl;
$headers .= $content . $nl;
$headers .= "--" . $boundary1 . "--" . $nl;
So, where is the bug? How can I debug such a Situation? Thx in advance...