Unwanted txt file attachment on emails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Unwanted txt file attachment on emails

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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;
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's wrong with just making the html the "normal" email content?
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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.
Post Reply