Solved

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

Posted on 2011-02-22
3
1,394 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
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

820 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