[TYPO3] Sending mail with attachments using t3lib_htmlmail

Rens Admiraal typo3 at ambitiondesign.nl
Wed Jul 18 10:37:51 CEST 2007


Hi all,

I'm trying to send mail with attachments, but I don't get it to work  
right.
Just sending the mail without the $mail->addAttachment line works  
fine. But, when I add the attachment the mail gets corrupted, and  
shows all headerdata in the body of the mail (including the content  
of the attachment). I've added an example beneath the code.

What am I doing wrong?

			$mail = t3lib_div::makeInstance('t3lib_htmlmail');
			$mail->start();
			$mail->useBase64();
			$mail->charset = 'iso-8859-1';
			$mail->plain_text_header = "Content-Type: text/plain;  
charset=iso-8859-1\nContent-Transfer-Encoding: quoted-printable";
			$mail->subject = $subject;
			$mail->from_email = $from_email;
			$mail->from_name = $from_name;
			$mail->organisation = $mail->from_name;
			$mail->replyto_email = $mail->from_email;
			$mail->replyto_name = $mail->from_name;
			$mail->mailer = $mailer;
			
			foreach ($attachments as $file) {
				if (is_file($file)) $mail->addAttachment($file);
			}
			
			$mail->setRecipient($this->form['toaddress']);
			$mail->setPlain($body);
			$mail->setContent();
			$mail->setHeaders();


Example:

This is a multi-part message in MIME format.

------------part_1_469c6fbf3ad1b
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Mailbody

------------part_1_469c6fbf3ad1b
Content-Type: application/octet-stream
  name="dummy26.doc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
  filename="dummy26.doc"

0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAOwADAP7/ 
CQAGAAAAAAAAAAAAAAACAAAAuAAAAAAAAAAA
EAAAAgAAAAEAAAD+////AAAAAAAAAACAAAA


More information about the TYPO3-english mailing list