Jump to content

trying to create multipart/alternative email.


michaellunsford

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
Link to comment
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]
Link to comment
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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.