Having trouble with php mail and rich text/html formatting

Discussion in 'PHP' started by absentx, Nov 11, 2009.

  1. #1
    Trying to get my mass mail script to function with ckeditor and send out nice fancy emails. I am close but I still dont quite have it. Now it will send emails and use things like bold and italics, but no colors or anything else. Not sure where to look, but here is a look at some of my code, I found some of it from other sources trying to help with this situation, but its the closest I have come. I think it would have something to do with charset or something similar? Pretty new to php in general.

    while ($row = mysqli_fetch_array($result)){
    	$email = $row['email'];
    	
    	
    	$to = $row['email'];
    	$random_hash = md5(date('r', time())); 
    	$headers = "From: info@mywebsite.com\r\nReply-To:   info@mywebsite.com";
    	$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
    	
    	ob_start(); 
    ?>
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    <?php echo $message; ?>
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    <?php echo $message; ?>
    
    --PHP-alt-<?php echo $random_hash; ?>--
    <?
    PHP:

     
    absentx, Nov 11, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    put
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit
    into $message and use normal html format in $message
     
    javaongsan, Nov 11, 2009 IP
  3. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Icreated this functions its easy and better:

    function sendHTMLemail($HTML,$from,$to,$subject,$bcc)
    {
    // First we have to build our email headers
    // Set out "from" address
    
        $headers = "From: $from\r\n"; 
    
    //bcc
    	$headers .= "Bcc: $bcc\r\n"; 
    
    // Now we specify our MIME version
    
        $headers .= "MIME-Version: 1.0\r\n"; 
    
    // Create a boundary so we know where to look for
    // the start of the data
    
        $boundary = uniqid("HTMLEMAIL"); 
        
    // First we be nice and send a non-html version of our email
        
        $headers .= "Content-Type: multipart/alternative;".
                    "boundary = $boundary\r\n\r\n"; 
    
        $headers .= "This is a MIME encoded message.\r\n\r\n"; 
    
        $headers .= "--$boundary\r\n".
                    "Content-Type: text/plain; charset=utf-8\r\n".
                    "Content-Transfer-Encoding: base64\r\n\r\n"; 
                    
        $headers .= chunk_split(base64_encode(strip_tags($HTML))); 
    
    // Now we attach the HTML version
    
        $headers .= "--$boundary\r\n".
                    "Content-Type: text/html; charset=utf-8\r\n".
                    "Content-Transfer-Encoding: base64\r\n\r\n"; 
                    
        $headers .= chunk_split(base64_encode($HTML)); 
    
    // And then send the email ....
    
        mail($to,$subject,"",$headers);
        
    }
    PHP:
     
    xenon2010, Nov 11, 2009 IP
  4. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    excellent Ill try these suggestions out and report back!
     
    absentx, Nov 12, 2009 IP