Jump to content

Archived

This topic is now archived and is closed to further replies.

michaellunsford

trying to create multipart/alternative email.

Recommended Posts

I have taken an actual multipart/alternative email and copied it character for character. The original displays as HTML, but my version comes in blank with a file attachment called "mime-attachment"

I've been hacking away at this for months, trying different variations of the email, but nothing seems to be working. I've tried using \r and \r\n for newlines, and I've just given up. I know I'm missing something simple, someone please set me straingt.

Thanks!

Want to play with it and see what it's doing?
http://www.virtual-showcase.net/mail_test.php

Share this post


Link to post
Share on other sites
You can use the function nl2br() to make new lines into the <br /> tag.

Share this post


Link to post
Share on other sites
[code]<?php
if ($_POST['subject']) {
$recep = explode(",",$_POST['to']);
reset($recep);
$err="";
$whodat="From: ".$_POST['from']."\n";
$whodat.="MIME-Version: 1.0\n";
$boundary=uniqid("HTMLDEMO");
$whodat.="Content-Type: multipart/alternative;\n\tboundary=\"$boundary\"\n";
$bodytext.="This is a MIME encoded message.\n\n";
$bodytext.="--$boundary\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: 8bit\n\n";
$bodytext.=stripslashes($_POST['plaintext'])."\n";
$bodytext.="--$boundary\nContent-Type: text/html; charset=ISO-8859-1\nContent-Transfer-Encoding: 8bit\n\n";
$bodytext.=stripslashes($_POST['htmltext']);
do {
if(!mail(current($recep), $_POST['subject'], $bodytext, $whodat)) $err.=current($recep).", ";
} while (next($recep));
if($err!="") {
echo "Errors! These folks received squat: ".$err;
} else echo "Bubba says, \"Check your e-mail!\"";
} else echo "<html>
<head>
<title>Really Cool Mass Mailer</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>
<body><form action=\"mailme.php\" method=\"post\">
<table><tr><td>To:<td><input type=\"text\" name=\"to\">
<tr><td>From:<td><input type=\"text\" name=\"from\">
<tr><td>Subject:<td><input type=\"text\" name=\"subject\">
<tr><td>HTML Message<td><textarea name=\"htmltext\" rows=\"10\" cols=\"80\"></textarea>
<tr><td>Plain Text<td><textarea name=\"plaintext\" rows=\"10\" cols=\"80\"></textarea>
<tr><td colspan=\"2\"><input type=\"reset\">&nbsp;&nbsp;<input type=\"submit\"></table></form>
</body>
</html>
";
?>
[/code]

Share this post


Link to post
Share on other sites
So what error are you getting exactly? Is it not sending, wrong formatting...? You need to be more specific. :)

Share this post


Link to post
Share on other sites
[quote]my version comes in blank with a file attachment called "mime-attachment"[/quote]

The email arrives in my inbox with no body, just a file attachment called "mime-attachment"

Share this post


Link to post
Share on other sites
I use the code below and I am able to send both plain text and html .

[code=php:0]$headers = "From: you@yoursite.com\r\n" .
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html; charset=utf-8\r\n" .
      "Content-Transfer-Encoding: 8bit\r\n\r\n";
    mail($to, $subject, $message, $headers)or die('something went wrong'); [/code]

try this instead and see that happens

Hope this helps

Tom

Share this post


Link to post
Share on other sites
I have been able to get the html only email working, just not the multipart. I'm missing something and just can't figure out what it is.

I tried emailing an address I check with my email client and get the blank body with a "mime attachment." If I send it to my old yahoo account, it comes across as plain text -- everything below the header prints just like it's part of an email. It's just nuts.

Share this post


Link to post
Share on other sites
One other note... the HTML email seems to work with anything but .mac accounts. Any idea what could be causing .mac to not receive the email at all?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.