Solved

PHPMailer not showing HTML properly in gmail and outlook? why?

Posted on 2011-02-22
3
1,430 Views
Last Modified: 2012-05-11
Hi guys

I am send a HTML formatted email. but when i receive in gmail it doesnt show any html. not even the IMG.

when receiving in outlook it shows the IMG but doesnt process the styles.

when receiving on LIVE.com it shows as it should.

What am i doing wrong here.
function sendEmail($UserId,$content,$headLine="Message From DateFeast"){
    global $smtpServer;
    $select = "SELECT Email FROM Users WHERE UserId=$UserId LIMIT 1";
    $rs = mysql_query($select);
    $row = mysql_fetch_array($rs);
    $Email = $row['Email'];

    $str = "
        <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
        <html xmlns='http://www.w3.org/1999/xhtml'>
        <head>
        <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
        <style type='text/css'>
        *{font-family:Arial;font-size:8pt;}    
        body{background-color:#211c19;margin:0;}
        .mainTable{min-width:600px;border:1px solid black;}
        .top{text-align:left;float:left;width:auto;height:77px;border-bottom:3px solid #dfca91;background-color:#490105;vertical-align:top;font-size:8pt;padding-right:14px;overflow:hidden;}
        .middle{width:100%;	background-repeat:no-repeat;	background-position:0px -1px;background-color:#3c312d;vertical-align:top;}
        .middleContainer{padding-left:5px;padding-right:5px;	}
        .bottom{border-top:3px solid #dfca91;background-color:#490105;height:55px;}
        .ContainerDiv{vertical-align:top;}
        .ContainerDivHolder{z-index:1;position:relative;top:-44px;vertical-align:top;padding-left:16px;}
        .ContainerImage{position:relative;left:0px;z-index:2;}
        .ContainerGraphic{vertical-align:top;border:1px solid #84713e;overflow:hidden;}
        .ContainerTop{vertical-align:top;height:31px;width:100%;background-color:#3c0105;}
        .ContainerTopText{text-align:left;font-weight:bold;color:#fadf9a;padding-top:6px;padding-left:40px;}
        .ContainerContent{background-color:#c4af78;height:100%;}
        </style>
        </head>
        <body>
        <center>
        <table cellpadding='0' cellspacing='0' border='0' class='mainTable'>
	        <tr><td class='top'><div style='padding-left:20px;padding-top:5px;text-align:left;'><img src='http://www.mydomain.com/images/myimage.png'></div></td></tr>
            <tr><td class='middle'>
            <div style='padding:10px;'>
                <div class='ContainerGraphic' style='width:100%;'>
				    <div class='ContainerTop'><div class='ContainerTopText' style='padding-left:5px;'>".$headLine."</div></div>
				    <div class='ContainerContent' id='Div1' style='padding:5px;padding-top:10px;overflow:hidden;' >
                    ".$content."
                    <br><br>
                    </div>
                </div>
            </div>
            
            </td></tr>
            <tr><td class='bottom'>&nbsp;</td></tr>
        </table>
        </center>
        </body>
        </html>
    ";

    
    $mail = new PHPMailer();
    $mail->IsHTML(true); 
	$mail->From     = "noreply@mydomain.com";
	$mail->FromName = "MyDomain Email";
    $mail->Host     = $smtpServer;
    $mail->Mailer   = "smtp";
	$mail->Body    = $str;
	$mail->AltBody = $str;
	$mail->Subject = "MyDomain Email";
    $mail->AddAddress($Email, '');
    $mail->AddAddress('MyDomain@gmail.com', '');

    if(!$mail->Send()){
		$mail->ClearAddresses();
	    $mail->ClearAttachments();
        return false;
	}else{
		$mail->ClearAddresses();
	    $mail->ClearAttachments();
        return true;
    }
	die();

}

Open in new window

0
Comment
Question by:tim_carter
[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
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 34954409
Because they don't support all of what you are doing.  Look here: http://www.campaignmonitor.com/css/  Gmail strips your 'style' sections and ignores them.  Outlook can be kind of crippled with HTML.  Email clients are not web browsers and those that use the web browser like Gmail, Yahoo, and Hotmail, rewrite your code to prevent their pages from breaking.
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34954438
so is there a place where you can see the tags that are allowed?
0
 
LVL 1

Author Comment

by:tim_carter
ID: 34954446
sorry, checked the link. thankss
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

739 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