Re: problems with creating both HTML and plaintext emails

news_at_celticbear.com
Date: 01/21/05


Date: 21 Jan 2005 12:32:11 -0800

Sam wrote:
> news@celticbear.com writes:
> > What am I doing wrong?
>
> > "Content-Type:multipart/alternative;\n" .
> > " boundary=\"{$mime_boundary}\r\n\"";
>
> Bug #1. For starters, you're using LF everywhere else, and here you
have
> CRLF. Furthermore, it's misplaced. It should be after the closing
quote.
>
> You'll have to investigate whether PHP's mail() functions expects all
lines
> to be terminated by LF, or CRLF. I don't recall offhand. Then you
must
> change your code and use a consistent EOL.

OK, Below is my updated script.
\n is the appropriate EOL, so I've fixed that as well as where the
quotes were. That was just bad on my part.

> > ".
> > "--{$mime_boundary}\n
> > ";
>
> Bug #2. The closing boundary delimiter should have a trailing "--".

And you'll see I added that too.
I also looked around at more source code of my successfully received
newsletter e-mails and am trying to emulate them, so I made a couple of
other changes.
And yet, still doesn't work.
No matter what e-mail client I use, the source code for the e-mail
looks fine, it's all there...but nothing is visible in the e-mail
display.
In Kmail, it show a brief summary of the parts the e-mail includes, and
on mine it always says:

e-mail type: multipart/alternative 8bit (that's odd considering I use
7bit in the code) 19.6 KB
body part: Plain Text Document 0 KB

E-mails that work always has a 2nd "body part" as HTML listed, and
obviously, the appropriate size. Why mine seems to cut off detection at
the plain text doc and not have the size, I can't fathom. Everything
appears the same as working e-mails.

Anyway, thanks for the replies, and any tips are appreciated!
Liam

<?php
// PAGE CREATED 2004-06-01 by Liam
$today_day = date("w"); // Day of the week numeric: Sun=0,
Mon=1...Sat=6
$today = date("Y-m-d");

$to="Recipient Name <e-mail-addy>";
$from="Sender Name <another-email-addy>";
$subject="My first HTML E-mail";
$mime_boundary="Multipart-Boundary-".md5(mt_rand());
$headers = "From: $from\n" .
"MIME-Version: 1.0\n" .
"Content-Type:multipart/alternative;\n" .
" boundary=\"--{$mime_boundary}--\"\n";
$headers.= "From: $from\n";
$message = "--{$mime_boundary}--\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n".
"Content-Disposition: inline\n".
"Content-Transfer-Encoding: 7bit\n\n".
"(PLAIN TEXT DOC GOES HERE)" .
"--{$mime_boundary}--\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n".
"Content-Disposition: inline\n".
"Content-Transfer-Encoding: 7bit\n\n".
"<html>

<head>
<title>Welcome to E-Boot Camp Phase I</title>
</head>

<body bgcolor=\"#ffffff\">
(HTML DOC GOES IN HERE)
</body>
</html>
".
"--{$mime_boundary}---\n\n\n

";
if (mail($to, $subject, $message, $headers))
echo "Message Sent!";
else
echo "Failed to send message.";

?>



Relevant Pages

  • Re: root password?
    ... Right, it shows it without the markup, so Sylpheed is translating it. ... the "source code", of course. ... the html shows as plain text without formatting etc. ...
    (Ubuntu)
  • PhpOpenChat 3.0.x ADODB Server.php "sql" SQL injection
    ... look at the server.php source code: ... echo 'No response from '.$host.':'.$port; die; ... echo $html; ...
    (Bugtraq)
  • Re: New Imformation: Also Kellys Line 227 Left: Set IE Fonts
    ... that is different than posting html. ... included via plain text and are on rare occasions here. ... 2004 Windows MVP "Winny" Award ... > *what notepad is or where I can find it*--it was introduced in Windows 95 ...
    (microsoft.public.windowsxp.general)
  • Re: New Imformation: Also Kellys Line 227 Left: Set IE Fonts
    ... that is different than posting html. ... included via plain text and are on rare occasions here. ... 2004 Windows MVP "Winny" Award ... > *what notepad is or where I can find it*--it was introduced in Windows 95 ...
    (microsoft.public.windowsxp.customize)
  • Re: New Imformation: Also Kellys Line 227 Left: Set IE Fonts
    ... that is different than posting html. ... included via plain text and are on rare occasions here. ... 2004 Windows MVP "Winny" Award ... > *what notepad is or where I can find it*--it was introduced in Windows 95 ...
    (microsoft.public.windowsxp.basics)