SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate multipart/alternative email

    Well I've done the code for a basic html email, now I want to create an email with plain text and html, for maximum compatibility...

    I was recommended to find a class etc.. but i want to do it from scratch..

    The email is sending, but when i view it in windows live (a live co uk email), it's blank...

    Can anyone shine a light on this???

    Ps Ive had to bash the code a bit to remove the website / ip and email addresses etc as Ive not made 5 posts yet


    My PHP is:
    Code:
    	$semi_rand = md5(time());
    	$varBoundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    	
    	$vTo = $varTo;
    	$vSubject = $varSubject;
    	$varMessage = wordwrap($varMessage);	
    	$varMessagePlus = wordwrap($varMessagePlus);		
    
    	$varHeaders = "From: email address" . "\n";
    	$varHeaders .= "Reply-To: email address " . "\n";				
    	$varHeaders .= "MIME-Version: 1.0\n";
    	$varHeaders .= "Content-type: multipart/alternative;   boundary=\"{$varBoundary}\"" . "\n"; 
    	$vHeaders = $varHeaders;	
    	
    	$vMessage =
    		"This is a multipart message in MIME format." . "\n" . 					
    		"\r\n\r\n--" . $varBoundary . "\n" . 
    		"Content-Type: text/plain; charset=\"iso-8859-1\"" . "\n" . 
    		"Content-Transfer-Encoding: 7bit" . "\n" . 
    		$varMessage .  
    		"\r\n\r\n--" . $varBoundary . "\n" . 
    		"Content-Type: text/html; charset=\"iso-8859-1\"" . "\n" . 
    		"Content-Transfer-Encoding: 7bit" . "\n" . 
    		$varMessagePlus .  
    		"\r\n\r\n--" . $varBoundary . "--";
    
    	if (@mail($vTo, $vSubject, $vMessage, $vHeaders) or die()) {
    		 return 0;
    	} else {
    		 return 1;
    	}
    The source for the resultant email is:
    Code:
    Sep 2009 21:06:54 +0100 
    Date: Wed, 09 Sep 2009 21:06:54 +0100 
    Subject: Test Message 
    To: email address 
    From:  email address 
    Reply-To: email address
    MIME-Version: 1.0 
    Content-type: multipart/alternative;   boundary="==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x" 
    Return-Path: email address 
    Message-ID: <WEBSERVER1Aq9KP8RlR00000021site address > 
    X-OriginalArrivalTime: 09 Sep 2009 20:06:54.0233 (UTC) FILETIME=[13959090:01CA3189]  
    
    This is a multipart message in MIME format.   
    
    --==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x 
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit 
    This is a plain text message... 		  
    
    --==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x 
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit 
    <html> 			<body> 				<h1>This is the HTML Message</h1> 				<p>With some more text...</p> 			</body> 		</html> 		 		  
    
    
    --==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x--

  2. #2
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Looks fine to me :\

    Only things i can suggest to play around with are

    * Change charset
    * Use quoted-printable instead of 7bit
    * Extra blank line after Content-Transfer-Encoding
    * Remove the "This is a multipart....." part

  3. #3
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What would you suggest I change the charset to? I'll check out the rest and report back

    Thanks

  4. #4
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    It's such a longshot - perhaps just utf8 or something different just to check. I don't imagine that's the issue though


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •