Solved

PHP Mail Multipart Showing Blank in Yahoo

Posted on 2009-05-07
1
495 Views
Last Modified: 2012-05-06
I have a multi-part email that I am sending off, I have tested it in Hotmail, Thunderbird, Outlook and Yahoo.  It works fine in all but Yahoo.  In Yahoo it is coming through but blank.  I have played with the headers a bit and if I leave the "Content-Type" blank it will come through raw.  If I included the Content-Type header it will come through blank.

I had read that the boundary in the header needed to be surrounded by double quotes so I added those, that didn't.  Here is the header from Yahoo where it is coming through blank, it looks fine to me.  Blow is the full code, I am sure I am missing something very simple but this is a real big problem.


~~~~~~~~~~~~~~~~~~Bad Yahoo Header~~~~~~~~~~~~~~~~~
From XXXXX Thu May  7 06:27:37 2009
Return-Path: <xxx@xxxx.com>
Authentication-Results: mta347.mail.mud.yahoo.com  from=xxxx.com; domainkeys=neutral (no sig); from=xxx.com; dkim=neutral (no  sig)
Received: from 67.192.241.184  (EHLO smtp184.xxx.xxx.com) (67.192.241.184)
  by mta347.mail.mud.yahoo.com with SMTP; Thu, 07 May 2009 06:27:38 -0700
Received: from relay8.relay.xxx.xxx.com (localhost [127.0.0.1])
      by relay8.relay.xxx.xxx.com (SMTP Server) with ESMTP id B4B9C403AC;
      Thu,  7 May 2009 09:27:37 -0400 (EDT)
Received: by relay8.relay.xxx.xxx.com (Authenticated sender: customer-AT-xxxxx.com) with ESMTPA id A9A054039F;
      Thu,  7 May 2009 09:27:37 -0400 (EDT)
From: xxxxxxxxx <xxxx@xxxxxxxxxx.com>
To: xxxxxxxxxxxx@yahoo.com
Subject: Subject
Content-Type: multipart/alternative; boundary="PHP-alt-22dc05556024f4de66cfa8490508b585"
Date: Thu, 07 May 2009 08:27:37 -0500
Message-ID: <91ec1f9324753048c0096d036a694f86@austinkayak.com>
Content-Length: 3829

<?php
 
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time())); 
 
//define the receiver of the email
$subject = "Subject";
$headers["From"] = "xxxx <xxx@xxx.com>";
$hearder["Reply-To"] = "xxx <xxx@xxx.com>";
$headers["Return-Path"] = "xxx@xxx.com";
$headers["To"] = $RecipientEmail;
$headers["Subject"] = $subject;
//add boundary string and mime type specification
//$headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
$headers["Date"] = date('r');
    $retArray = "xxx@xxx.com";
	$theMSGID = $retArray;
	$theMSGID = explode("@", $theMSGID);
	$theMSGID = "<".md5($theMSGID[0])."@xxxx.com>";
$headers["Message-ID"] = $theMSGID; 
$headers["X-Mailer"] = "PHP v".phpversion();
$headers["X-Priority"] = "3";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
 
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash;?>
 
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit
 
Some simple text
 
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
 
<html>
<body>
            <table width=770 cellpadding=5 cellspacing=0>
              <tr>
            	<td width=375 rowspan=2>some simple html
				</td>
				</tr>
				</table>
</body>
</html>
 
--PHP-alt-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
 
require_once('/home/xxxx/public_html/utilities/includes/xxxx_config.php');
 
$mail_object =& Mail::factory("smtp", $smtpinfo);
 
$RecipientEmail .= "," . "xxx@xxxx.com";
$mail_object->send($RecipientEmail, $headers, $message);
 
?>

Open in new window

0
Comment
Question by:pmessana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
pmessana earned 0 total points
ID: 24328750
Wow, this was a simple one and I am surprised that it wasn't answered before I figured it out.  The parsing after an echo was muffed up.

--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"

needed to be

--PHP-alt-<?php echo $random_hash; ?>

Content-Type: text/html; charset="iso-8859-1"

The extra line break is necessary and fixes the problem, without it it is merging both lines together and thus making the boundary invalid.

0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question