PHP Classes

Plain text parts mistakenly showing up as attachments

Recommend this page to a friend!

      MIME E-mail message sending  >  MIME E-mail message sending package blog  >  How Can PHP Send Emai...  >  All threads  >  Plain text parts mistakenly showing...  >  (Un) Subscribe thread alerts  
Subject:Plain text parts mistakenly showing...
Summary:Plain text part showing up as an attachment
Messages:2
Author:poisa
Date:2010-01-27 04:55:22
Update:2010-01-27 05:11:41
 

  1. Plain text parts mistakenly showing...   Reply   Report abuse  
Picture of poisa poisa - 2010-01-27 04:55:22
Hi Manuel,

Congratulations in a most excellent and well documented class!

I have a quick question for you. Everything is working fine except that the plain text part keeps showing up as an attachment in various mail clients (like Outlook 2003/2007).

Here's the code I'm using and at the end there is a dump of the debug output the class generates so that you can see the actual MIME body.

I've replaced the sensitive data with "(snip)".


<?php

require ("lib/mail/email_message.php");
require ("lib/mail/smtp_message.php");
require ("lib/mail/smtp.php");
require ("lib/mail/sasl.php");

$from_name = "My Name";
$from_address = "me@example.com";

$reply_name = $from_name;
$reply_address = $from_address;
$error_delivery_name = $from_name;
$error_delivery_address = $from_address;

$to_name = "Bob";
$to_address = "bob@mail.com";
$subject = "Testing email class...";
$text_message = "I'm testing the email server for problems.";
$html_message = "<html><head><title>Some Test</title></head><body><h1>Hello World</h1></body></html>";

$email_message = new smtp_message_class();

$email_message->localhost = "localhost";
$email_message->smtp_host = "mail.example.com";
$email_message->smtp_port = 25;
$email_message->smtp_ssl = 0;
$email_message->smtp_start_tls = 0;
$email_message->smtp_direct_delivery = 0;

$email_message->smtp_exclude_address = "";
$email_message->smtp_user = "user";
$email_message->smtp_password = "pass";
$email_message->smtp_pop3_auth_host = "";
$email_message->smtp_realm = "";
$email_message->smtp_workstation = "";
$email_message->smtp_authentication_mechanism = "";
$email_message->smtp_debug = 1;
$email_message->smtp_html_debug = 0;

$email_message->SetEncodedEmailHeader("To", $to_address, $to_name);
$email_message->SetEncodedEmailHeader("From", $from_address, $from_name);
$email_message->SetEncodedEmailHeader("Reply-To", $reply_address, $reply_name);
$email_message->SetHeader("Return-Path", $error_delivery_address);
$email_message->SetEncodedEmailHeader("Errors-To", $error_delivery_address, $error_delivery_name);
$email_message->SetEncodedHeader("Subject", $subject);
$email_message->AddQuotedPrintableTextPart($email_message->WrapText($text_message));
$email_message->AddQuotedPrintableHTMLPart($html_message);

$error = $email_message->Send();

if ($error != "") {
echo "Error: $error\n";
} else {
echo "Done.\n";
}


/*
Resolving SMTP server domain "(snip)"...
Connecting to host address "(snip)" port 25...
Connected to SMTP server "(snip)".
S 220 (snip) ESMTP
C EHLO localhost
S 250-(snip)
S 250-AUTH=LOGIN CRAM-MD5 PLAIN
S 250-AUTH LOGIN CRAM-MD5 PLAIN
S 250-STARTTLS
S 250-PIPELINING
S 250 8BITMIME
C AUTH LOGIN
S 334 VXNlcm5hbWU6
C bWVkaWFAbHZscm9waHktd3N0YS5jb20=
S 334 UGFzc3zzcmQ6
C MTIzM2d4dHJv
S 235 go ahead
C MAIL FROM:(snip)
C RCPT TO:(snip)
C DATA
S 250 ok
S 250 ok
S 354 go ahead
C To: (snip) <(snip)>
Subject: Testing email class...
From: (snip) <(snip)>
Reply-To: My Name <(snip)>
Return-Path: (snip)
Errors-To: My Name <(snip)>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="b1a06198656a8849b44a334a6207adc4"
Date: Tue, 26 Jan 2010 20:44:43 PST
Message-ID: <20100126204443.8547.(snip)>


C
--b1a06198656a8849b44a334a6207adc4
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I'm testing the email server for problems.

--b1a06198656a8849b44a334a6207adc4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<html><head><title>Some Test</title></head><body><h1>Hello World</h1></body=
></html>

--b1a06198656a8849b44a334a6207adc4--

C
.
S 250 ok 1264567484 qp 12364
C QUIT
S 221 (snip)
Disconnected.
Done.


*/
?>

  2. Re: Plain text parts mistakenly showing...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-01-27 05:11:41 - In reply to message 1 from poisa
I suppose you want to send an HTML message with an alternative text part.

In that case you need to compose a multipart/alternative message. Take a look at the test_simple_html_mail_message.php example script.

You may also take a look at this presentation, specially starting slide 7.

phpclasses.org/browse/video/3/packa ...