Page 1 of 1

Unwanted txt file attachment on emails

Posted: Wed Jan 26, 2005 7:22 pm
by SBro
Currently I have an email script which displays a HTML file inline in an email. You can choose to add text to the beginning of the email (ie. before the html file is displayed) For some reason however the text that is meant to go before the html file is being displayed in an attachment of the form AT000xx.txt

If no html file is attached, then the text is displayed fine in the body (but still with attachment copy) If the html file is displayed then the other text is only displayed in the attachment. I deliberatley haven't attached any code to this post, because a) i'm hoping it's a simple MIME type problem or something and b) it's someone elses code I'm working on, read: trying to fix. Thanks.

Posted: Wed Jan 26, 2005 8:21 pm
by shiznatix
i dunno how ur putting in this text file but try include("textfile.txt"); would work if i am picturing this code correctly, post the code thou so we can all have a closer look instead of just guessing

Posted: Wed Jan 26, 2005 9:08 pm
by SBro
This is how it works:

Code: Select all

$m= new Mail; // create the mail
	$m->To( "$to" );
	$m->From( "$from" );
	$m->Subject( $_POSTї'email_subject'] );
	
        // $email_body gets the contents of the textarea where user can enter additional text, should be displayed before the inline html, instead is being displayed in attachment: ATT000xx.txt
       
        $m->Body( $email_body );	// set the body
	//$m->Cc( $email_adds );
	$m->Bcc( $email_adds );
	$m->Priority(4) ;	// set the priority to Low
	// inline intructs the mail client to display the HTML if it can
	$m->Attach( $html_file_name, "text/html", "inline" );
        $m->Send();
The class for this is over 300 lines so I won't post (can post specific function etc if required) but you can see the complete class online here:
http://cuib.laborales.unam.mx/publicaciones/Libmail.inc

Posted: Wed Jan 26, 2005 9:14 pm
by feyd
I would imagine that because the client supports the "inline" component of the html attachment, it has to attach the text that was originally inlined. What about placing a "templatable" variable where the posted text can be copied into the html?

Posted: Wed Jan 26, 2005 9:18 pm
by shiznatix
this should work. feyd if im wrong tell me. add there were you put in your own comment

Code: Select all

$open_txt_file = file_get_contents("textfile.txt");
$email_body = $open_txt_file .'<br>'. $email_body;

Posted: Wed Jan 26, 2005 9:26 pm
by SBro
Feyd, yes I have considered this and can get the text to display in the email using your method, however a txt file is still attached to the e-mail which is the main problem.

Shiznatix: There is no text file initially $email_body comes from a textarea ie.
$email_body = $_POST['textarea'];
But then somewhere along the line it gets placed in a text file for attachment, probably because as Feyd suggested it is attaching the html file inline.

Posted: Wed Jan 26, 2005 9:28 pm
by feyd
what's wrong with just making the html the "normal" email content?

Posted: Wed Jan 26, 2005 9:35 pm
by SBro
Hmm good point, I might try that, I guess since I was already implementing an external class (and since this originally wasn't my code) I hadn't considered that, thanks for your help.