Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-22
3
Medium Priority
?
1,570 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

618 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