Jump to content


Photo

trying to create multipart/alternative email.


  • Please log in to reply
8 replies to this topic

#1 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 July 2006 - 09:05 PM

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-s...t/mail_test.php

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 15 July 2006 - 09:20 PM

post what code you have so far

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 09:23 PM

You can use the function nl2br() to make new lines into the <br /> tag.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 July 2006 - 09:24 PM

<?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>
";
?>


#5 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 09:27 PM

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

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#6 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 July 2006 - 09:32 PM

my version comes in blank with a file attachment called "mime-attachment"


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

#7 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 15 July 2006 - 09:41 PM

I use the code below and I am able to send both plain text and html .

$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');

try this instead and see that happens

Hope this helps

Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#8 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 16 July 2006 - 01:57 PM

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.

#9 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 16 July 2006 - 08:48 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users