Kyrus Posted July 27, 2009 Share Posted July 27, 2009 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 = "[email protected]"; // 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 = "[email protected]"; // 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. Link to comment https://forums.phpfreaks.com/topic/167608-mail-with-simple-txt-attachment-gone-wrong/ Share on other sites More sharing options...
JonnoTheDev Posted July 27, 2009 Share Posted July 27, 2009 Use PEAR MAIL::MIME or swiftmailer libraries for sending attachments http://pear.php.net/package/Mail_Mime Not that base64 crap and mail(); Link to comment https://forums.phpfreaks.com/topic/167608-mail-with-simple-txt-attachment-gone-wrong/#findComment-883837 Share on other sites More sharing options...
patrickmvi Posted July 27, 2009 Share Posted July 27, 2009 PHPMailer also works well for that sort of thing: http://sourceforge.net/projects/phpmailer/ Link to comment https://forums.phpfreaks.com/topic/167608-mail-with-simple-txt-attachment-gone-wrong/#findComment-883856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.