DPChallenge: A Digital Photography Contest You are not logged in. (log in or register
 

DPChallenge Forums >> General Discussion >> Any PHP coders want to debug a piece of mail code?
Pages:  
Showing posts 1 - 6 of 6, (reverse)
AuthorThread
07/12/2011 02:24:45 PM · #1
Anyone have experience with the PHP mail() function? I had this function written by a contractor awhile back and the email messages look fine in Outlook, but messed up in gmail or mac email clients. The function itself gets passed either an HTML message string or and HTML message string and separate plain text string. If only HTML string is passed, this function just strips the tags to create the plain text version.

This is the snippet from the mail function he wrote that is supposed to work for both plain text and html email clients. I believe the problem is with the headers and I am hoping that someone who has experience with this can easily identify the problem in the way the headers are being formed here - possibly to do with the boundary?

	$boundary = md5(uniqid(rand(), true));

$message_plain = ($message_plain == '') ? strip_tags($message_html) : $message_plain;
$headers = "From: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"';
$headers .= "\r\n";
$headers .= "--".$boundary."\r\n";
$headers.= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$headers .= $message_plain."\r\n";
$headers .= "--".$boundary."\r\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$headers .= $message_html."\r\n";
$headers .= "--".$boundary."--\r\n";

mail($to, $subject, '', $headers, "-f $from_email");


The HTML message is being duplicated in the resulting email.
Here are the resulting headers in the email message (some details X'd out):

Originally posted by "Email Header":

Return-path:
Envelope-to: art@artroflmao.com
Delivery-date: Tue, 12 Jul 2011 14:12:00 -0400
Received: from omr1.networksolutionsemail.com ([205.178.146.51])
by pbw3.pbwhosting.net with esmtp (Exim 4.69)
(envelope-from )
id 1QghR5-0000bp-AR
for art@artroflmao.com; Tue, 12 Jul 2011 14:12:00 -0400
Received: from vux.bos.netsolhost.com ([10.49.33.130])
by omr1.networksolutionsemail.com (8.13.6/8.13.6) with ESMTP id p6CIBocx008980
for ; Tue, 12 Jul 2011 14:11:50 -0400
Received: from vux130.mgt.hosting.dc2.netsol.com (smmsp@localhost [127.0.0.1])
by vux.bos.netsolhost.com (8.14.4/8.14.4) with ESMTP id p6CIBn1e022729
for ; Tue, 12 Jul 2011 14:11:50 -0400
X-SenderID: 2484570.2720926@localhost
Received: (from 2484570.2720926@localhost)
by vux130.mgt.hosting.dc2.netsol.com (8.14.4/8.14.4/Submit) id p6CI6o0D019248;
Tue, 12 Jul 2011 14:06:50 -0400
Date: Tue, 12 Jul 2011 14:06:50 -0400
Message-Id: <201107121806.p6CI6o0D019248@vux130.mgt.hosting.dc2.netsol.com>
X-Authentication-Warning: vux130.mgt.hosting.dc2.netsol.com: 2484570.2720926 set sender to XXXX@XXXXX.com using -f
To: Art Roflmao
Subject: Thank you for subscribing to our Newsletter!
From: XXXXX
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="c050e6b9069d02f9d2d0ee91cdea4b21"
X-Spam-Status: No, score=-2.3
X-Spam-Score: -22
X-Spam-Bar: --
X-Spam-Flag: NO


Or just point me to a chunk of code that I can replace this with that can easily be modified to work. Any help is mucho appreciado.
07/12/2011 09:00:13 PM · #2
How are they messed up? Is it garbage, or is it missing formatting?
07/12/2011 09:25:15 PM · #3
body of the message is duplicated, boundary code shows up in the body, html tags are exposed as plain text.

...I figured nobody could help me. :)
07/12/2011 09:28:40 PM · #4
07/12/2011 10:19:03 PM · #5
I haven't worked with python, but have some experience in other platforms. The program looms pretty straightforward. In any case, I found this link that walks you through each of the headers. Good luck.
Useful page
07/12/2011 11:39:33 PM · #6
Thanks Sam! Should help!
Pages:  
Current Server Time: 08/19/2025 03:45:05 AM

Please log in or register to post to the forums.


Home - Challenges - Community - League - Photos - Cameras - Lenses - Learn - Help - Terms of Use - Privacy - Top ^
DPChallenge, and website content and design, Copyright © 2001-2025 Challenging Technologies, LLC.
All digital photo copyrights belong to the photographers and may not be used without permission.
Current Server Time: 08/19/2025 03:45:05 AM EDT.