PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
eyespark
Forum Commoner
Posts: 50 Joined: Tue Jan 24, 2006 7:36 am
Post
by eyespark » Tue Oct 17, 2006 3:55 am
I would like to send multipart emails with this code:
Code: Select all
$mejl_query = "SELECT * FROM ".SUBSCRIBERS." WHERE is_activated = '1' && list_id='$list_id'";
$mejl_result = mysql_query($mejl_query) or die("Query failed : " . mysql_error());
while ($mejl_row = mysql_fetch_array($mejl_result))
{
$to = $mejl_row['email'];
$subject = $subject;
$msg = "<p>Some text here</p><p>some more text</p>";
$msg .= " To unsubscribe......";
$headers = "From: info@something.net\r\nReply-To: info@something.net\r\nX-Mailer: something.net\r\n";
$boundary = md5(uniqid(time()));
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative;\r\n";
$headers .= " boundary=\"$boundary\"\r\n";
$message = "invisible\r\n\r\n";
$message .= "--$boundary\r\n";
$message .= "Content-type: text/plain; charset=utf-8\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= strip_tags($msg) . "\r\n";
$message .= "--$boundary\r\n";
$message .= "Content-type: text/html; charset=utf-8\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$message .= $msg . "\r\n";
$message .= "--$boundary--\r\n";
if(mail($to, $subject, $message, $headers)){echo ". ";} else {echo "X";}
}
echo "<p>Message sent.</p>";
The problem is that in my test emails everything is visible - boundary, invisible part, plain text part and html part (including html tags). Please help.
Thanks
eyespark
Forum Commoner
Posts: 50 Joined: Tue Jan 24, 2006 7:36 am
Post
by eyespark » Tue Oct 17, 2006 5:06 am
I know, it is excellent script. I also looked at some classes from phpclasses.org... but I would really like to know, where did I go wrong.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Oct 17, 2006 5:27 am
Post the source which gets output by this (find the "View Email Source" feature in your mail client) and I'll tell you.
eyespark
Forum Commoner
Posts: 50 Joined: Tue Jan 24, 2006 7:36 am
Post
by eyespark » Tue Oct 17, 2006 8:21 am
Code: Select all
From - Mon Oct 16 18:58:19 2006
X-Account-Key: account2
X-UIDL: AAwcp+BAAAw1ouA6TKQBzyEnwryvcww+
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
Received: from somethig.net ([87.233.133.136]) by somethig with Microsoft SMTPSVC(6.0.3790.211);
Mon, 16 Oct 2006 18:54:43 +0200
Received: (qmail 5835 invoked by uid 48); 16 Oct 2006 18:58:02 +0200
Date: 16 Oct 2006 18:58:02 +0200
Message-ID: <20061016165802.5833.somethig@somethig.net>
To: somethigc@somethig.com
Subject: test
From: info@somethig.net
Reply-To: info@somethig.net
X-Mailer: somethig.netMIME-Version: 1.0
Content-type: multipart/alternative;
boundary="d3ff277506e5510651b17207ecf2da23"
Return-Path: something@somethig.net
X-OriginalArrivalTime: 16 Oct 2006 16:54:43.0875 (UTC) FILETIME=[C77F4F30:01C6F143]
invisible
--d3ff277506e5510651b17207ecf2da23
Content-type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
dasfasdf HTML verzija.
dasfasdf HTML verzija.
dasfasdf HTML verzija.
To unsubscribe...
--d3ff277506e5510651b17207ecf2da23
Content-type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
<p>dasfasdf <b>HTML</b> verzija.</p>
<p>dasfasdf <b>HTML</b> verzija.</p>
<p>dasfasdf <b>HTML</b> verzija.</p>
<p>To unsubscribe...</p>
--d3ff277506e5510651b17207ecf2da23--
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Tue Oct 17, 2006 8:55 am
Change \r\n to just \n. mail() is a bit dim-witted and plays around with the line endings depending upon the OS. Some MTAs actually do this too and make a mess of it (qMail anyone?).
I'll hazard a guess you're on a linux server not a windows one
eyespark
Forum Commoner
Posts: 50 Joined: Tue Jan 24, 2006 7:36 am
Post
by eyespark » Tue Oct 17, 2006 10:52 am
Jup, I'm on linux.
Thanks, I'll try your suggestion.