Solved

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

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

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
so is there a place where you can see the tags that are allowed?
0
 
LVL 1

Author Comment

by:tim_carter
Comment Utility
sorry, checked the link. thankss
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now