Jump to content

Recommended Posts

Hello.

 

Very quick version: Does anyone know how to encode an attachment in MIME to accept line rbeaks in.txt documents?

 

Long version:

 

I have this code that puts the attachment into my email that I'm gonna send below on the code.

 

$fileatt = "encomendas/$filename.txt"; // Path to the file
$fileatt_type = "text/html"; // File Type
$fileatt_name = "$filename.txt"; // Filename that will be used for the file as the attachment
$email_from = "geral@bastosviegas.com"; // Who the email is from
$email_subject = "Encomenda"; // The Subject of the email
$email_txt = "Dados do Cliente referente a Medicalexpress online<br>\n<br>\nNúmero: $nr <br>\n Nome: $name <br>\n Endereço: $endereco <br>\n Localidade: $localidade <br>\n Código postal: $cod_postal <br>\n País: $pais <br>\n Telefone: $telefone <br>\n Fax: $fax <br>\n Profissão: $profissao <br>\n Actividade: $actividade <br>\n Met. pagamento: $metpag <br>\n Email: $email <br>\n Nr. Contribuinte: $nrcont <br>\n Mensagem: $msg";
$email_to = "pedropeixoto@bastosviegas.com"; // Who the email is too
$headers = "From: ".$email_from;

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

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

$headers .= "\nMIME-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/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message . "\n\n" .
$email_txt . "\n\n";


$enc_txt = chunk_split(base64_encode($enc_txt));

$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" .
$enc_txt . "\n\n" .
"--{$mime_boundary}--\n";

 

It works. It sends the .txt attachment I want in the email.

 

The thing is, the .txt that comes with the email isint accepting line breaks. I guess it has to do with the base64 encoding so please can anyone tell me how to encode my .txt to accept line breaks?

 

Thank you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.